change config to env, add ci-script
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
This commit is contained in:
parent
5cabef91ea
commit
4ea85f3c7e
29
.woodpecker.yml
Normal file
29
.woodpecker.yml
Normal file
@ -0,0 +1,29 @@
|
||||
steps:
|
||||
build:
|
||||
image: plugins/kaniko
|
||||
settings:
|
||||
repo: gitea.hottis.de/wn/pv-controller
|
||||
registry:
|
||||
from_secret: container_registry
|
||||
tags: latest,${CI_COMMIT_SHA},${CI_COMMIT_TAG}
|
||||
username:
|
||||
from_secret: container_registry_username
|
||||
password:
|
||||
from_secret: container_registry_password
|
||||
dockerfile: Dockerfile
|
||||
when:
|
||||
- event: [push, tag]
|
||||
|
||||
deploy:
|
||||
image: portainer/kubectl-shell:latest
|
||||
secrets:
|
||||
- source: kube_config
|
||||
target: KUBE_CONFIG_CONTENT
|
||||
commands:
|
||||
- export IMAGE_TAG=$CI_COMMIT_TAG
|
||||
- printf "$KUBE_CONFIG_CONTENT" > /tmp/kubeconfig
|
||||
- export KUBECONFIG=/tmp/kubeconfig
|
||||
- cat ./deployment/install-yml.tmpl | sed -e 's,%IMAGETAG%,'$IMAGE_TAG','g | kubectl apply -f -
|
||||
when:
|
||||
- event: tag
|
||||
|
44
deployment/install-yml.tmpl
Normal file
44
deployment/install-yml.tmpl
Normal file
@ -0,0 +1,44 @@
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: homea
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: digitaltwin1
|
||||
namespace: homea
|
||||
data:
|
||||
MQTT__BROKER: "emqx01-anonymous-cluster-internal.broker.svc.cluster.local"
|
||||
MQTT__DIGITALOUTPUTTOPICPREFIX: "dt1/coil"
|
||||
MQTT__DIGITALINPUTTOPICPREFIX: "dt1/di"
|
||||
MQTT__ANALOGINPUTEVENTTOPICPREFIX: "dt1/ai/event"
|
||||
MQTT__ANALOGINPUTPERIODICTOPICPREFIX: "dt1/ai/periodic"
|
||||
MQTT__ANALOGPUBLISHPERIOD: "10.0"
|
||||
MQTT__DISABLEANALOGINPUTEVENTPUBLISHING: "true"
|
||||
MODBUS__CLIENT: "172.16.2.157"
|
||||
MODBUS__SCANRATE: "0.25"
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: digitaltwin1
|
||||
namespace: homea
|
||||
labels:
|
||||
app: digitaltwin1
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: digitaltwin1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: digitaltwin1
|
||||
spec:
|
||||
containers:
|
||||
- name: digitaltwin1
|
||||
image: gitea.hottis.de/wn/digitaltwin1:%IMAGETAG%
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: digitaltwin1
|
30
src/config.py
Normal file
30
src/config.py
Normal file
@ -0,0 +1,30 @@
|
||||
import os
|
||||
from loguru import logger
|
||||
|
||||
class Config:
|
||||
OPTIONS = {
|
||||
'mqtt': [ 'broker',
|
||||
'digitalInputTopicPrefix',
|
||||
'digitalInputTopicPrefix',
|
||||
'analogInputEventTopicPrefix',
|
||||
'analogInputPeriodicTopicPrefix',
|
||||
'analogInputPublishPeriod',
|
||||
'disableAnalogInputEventPublishing' ],
|
||||
'modbus': [ 'client', 'scanrate' ]
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
self.values = {}
|
||||
for section, keys in Config.OPTIONS.items():
|
||||
self.values[section] = {}
|
||||
for key in keys:
|
||||
varname = f"{section}__{key}".upper()
|
||||
try:
|
||||
self.values[section][key] = os.environ[varname]
|
||||
logger.info(f"Config: {section} {key} -> {self.values[section][key]}")
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
def __getitem__(self, section):
|
||||
return self.values[section]
|
||||
|
@ -8,7 +8,7 @@ from ModbusHandler import ModbusHandler
|
||||
from MqttEventPublisher import MqttEventPublisher, mqttEventPublisherStart
|
||||
from MqttPeriodPublisher import MqttPeriodPublisher
|
||||
from MqttCoilSubscriber import MqttCoilSubscriber
|
||||
|
||||
from config import Config
|
||||
|
||||
deathBell = threading.Event()
|
||||
|
||||
@ -21,18 +21,7 @@ def exceptHook(args):
|
||||
|
||||
logger.info("DigitalTwin1 starting")
|
||||
|
||||
parser = argparse.ArgumentParser(description="DigitalTwin1")
|
||||
parser.add_argument('--config', '-f',
|
||||
help='Config file, default is $pwd/config/config.ini',
|
||||
required=False,
|
||||
default='./config/config.ini')
|
||||
args = parser.parse_args()
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read(args.config)
|
||||
|
||||
|
||||
|
||||
config = Config()
|
||||
|
||||
processImage = ProcessImage()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user