Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
63857671f9
|
|||
|
d008c9fd5a
|
|||
|
1eb0f84659
|
|||
|
51df63d9f2
|
|||
|
cdaa5deb58
|
|||
|
91ef285a6c
|
|||
|
9afa68a111
|
|||
|
1119bb529f
|
|||
|
26286ce194
|
@@ -19,7 +19,7 @@ steps:
|
|||||||
auto_tag: true
|
auto_tag: true
|
||||||
dockerfile: apps/${APP}/Dockerfile
|
dockerfile: apps/${APP}/Dockerfile
|
||||||
when:
|
when:
|
||||||
event: [push, tag]
|
event: [tag]
|
||||||
ref:
|
ref:
|
||||||
exclude:
|
exclude:
|
||||||
- refs/tags/*-configchange
|
- refs/tags/*-configchange
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ steps:
|
|||||||
commands:
|
commands:
|
||||||
- printf "$KUBE_CONFIG_CONTENT" > /tmp/kubeconfig
|
- printf "$KUBE_CONFIG_CONTENT" > /tmp/kubeconfig
|
||||||
- export KUBECONFIG=/tmp/kubeconfig
|
- export KUBECONFIG=/tmp/kubeconfig
|
||||||
- echo "Deploying application ${APP} (${IMAGE}) to namespace ${NAMESPACE}"
|
- echo "Deploying application ${APP} ($IMAGE) to namespace $NAMESPACE"
|
||||||
|
- cat deployment/${APP}-deployment.yaml | sed "s,%IMAGE%,$IMAGE,g" | kubectl apply -n $NAMESPACE -f -
|
||||||
when:
|
when:
|
||||||
event: [tag]
|
event: [tag]
|
||||||
ref:
|
ref:
|
||||||
|
|||||||
@@ -25,13 +25,14 @@ steps:
|
|||||||
- printf "$KUBE_CONFIG_CONTENT" > /tmp/kubeconfig
|
- printf "$KUBE_CONFIG_CONTENT" > /tmp/kubeconfig
|
||||||
- export KUBECONFIG=/tmp/kubeconfig
|
- export KUBECONFIG=/tmp/kubeconfig
|
||||||
- kubectl create configmap home-automation-config
|
- kubectl create configmap home-automation-config
|
||||||
--from-file=devices=config/devices.yaml
|
--from-file=devices.yaml=config/devices.yaml
|
||||||
--from-file=groups=config/groups.yaml
|
--from-file=groups.yaml=config/groups.yaml
|
||||||
--from-file=layout=config/layout.yaml
|
--from-file=layout.yaml=config/layout.yaml
|
||||||
--from-file=rules=config/rules.yaml
|
--from-file=rules.yaml=config/rules.yaml
|
||||||
--from-file=scenes=config/scenes.yaml
|
--from-file=scenes.yaml=config/scenes.yaml
|
||||||
--namespace=$NAMESPACE
|
--namespace=$NAMESPACE
|
||||||
--dry-run=client -o yaml | kubectl apply -f -
|
--dry-run=client -o yaml | kubectl apply -f -
|
||||||
|
- kubectl apply -f deployment/configmap.yaml -n $NAMESPACE
|
||||||
when:
|
when:
|
||||||
event: [tag]
|
event: [tag]
|
||||||
|
|
||||||
|
|||||||
@@ -391,9 +391,19 @@ async def async_main() -> None:
|
|||||||
validate_devices(devices)
|
validate_devices(devices)
|
||||||
logger.info(f"Loaded {len(devices)} device(s) from configuration")
|
logger.info(f"Loaded {len(devices)} device(s) from configuration")
|
||||||
|
|
||||||
# Get Redis URL from config or environment variable or use default
|
# Build Redis URL from environment variables or config or use default
|
||||||
|
redis_host = os.environ.get("REDIS_HOST")
|
||||||
|
redis_port = os.environ.get("REDIS_PORT")
|
||||||
|
redis_db = os.environ.get("REDIS_DB")
|
||||||
|
|
||||||
|
if redis_host and redis_port and redis_db:
|
||||||
|
redis_url = f"redis://{redis_host}:{redis_port}/{redis_db}"
|
||||||
|
logger.info(f"Using Redis from environment variables: {redis_url}")
|
||||||
|
else:
|
||||||
|
# Fallback to config file
|
||||||
redis_config = config.get("redis", {})
|
redis_config = config.get("redis", {})
|
||||||
redis_url = redis_config.get("url") or os.environ.get("REDIS_URL", "redis://localhost:6379/0")
|
redis_url = redis_config.get("url") or "redis://localhost:6379/0"
|
||||||
|
logger.info(f"Using Redis from config file: {redis_url}")
|
||||||
|
|
||||||
# Connect to Redis with retry
|
# Connect to Redis with retry
|
||||||
redis_client = await get_redis_client(redis_url)
|
redis_client = await get_redis_client(redis_url)
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ app.add_middleware(
|
|||||||
"http://localhost:8002",
|
"http://localhost:8002",
|
||||||
"http://172.19.1.11:8002",
|
"http://172.19.1.11:8002",
|
||||||
"http://127.0.0.1:8002",
|
"http://127.0.0.1:8002",
|
||||||
|
"https://homea2.hottis.de"
|
||||||
],
|
],
|
||||||
allow_credentials=True,
|
allow_credentials=True,
|
||||||
allow_methods=["*"],
|
allow_methods=["*"],
|
||||||
|
|||||||
@@ -1,14 +1,4 @@
|
|||||||
version: 1
|
version: 1
|
||||||
mqtt:
|
|
||||||
broker: "172.16.2.16"
|
|
||||||
port: 1883
|
|
||||||
client_id: "home-automation-abstraction"
|
|
||||||
username: null
|
|
||||||
password: null
|
|
||||||
keepalive: 60
|
|
||||||
redis:
|
|
||||||
url: "redis://172.23.1.116:6379/8"
|
|
||||||
channel: "ui:updates"
|
|
||||||
devices:
|
devices:
|
||||||
- device_id: lampe_semeniere_wohnzimmer
|
- device_id: lampe_semeniere_wohnzimmer
|
||||||
name: Semeniere
|
name: Semeniere
|
||||||
|
|||||||
73
deployment/abstraction-deployment.yaml
Normal file
73
deployment/abstraction-deployment.yaml
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: abstraction
|
||||||
|
labels:
|
||||||
|
app: abstraction
|
||||||
|
component: home-automation
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: abstraction
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
reloader.stakater.com/auto: "true"
|
||||||
|
configmap.reloader.stakater.com/reload: "home-automation-environment,home-automation-config"
|
||||||
|
labels:
|
||||||
|
app: abstraction
|
||||||
|
component: home-automation
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: abstraction
|
||||||
|
image: %IMAGE%
|
||||||
|
env:
|
||||||
|
- name: MQTT_BROKER
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: home-automation-environment
|
||||||
|
key: SHARED_MQTT_BROKER
|
||||||
|
- name: MQTT_PORT
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: home-automation-environment
|
||||||
|
key: SHARED_MQTT_PORT
|
||||||
|
- name: REDIS_HOST
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: home-automation-environment
|
||||||
|
key: SHARED_REDIS_HOST
|
||||||
|
- name: REDIS_PORT
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: home-automation-environment
|
||||||
|
key: SHARED_REDIS_PORT
|
||||||
|
- name: REDIS_DB
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: home-automation-environment
|
||||||
|
key: SHARED_REDIS_DB
|
||||||
|
volumeMounts:
|
||||||
|
- name: config-volume
|
||||||
|
mountPath: /app/config
|
||||||
|
readOnly: true
|
||||||
|
livenessProbe:
|
||||||
|
exec:
|
||||||
|
command:
|
||||||
|
- /bin/sh
|
||||||
|
- -c
|
||||||
|
- "ps aux | grep -v grep | grep python"
|
||||||
|
initialDelaySeconds: 30
|
||||||
|
periodSeconds: 10
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpu: 500m
|
||||||
|
memory: 512Mi
|
||||||
|
requests:
|
||||||
|
cpu: 100m
|
||||||
|
memory: 128Mi
|
||||||
|
volumes:
|
||||||
|
- name: config-volume
|
||||||
|
configMap:
|
||||||
|
name: home-automation-config
|
||||||
125
deployment/api-deployment.yaml
Normal file
125
deployment/api-deployment.yaml
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: api
|
||||||
|
namespace: homea2
|
||||||
|
labels:
|
||||||
|
app: api
|
||||||
|
component: home-automation
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: api
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
reloader.stakater.com/auto: "true"
|
||||||
|
configmap.reloader.stakater.com/reload: "home-automation-environment,home-automation-config"
|
||||||
|
labels:
|
||||||
|
app: api
|
||||||
|
component: home-automation
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: api
|
||||||
|
image: %IMAGE%
|
||||||
|
ports:
|
||||||
|
- containerPort: 8001
|
||||||
|
name: http
|
||||||
|
env:
|
||||||
|
- name: MQTT_BROKER
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: home-automation-environment
|
||||||
|
key: SHARED_MQTT_BROKER
|
||||||
|
- name: MQTT_PORT
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: home-automation-environment
|
||||||
|
key: SHARED_MQTT_PORT
|
||||||
|
- name: REDIS_HOST
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: home-automation-environment
|
||||||
|
key: SHARED_REDIS_HOST
|
||||||
|
- name: REDIS_PORT
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: home-automation-environment
|
||||||
|
key: SHARED_REDIS_PORT
|
||||||
|
- name: REDIS_DB
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: home-automation-environment
|
||||||
|
key: SHARED_REDIS_DB
|
||||||
|
- name: REDIS_CHANNEL
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: home-automation-environment
|
||||||
|
key: API_REDIS_CHANNEL
|
||||||
|
volumeMounts:
|
||||||
|
- name: config-volume
|
||||||
|
mountPath: /app/config
|
||||||
|
readOnly: true
|
||||||
|
livenessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /health
|
||||||
|
port: 8001
|
||||||
|
initialDelaySeconds: 30
|
||||||
|
periodSeconds: 10
|
||||||
|
readinessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /health
|
||||||
|
port: 8001
|
||||||
|
initialDelaySeconds: 5
|
||||||
|
periodSeconds: 5
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpu: 1000m
|
||||||
|
memory: 1Gi
|
||||||
|
requests:
|
||||||
|
cpu: 200m
|
||||||
|
memory: 256Mi
|
||||||
|
volumes:
|
||||||
|
- name: config-volume
|
||||||
|
configMap:
|
||||||
|
name: home-automation-config
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: api
|
||||||
|
labels:
|
||||||
|
app: api
|
||||||
|
component: home-automation
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: api
|
||||||
|
ports:
|
||||||
|
- port: 80
|
||||||
|
targetPort: 8001
|
||||||
|
name: http
|
||||||
|
type: ClusterIP
|
||||||
|
---
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
name: api-ingress
|
||||||
|
annotations:
|
||||||
|
cert-manager.io/cluster-issuer: letsencrypt-production-http
|
||||||
|
spec:
|
||||||
|
tls:
|
||||||
|
- hosts:
|
||||||
|
- homea2-api.hottis.de
|
||||||
|
secretName: homea2-api-cert
|
||||||
|
rules:
|
||||||
|
- host: homea2-api.hottis.de
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- path: /
|
||||||
|
pathType: Prefix
|
||||||
|
backend:
|
||||||
|
service:
|
||||||
|
name: api
|
||||||
|
port:
|
||||||
|
number: 80
|
||||||
23
deployment/configmap.yaml
Normal file
23
deployment/configmap.yaml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: home-automation-environment
|
||||||
|
namespace: homea2
|
||||||
|
data:
|
||||||
|
# Default environment variables
|
||||||
|
SHARED_MQTT_BROKER: "emqx01-anonymous-cluster-internal.broker.svc.cluster.local"
|
||||||
|
SHARED_MQTT_PORT: "1883"
|
||||||
|
SHARED_REDIS_HOST: "redis-master.redis.svc.cluster.local"
|
||||||
|
SHARED_REDIS_PORT: "6379"
|
||||||
|
SHARED_REDIS_DB: "8"
|
||||||
|
|
||||||
|
# UI specific environment variables
|
||||||
|
UI_UI_PORT: "8002"
|
||||||
|
UI_API_BASE: "https://homea2-api.hottis.de"
|
||||||
|
UI_BASE_PATH: "/"
|
||||||
|
|
||||||
|
# API specific environment variables
|
||||||
|
API_REDIS_CHANNEL: "ui:updates"
|
||||||
|
|
||||||
|
# Rules specific environment variables
|
||||||
|
RULES_RULES_CONFIG: "/app/config/rules.yaml"
|
||||||
78
deployment/rules-deployment.yaml
Normal file
78
deployment/rules-deployment.yaml
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: rules
|
||||||
|
labels:
|
||||||
|
app: rules
|
||||||
|
component: home-automation
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: rules
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
reloader.stakater.com/auto: "true"
|
||||||
|
configmap.reloader.stakater.com/reload: "home-automation-environment,home-automation-config"
|
||||||
|
labels:
|
||||||
|
app: rules
|
||||||
|
component: home-automation
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: rules
|
||||||
|
image: %IMAGE%
|
||||||
|
env:
|
||||||
|
- name: MQTT_BROKER
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: home-automation-environment
|
||||||
|
key: SHARED_MQTT_BROKER
|
||||||
|
- name: MQTT_PORT
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: home-automation-environment
|
||||||
|
key: SHARED_MQTT_PORT
|
||||||
|
- name: REDIS_HOST
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: home-automation-environment
|
||||||
|
key: SHARED_REDIS_HOST
|
||||||
|
- name: REDIS_PORT
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: home-automation-environment
|
||||||
|
key: SHARED_REDIS_PORT
|
||||||
|
- name: REDIS_DB
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: home-automation-environment
|
||||||
|
key: SHARED_REDIS_DB
|
||||||
|
- name: RULES_CONFIG
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: home-automation-environment
|
||||||
|
key: RULES_RULES_CONFIG
|
||||||
|
volumeMounts:
|
||||||
|
- name: config-volume
|
||||||
|
mountPath: /app/config
|
||||||
|
readOnly: true
|
||||||
|
livenessProbe:
|
||||||
|
exec:
|
||||||
|
command:
|
||||||
|
- /bin/sh
|
||||||
|
- -c
|
||||||
|
- "ps aux | grep -v grep | grep python"
|
||||||
|
initialDelaySeconds: 30
|
||||||
|
periodSeconds: 10
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpu: 500m
|
||||||
|
memory: 512Mi
|
||||||
|
requests:
|
||||||
|
cpu: 100m
|
||||||
|
memory: 128Mi
|
||||||
|
volumes:
|
||||||
|
- name: config-volume
|
||||||
|
configMap:
|
||||||
|
name: home-automation-config
|
||||||
102
deployment/ui-deployment.yaml
Normal file
102
deployment/ui-deployment.yaml
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: ui
|
||||||
|
namespace: homea2
|
||||||
|
labels:
|
||||||
|
app: ui
|
||||||
|
component: home-automation
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: ui
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
reloader.stakater.com/auto: "true"
|
||||||
|
configmap.reloader.stakater.com/reload: "home-automation-environment"
|
||||||
|
labels:
|
||||||
|
app: ui
|
||||||
|
component: home-automation
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: ui
|
||||||
|
image: %IMAGE%
|
||||||
|
ports:
|
||||||
|
- containerPort: 8002
|
||||||
|
name: http
|
||||||
|
env:
|
||||||
|
- name: UI_PORT
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: home-automation-environment
|
||||||
|
key: UI_UI_PORT
|
||||||
|
- name: API_BASE
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: home-automation-environment
|
||||||
|
key: UI_API_BASE
|
||||||
|
- name: BASE_PATH
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: home-automation-environment
|
||||||
|
key: UI_BASE_PATH
|
||||||
|
livenessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /
|
||||||
|
port: 8002
|
||||||
|
initialDelaySeconds: 30
|
||||||
|
periodSeconds: 10
|
||||||
|
readinessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /
|
||||||
|
port: 8002
|
||||||
|
initialDelaySeconds: 5
|
||||||
|
periodSeconds: 5
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpu: 500m
|
||||||
|
memory: 512Mi
|
||||||
|
requests:
|
||||||
|
cpu: 100m
|
||||||
|
memory: 128Mi
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: ui
|
||||||
|
labels:
|
||||||
|
app: ui
|
||||||
|
component: home-automation
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: ui
|
||||||
|
ports:
|
||||||
|
- port: 80
|
||||||
|
targetPort: 8002
|
||||||
|
name: http
|
||||||
|
type: ClusterIP
|
||||||
|
---
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
name: ui-ingress
|
||||||
|
annotations:
|
||||||
|
cert-manager.io/cluster-issuer: letsencrypt-production-http
|
||||||
|
spec:
|
||||||
|
tls:
|
||||||
|
- hosts:
|
||||||
|
- homea2.hottis.de
|
||||||
|
secretName: homea2-ui-cert
|
||||||
|
rules:
|
||||||
|
- host: homea2.hottis.de
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- path: /
|
||||||
|
pathType: Prefix
|
||||||
|
backend:
|
||||||
|
service:
|
||||||
|
name: ui
|
||||||
|
port:
|
||||||
|
number: 80
|
||||||
Reference in New Issue
Block a user