Compare commits
11 Commits
add-networ
...
v1.7.4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
534a8b805e | ||
| de1d073c6d | |||
| d3e34871aa | |||
| 3e8aead632 | |||
| 9498554758 | |||
| c2167d5d97 | |||
| 6eb2d0145e | |||
| b1ca0497b0 | |||
| 589fb4fcf7 | |||
| 51213c51e0 | |||
| da20bbe045 |
@@ -11,12 +11,14 @@ stages:
|
||||
- push_dockerhub
|
||||
|
||||
.docker_base:
|
||||
image: docker:18.09.7-dind
|
||||
image: docker:20.10.6-dind
|
||||
services:
|
||||
- docker:18.09.7-dind
|
||||
- name: docker:20.10.6-dind
|
||||
command: ["--tls=false"]
|
||||
variables:
|
||||
DOCKER_DRIVER: overlay
|
||||
DOCKER_HOST: tcp://localhost:2375/
|
||||
DOCKER_HOST: tcp://127.0.0.1:2375/
|
||||
DOCKER_TLS_CERTDIR: ""
|
||||
IMAGE_TAG: "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG"
|
||||
FF_GITLAB_REGISTRY_HELPER_IMAGE: 1
|
||||
before_script:
|
||||
@@ -71,7 +73,7 @@ push dockerhub:
|
||||
- docker push $CI_DOCKERHUB_IMAGE
|
||||
|
||||
release:
|
||||
image: node:13
|
||||
image: node:16-alpine3.13
|
||||
stage: release
|
||||
only:
|
||||
refs:
|
||||
@@ -83,7 +85,9 @@ release:
|
||||
- /^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/
|
||||
script:
|
||||
- touch CHANGELOG.md
|
||||
- npm install @semantic-release/gitlab @semantic-release/changelog @semantic-release/git
|
||||
- apk add --no-cache git
|
||||
- npm install @semantic-release/gitlab @semantic-release/changelog
|
||||
@semantic-release/git conventional-changelog-eslint
|
||||
- npx semantic-release
|
||||
artifacts:
|
||||
paths:
|
||||
@@ -95,8 +99,9 @@ include:
|
||||
- template: Security/SAST.gitlab-ci.yml
|
||||
|
||||
sonarqube-check:
|
||||
stage: test
|
||||
image:
|
||||
name: sonarsource/sonar-scanner-cli:latest
|
||||
name: sonarsource/sonar-scanner-cli:4.6
|
||||
entrypoint: [""]
|
||||
variables:
|
||||
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache
|
||||
@@ -110,3 +115,30 @@ sonarqube-check:
|
||||
allow_failure: true
|
||||
only:
|
||||
- master # or the name of your main branch
|
||||
- branches
|
||||
|
||||
trivy:
|
||||
stage: test
|
||||
extends:
|
||||
- .docker_base
|
||||
before_script:
|
||||
- export TRIVY_VERSION=$(wget -qO - "https://api.github.com/repos/aquasecurity/trivy/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/')
|
||||
- echo $TRIVY_VERSION
|
||||
- wget --no-verbose https://github.com/aquasecurity/trivy/releases/download/v${TRIVY_VERSION}/trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz -O - | tar -zxvf -
|
||||
allow_failure: true
|
||||
script:
|
||||
# Build image
|
||||
- docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA ./Docker/
|
||||
# Build report
|
||||
- ./trivy --exit-code 0 --cache-dir .trivycache/ --no-progress --format template --template "@contrib/gitlab.tpl" -o gl-container-scanning-report.json image $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
|
||||
# Print report
|
||||
- ./trivy --exit-code 0 --cache-dir .trivycache/ --no-progress --severity HIGH image $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
|
||||
# Fail on severe vulnerabilities
|
||||
- ./trivy --exit-code 1 --cache-dir .trivycache/ --severity CRITICAL --no-progress image $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
|
||||
cache:
|
||||
paths:
|
||||
- .trivycache/
|
||||
# Enables https://docs.gitlab.com/ee/user/application_security/container_scanning/ (Container Scanning report is available on GitLab EE Ultimate or GitLab.com Gold)
|
||||
artifacts:
|
||||
reports:
|
||||
container_scanning: gl-container-scanning-report.json
|
||||
|
||||
@@ -1,6 +1,38 @@
|
||||
plugins:
|
||||
- "@semantic-release/commit-analyzer"
|
||||
- "@semantic-release/release-notes-generator"
|
||||
- - "@semantic-release/commit-analyzer"
|
||||
- preset: eslint
|
||||
releaseRules:
|
||||
- tag: Breaking
|
||||
release: major
|
||||
- tag: Build
|
||||
release: patch
|
||||
- tag: Chore
|
||||
release: minor
|
||||
- tag: Fix
|
||||
release: patch
|
||||
- tag: New
|
||||
release: minor
|
||||
- tag: Update
|
||||
release: minor
|
||||
- tag: Upgrade
|
||||
release: minor
|
||||
- - "@semantic-release/release-notes-generator"
|
||||
- preset: eslint
|
||||
releaseRules:
|
||||
- tag: Breaking
|
||||
release: major
|
||||
- tag: Build
|
||||
release: patch
|
||||
- tag: Chore
|
||||
release: minor
|
||||
- tag: Fix
|
||||
release: patch
|
||||
- tag: New
|
||||
release: minor
|
||||
- tag: Update
|
||||
release: minor
|
||||
- tag: Upgrade
|
||||
release: minor
|
||||
- - "@semantic-release/changelog"
|
||||
- changelogFile: CHANGELOG.md
|
||||
- "@semantic-release/gitlab"
|
||||
|
||||
13
CHANGELOG.md
13
CHANGELOG.md
@@ -1,3 +1,16 @@
|
||||
## [1.7.4](https://gitlab.evanrichardsonphotography.com/erichardson/py-eagle-mqtt/compare/v1.7.3...v1.7.4) (2021-05-09)
|
||||
|
||||
|
||||
### Build
|
||||
|
||||
* cleanup long install line ([de1d073](https://gitlab.evanrichardsonphotography.com/erichardson/py-eagle-mqtt/commit/de1d073c6daf5d43fb7d9b7dafddd3b0cbcffc9b))
|
||||
|
||||
### ci
|
||||
|
||||
* Add git to node image ([6eb2d01](https://gitlab.evanrichardsonphotography.com/erichardson/py-eagle-mqtt/commit/6eb2d0145eff50c3243a364d821e769ae2ee06c9))
|
||||
* change semantic release image to alpine to save space, updated to node 16 ([b1ca049](https://gitlab.evanrichardsonphotography.com/erichardson/py-eagle-mqtt/commit/b1ca0497b0b51e0c50ca1e5f99e5c8abd4224d53))
|
||||
* Update DinD base to 20.10.6 and semantic release to node:15. Also pin sonar-scanner-cli to 4.6 ([589fb4f](https://gitlab.evanrichardsonphotography.com/erichardson/py-eagle-mqtt/commit/589fb4fcf7841d3c5f08327d7fb5d5c107562ed6))
|
||||
|
||||
## [1.7.3](https://gitlab.evanrichardsonphotography.com/erichardson/py-eagle-mqtt/compare/v1.7.2...v1.7.3) (2021-04-12)
|
||||
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# ===========================================================================
|
||||
#===========================================================================
|
||||
#
|
||||
# Eagle posting server
|
||||
#
|
||||
# ===========================================================================
|
||||
#===========================================================================
|
||||
|
||||
__doc__ = """
|
||||
Starts a small web server. The Rain Forest Eagle is configured with
|
||||
@@ -22,116 +22,100 @@ import json
|
||||
import bottle as B
|
||||
import tHome as T
|
||||
|
||||
#===========================================================================
|
||||
def meter( client, data, cfg ):
|
||||
msg = {
|
||||
"time" : data.TimeUnix,
|
||||
"consumed" : data.Consumed, # kWh
|
||||
"produced" : data.Produced, # kWh
|
||||
}
|
||||
|
||||
# ===========================================================================
|
||||
def meter(client, data, cfg):
|
||||
msg = {
|
||||
"time": data.TimeUnix,
|
||||
"consumed": data.Consumed, # kWh
|
||||
"produced": data.Produced, # kWh
|
||||
}
|
||||
return ( cfg.mqttEnergy, msg )
|
||||
|
||||
return cfg.mqttEnergy, msg
|
||||
#===========================================================================
|
||||
def instant( client, data, cfg ):
|
||||
msg = {
|
||||
"time" : data.TimeUnix,
|
||||
"power" : data.Power * 1000, # W
|
||||
}
|
||||
|
||||
return ( cfg.mqttPower, msg )
|
||||
|
||||
# ===========================================================================
|
||||
def instant(client, data, cfg):
|
||||
msg = {
|
||||
"time": data.TimeUnix,
|
||||
"power": data.Power * 1000, # W
|
||||
}
|
||||
#===========================================================================
|
||||
def price( client, data, cfg ):
|
||||
msg = {
|
||||
"time" : data.TimeUnix,
|
||||
"price" : data.Price,
|
||||
"tier" : data.Tier,
|
||||
}
|
||||
return ( cfg.mqttPrice, msg )
|
||||
|
||||
return cfg.mqttPower, msg
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
def price(client, data, cfg):
|
||||
msg = {
|
||||
"time": data.TimeUnix,
|
||||
"price": data.Price,
|
||||
"tier": data.Tier,
|
||||
}
|
||||
return cfg.mqttPrice, msg
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
def network(client, data, cfg):
|
||||
msg = {
|
||||
"status": data.Status,
|
||||
"description": data.Description,
|
||||
"linkstrength": data.LinkStrength
|
||||
}
|
||||
return cfg.mqttNetwork, msg
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
#===========================================================================
|
||||
handlers = {
|
||||
# "BlockPriceDetail" :
|
||||
"CurrentSummation": meter,
|
||||
# "DeviceInfo" :
|
||||
# "FastPollStatus" :
|
||||
"InstantaneousDemand": instant,
|
||||
# "MessageCluster" :
|
||||
# "MeterInfo" :
|
||||
"NetworkInfo": network,
|
||||
"PriceCluster": price,
|
||||
# "Reading" :
|
||||
# "ScheduleInfo" :
|
||||
# "TimeCluster" :
|
||||
}
|
||||
#"BlockPriceDetail" :
|
||||
"CurrentSummation" : meter,
|
||||
#"DeviceInfo" :
|
||||
#"FastPollStatus" :
|
||||
"InstantaneousDemand" : instant,
|
||||
#"MessageCluster" :
|
||||
#"MeterInfo" :
|
||||
#"NetworkInfo" :
|
||||
"PriceCluster" : price,
|
||||
#"Reading" :
|
||||
#"ScheduleInfo" :
|
||||
#"TimeCluster" :
|
||||
}
|
||||
|
||||
#===========================================================================
|
||||
|
||||
# ===========================================================================
|
||||
|
||||
@B.post('/')
|
||||
@B.post( '/' )
|
||||
def root_post():
|
||||
data = B.request.body.read(B.request.content_length)
|
||||
try:
|
||||
obj = T.eagle.parse(data)
|
||||
except:
|
||||
log.exception("Error parsing Eagle posted data")
|
||||
return "ERROR"
|
||||
data = B.request.body.read( B.request.content_length )
|
||||
try:
|
||||
obj = T.eagle.parse( data )
|
||||
except:
|
||||
log.exception( "Error parsing Eagle posted data" )
|
||||
return "ERROR"
|
||||
|
||||
log.info("Read packet: %s" % obj.name)
|
||||
log.info( "Read packet: %s" % obj.name )
|
||||
|
||||
func = handlers.get(obj.name, None)
|
||||
if func:
|
||||
topic, msg = func(client, obj, cfg)
|
||||
if msg:
|
||||
log.info("Publish: %s: %s" % (topic, msg))
|
||||
func = handlers.get( obj.name, None )
|
||||
if func:
|
||||
topic, msg = func( client, obj, cfg )
|
||||
if msg:
|
||||
log.info( "Publish: %s: %s" % ( topic, msg ) )
|
||||
|
||||
payload = json.dumps(msg)
|
||||
client.publish(topic, payload)
|
||||
payload = json.dumps( msg )
|
||||
client.publish( topic, payload )
|
||||
|
||||
return "ok"
|
||||
return "ok"
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
#===========================================================================
|
||||
#
|
||||
# Main applications script
|
||||
#
|
||||
# ===========================================================================
|
||||
#===========================================================================
|
||||
|
||||
p = argparse.ArgumentParser(prog=sys.argv[0],
|
||||
description="T-Home Eagle Server")
|
||||
p.add_argument("-c", "--configDir", metavar="configDir",
|
||||
default="/etc/tHome",
|
||||
help="Configuration file directory.")
|
||||
p.add_argument("-l", "--log", metavar="logFile",
|
||||
default=None, help="Logging file to use. Input 'stdout' "
|
||||
"to log to the screen.")
|
||||
c = p.parse_args(sys.argv[1:])
|
||||
p = argparse.ArgumentParser( prog=sys.argv[0],
|
||||
description="T-Home Eagle Server" )
|
||||
p.add_argument( "-c", "--configDir", metavar="configDir",
|
||||
default="/etc/tHome",
|
||||
help="Configuration file directory." )
|
||||
p.add_argument( "-l", "--log", metavar="logFile",
|
||||
default=None, help="Logging file to use. Input 'stdout' "
|
||||
"to log to the screen." )
|
||||
c = p.parse_args( sys.argv[1:] )
|
||||
|
||||
# Parse the eagle config file.
|
||||
cfg = T.eagle.config.parse(c.configDir)
|
||||
log = T.eagle.config.log(cfg, c.log)
|
||||
cfg = T.eagle.config.parse( c.configDir )
|
||||
log = T.eagle.config.log( cfg, c.log )
|
||||
|
||||
# Create the MQTT client and connect it to the broker.
|
||||
client = T.broker.connect(c.configDir, log)
|
||||
client = T.broker.connect( c.configDir, log )
|
||||
|
||||
# Start the MQTT as a background thread. This way we can run the web
|
||||
# server as the main thread here.
|
||||
client.loop_start()
|
||||
|
||||
log.info("Starting web server at port %d" % cfg.httpPort)
|
||||
B.run(host='0.0.0.0', port=cfg.httpPort, quiet=True)
|
||||
log.info( "Starting web server at port %d" % cfg.httpPort )
|
||||
B.run( host='0.0.0.0', port=cfg.httpPort, quiet=True )
|
||||
|
||||
@@ -23,9 +23,6 @@ mqttPrice = 'power/elec/Home/price'
|
||||
#Current rate label (returns rate label from meter)
|
||||
mqttRateLabel = 'power/elec/Home/ratelabel'
|
||||
|
||||
#Network Info Topic (returns status, description and link strength from meter)
|
||||
mqttNetwork = 'power/elec/Home/network'
|
||||
|
||||
#===========================================================================
|
||||
#
|
||||
# Logging configuration. Env variables are allowed in the file name.
|
||||
|
||||
Reference in New Issue
Block a user