continuos deploy

This commit is contained in:
2025-11-22 01:57:22 +00:00
parent 726f3c5bb3
commit 001e785192
16 changed files with 229 additions and 59 deletions

View File

@@ -0,0 +1,45 @@
name: Setup kubectl
description: "Reads kube config from inputs and sets KUBECONFIG"
inputs:
kube_server:
description: "Kubernetes API server address"
required: true
kube_ca_base64:
description: "Base64-encoded CA certificate"
required: true
kube_token:
description: "ServiceAccount token"
required: true
runs:
using: "composite"
steps:
- name: Create kubeconfig
shell: bash
run: |
set -euo pipefail
mkdir -p "${GITHUB_TEMP}/.kube"
cat <<EOF > "${GITHUB_TEMP}/.kube/config"
apiVersion: v1
kind: Config
clusters:
- cluster:
certificate-authority-data: ${{ inputs.kube_ca_base64 }}
server: ${{ inputs.kube_server }}
name: cluster
contexts:
- context:
cluster: cluster
namespace: default
user: user
name: context
current-context: context
users:
- name: user
user:
token: ${{ inputs.kube_token }}
EOF
echo "KUBECONFIG=${GITHUB_TEMP}/.kube/config" >> "${GITHUB_ENV}"

View File

@@ -0,0 +1,35 @@
name: Casa Home Assistant CI/CD Pipeline
on:
push:
branches:
- main
pull_request:
jobs:
build:
runs-on: mf-casa-vlan-cid-runner
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup kubectl
uses: ./.github/actions/kubectl-setup
with:
kube_server: ${{ secrets.casa_vlan_kube_server }}
kube_ca_base64: ${{ secrets.casa_vlan_kube_ca_base64 }}
kube_token: ${{ secrets.casa_vlan_kube_token }}
- name: Deploy Home Assistant
shell: bash
run: |
set -e
cd ${{ gitea.workspace }}
export ENDPOINT_IP="${{ secrets.ENDPOINT_IP }}"
export SERVICE_PORT=${{ secrets.SERVICE_PORT }}
export INGRESS_ROUTES_MATCH="${{ secrets.INGRESS_ROUTES_MATCH }}"
export INGRESS_TLS_SECRET_NAME=${{ secrets.INGRESS_TLS_SECRET_NAME }}
kubectl apply -f ./deploy/deployment.yaml
envsubst < ./deploy/service.template.yaml | kubectl apply -f -

View File

@@ -37,7 +37,7 @@ All essential containers, such as MQTT and speech recognition, are hosted on the
Using as Ir blaster for living room devices and temperature meter.
![ZigBee Smart Plugs](doc/images/broadlink-universal-remote-irwifi-rm4-mini.jpg)
![ZigBee Smart Plugs](./docs/images/broadlink-universal-remote-irwifi-rm4-mini.jpg)
**Integrations:**
@@ -51,7 +51,7 @@ Currently controlling:
- dining table lights
- office room lights
![ZigBee Smart Plugs](doc/images/51ojy7qoMmL._SL1500_.jpg)
![ZigBee Smart Plugs](./docs/images/51ojy7qoMmL._SL1500_.jpg)
**Integrations:**
@@ -68,7 +68,7 @@ Currently controlling:
- shellyplug-s-80646F80FB14.dev.lan
- gaia.dev.lan (proxmox server)
![Shelly - Smart Plug](doc/images/shellysmartplug.png)
![Shelly - Smart Plug](./docs/images/shellysmartplug.png)
Devices connected to IOT lan.
@@ -102,7 +102,7 @@ Using SONOFF Universal Zigbee 3.0 USB Dongle Plus.
The [broadlink integration](https://www.home-assistant.io/integrations/broadlink) allows you to control and monitor Broadlink universal remotes, smart plugs, power strips, switches and sensors.
![broadlink integration](./doc/images/integrations-broadlink.png).
![broadlink integration](./docs/images/integrations-broadlink.png).
Devices:
@@ -255,5 +255,4 @@ Home Assistant authenticates with Xbox Live through OAuth2 using the Home Assist
## Setup
[Check folder setup](./setup).
[Deploy documentation](./deploy/README.md).

51
deploy/README.md Normal file
View File

@@ -0,0 +1,51 @@
# Home Assistant Deploy
## Namespace
```bash { cwd=../ terminalRows=15 }
# from repo root folder
kubectl create namespace home-assistant
```
## Deployment
### Environments requirements
``` bash
#./deploy/.env
export ENDPOINT_IP="xxx.xxx.xxx.xxxx"
export SERVICE_PORT=xxxx
export INGRESS_ROUTES_MATCH="Host(`xxxx`)"
export INGRESS_TLS_SECRET_NAME=xxxxxx
```
## Test Templates
```bash { cwd=../ terminalRows=15 }
# from repo root folder
source ./deploy/.env \
&& cat ./deploy/deployment.yaml \
&& envsubst < ./deploy/service.template.yaml
```
## Deploy
```bash { cwd=../ terminalRows=15 }
# from repo root folder
source ./deploy/.env \
&& kubectl apply -f ./deploy/deployment.yaml \
&& envsubst < ./deploy/service.template.yaml | kubectl apply -f -
```
## Continuos Deploy
All Environment variables requirements as set as secrets.
[gitea workflow](../.gitea/workflows/deploy.yaml)
## RBAC
```bash { cwd=../ }
kubectl apply -f ./deploy/rbac.yaml
```

View File

@@ -1,7 +1,3 @@
apiVersion: v1
kind: Namespace
metadata:
name: home-assistant
---
apiVersion: v1
@@ -38,10 +34,10 @@ spec:
dnsPolicy: ClusterFirstWithHostNet # ensures pod uses cluster DNS (CoreDNS) for service discovery even with host networking
hostNetwork: true
# delays start so host have time to start on low memory resources
initContainers:
- name: delay-start
image: busybox:latest
command: ["sh", "-c", "sleep 60"]
# initContainers:
# - name: delay-start
# image: busybox:latest
# command: ["sh", "-c", "sleep 60"]
containers:
- name: home-assistant
image: "homeassistant/home-assistant"

View File

@@ -1,23 +0,0 @@
apiVersion: v1
kind: Service
metadata:
name: home-assistant-external
namespace: home-assistant
spec:
clusterIP: None
ports:
- port: 8123
protocol: TCP
---
apiVersion: v1
kind: Endpoints
metadata:
name: home-assistant-external
namespace: home-assistant
subsets:
- addresses:
- ip: 192.168.14.9 # Replace with your actual external IP
ports:
- port: 8123

View File

@@ -1,22 +0,0 @@
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: home-assistant
namespace: home-assistant
spec:
entryPoints:
- websecure
routes:
- match: Host(`casa.limbosolutions.com`)
kind: Rule
services:
- name: home-assistant-external
port: 8123
- match: Host(`has.casa.limbosolutions.com`)
kind: Rule
services:
- name: home-assistant-external
port: 8123
tls:
secretName: casa-limbosolutions-com-tls

34
deploy/rbac.yaml Normal file
View File

@@ -0,0 +1,34 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: home-assistant
name: ci-cd
rules:
- apiGroups: [""]
resources: ["pods", "services", "secrets", "configmaps", "persistentvolumeclaims", "endpoints"]
verbs: ["get", "watch", "list", "create", "update", "patch", "delete"]
- apiGroups: ["apps"]
resources: ["deployments", "statefulsets"]
verbs: ["get", "watch", "list", "create", "update", "patch", "delete"]
- apiGroups: ["networking.k8s.io"]
resources: ["ingresses"]
verbs: ["get", "watch", "list", "create", "update", "patch", "delete"]
- apiGroups: ["traefik.io"]
resources: ["ingressroutes"]
verbs: ["get", "watch", "list", "create", "update", "patch", "delete"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: ci-cd
namespace: home-assistant
subjects:
- kind: ServiceAccount
name: casa-ci-cd
namespace: home-assistant
roleRef:
kind: Role
name: ci-cd
apiGroup: rbac.authorization.k8s.io

View File

@@ -0,0 +1,7 @@
apiVersion: v1
kind: Secret
metadata:
name: casa-ci-cd
annotations:
kubernetes.io/service-account.name: casa-ci-cd
type: kubernetes.io/service-account-token

View File

@@ -0,0 +1,6 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: casa-ci-cd
namespace: home-assistant

View File

@@ -0,0 +1,42 @@
apiVersion: v1
kind: Service
metadata:
name: home-assistant
namespace: home-assistant
spec:
clusterIP: None
ports:
- port: ${SERVICE_PORT}
protocol: TCP
---
apiVersion: v1
kind: Endpoints
metadata:
name: home-assistant
namespace: home-assistant
subsets:
- addresses:
- ip: ${ENDPOINT_IP}
ports:
- port: ${SERVICE_PORT}
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: home-assistant
namespace: home-assistant
spec:
entryPoints:
- websecure
routes:
- match: ${INGRESS_ROUTES_MATCH}
kind: Rule
services:
- name: home-assistant
port: ${SERVICE_PORT}
tls:
secretName: ${INGRESS_TLS_SECRET_NAME}

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

View File

Before

Width:  |  Height:  |  Size: 47 KiB

After

Width:  |  Height:  |  Size: 47 KiB

View File

Before

Width:  |  Height:  |  Size: 128 KiB

After

Width:  |  Height:  |  Size: 128 KiB

View File

Before

Width:  |  Height:  |  Size: 47 KiB

After

Width:  |  Height:  |  Size: 47 KiB