feat: add k8s manifests and gitops sync workflow for smart-home
Sync Smart Home Manifests to GitOps / Sync Manifests to GitOps Repo (push) Successful in 3s
Sync Smart Home Manifests to GitOps / Sync Manifests to GitOps Repo (push) Successful in 3s
This commit is contained in:
@@ -0,0 +1,76 @@
|
|||||||
|
name: Sync Smart Home Manifests to GitOps
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- master
|
||||||
|
paths:
|
||||||
|
- 'k8s/**'
|
||||||
|
- '.gitea/workflows/**'
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
env:
|
||||||
|
GITOPS_REPO: git.bnhmeijer.nl/bart/k8s-infra-vmserver.git
|
||||||
|
GITOPS_PATH: workloads/smart-home
|
||||||
|
ARGOCD_SERVER: ${{ vars.ARGOCD_SERVER || 'argocd.bnhmeijer.nl' }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
sync-to-gitops:
|
||||||
|
name: Sync Manifests to GitOps Repo
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout smart-home repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Sync manifests to k8s-infra-vmserver
|
||||||
|
env:
|
||||||
|
TOKEN: ${{ secrets.GITOPS_PAT || secrets.CI_TOKEN }}
|
||||||
|
GITEA_SHA: ${{ gitea.sha }}
|
||||||
|
run: |
|
||||||
|
git config --global user.name "Gitea Actions Bot"
|
||||||
|
git config --global user.email "actions@git.bnhmeijer.nl"
|
||||||
|
|
||||||
|
echo "Cloning GitOps repository..."
|
||||||
|
git clone https://${TOKEN}@${GITOPS_REPO} gitops-repo
|
||||||
|
|
||||||
|
echo "Syncing k8s manifests into ${GITOPS_PATH}..."
|
||||||
|
mkdir -p "gitops-repo/${GITOPS_PATH}"
|
||||||
|
rm -rf "gitops-repo/${GITOPS_PATH}"/*
|
||||||
|
cp -r k8s/* "gitops-repo/${GITOPS_PATH}/"
|
||||||
|
|
||||||
|
cd gitops-repo
|
||||||
|
if [ -n "$(git status --porcelain)" ]; then
|
||||||
|
git add .
|
||||||
|
git commit -m "ci(smart-home): sync manifests (${GITEA_SHA::7})"
|
||||||
|
git push origin main
|
||||||
|
echo "Successfully pushed updated manifests to k8s-infra-vmserver!"
|
||||||
|
else
|
||||||
|
echo "No manifest changes detected in GitOps repository."
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Trigger ArgoCD Sync for smart-home
|
||||||
|
env:
|
||||||
|
ARGOCD_SERVER: ${{ env.ARGOCD_SERVER }}
|
||||||
|
ARGOCD_TOKEN: ${{ secrets.ARGOCD_TOKEN }}
|
||||||
|
run: |
|
||||||
|
if [ -n "$ARGOCD_TOKEN" ]; then
|
||||||
|
SERVER_URL="${ARGOCD_SERVER}"
|
||||||
|
if [[ ! "$SERVER_URL" =~ ^https?:// ]]; then
|
||||||
|
SERVER_URL="https://${SERVER_URL}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Triggering ArgoCD sync for application smart-home on $SERVER_URL..."
|
||||||
|
RESPONSE=$(curl -s -S -k -w "\nHTTP_STATUS:%{http_code}" -X POST \
|
||||||
|
-H "Authorization: Bearer $ARGOCD_TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
"${SERVER_URL}/api/v1/applications/smart-home/sync" || true)
|
||||||
|
|
||||||
|
HTTP_STATUS=$(echo "$RESPONSE" | grep "HTTP_STATUS:" | cut -d':' -f2)
|
||||||
|
BODY=$(echo "$RESPONSE" | grep -v "HTTP_STATUS:")
|
||||||
|
echo "ArgoCD API Response (HTTP $HTTP_STATUS): $BODY"
|
||||||
|
else
|
||||||
|
echo "ARGOCD_TOKEN secret is not set, skipping ArgoCD sync trigger (ArgoCD auto-sync will pick up changes)."
|
||||||
|
fi
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: homeassistant
|
||||||
|
namespace: smart-home
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: homeassistant
|
||||||
|
app.kubernetes.io/part-of: smart-home
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
strategy:
|
||||||
|
type: Recreate
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: homeassistant
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: homeassistant
|
||||||
|
spec:
|
||||||
|
hostNetwork: true
|
||||||
|
dnsPolicy: ClusterFirstWithHostNet
|
||||||
|
nodeSelector:
|
||||||
|
kubernetes.io/hostname: vmserver
|
||||||
|
containers:
|
||||||
|
- name: homeassistant
|
||||||
|
image: ghcr.io/home-assistant/home-assistant:2026.9.4
|
||||||
|
env:
|
||||||
|
- name: TZ
|
||||||
|
value: "Europe/Amsterdam"
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 250m
|
||||||
|
memory: 512Mi
|
||||||
|
limits:
|
||||||
|
cpu: 2000m
|
||||||
|
memory: 4Gi
|
||||||
|
volumeMounts:
|
||||||
|
- name: config
|
||||||
|
mountPath: /config
|
||||||
|
livenessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /manifest.json
|
||||||
|
port: 8123
|
||||||
|
initialDelaySeconds: 60
|
||||||
|
periodSeconds: 20
|
||||||
|
timeoutSeconds: 5
|
||||||
|
readinessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /manifest.json
|
||||||
|
port: 8123
|
||||||
|
initialDelaySeconds: 30
|
||||||
|
periodSeconds: 10
|
||||||
|
timeoutSeconds: 5
|
||||||
|
volumes:
|
||||||
|
- name: config
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: homeassistant-config
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
|
||||||
|
namespace: smart-home
|
||||||
|
|
||||||
|
resources:
|
||||||
|
- namespace.yaml
|
||||||
|
- pvc.yaml
|
||||||
|
- service.yaml
|
||||||
|
- deployment.yaml
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: smart-home
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: smart-home
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: PersistentVolumeClaim
|
||||||
|
metadata:
|
||||||
|
name: homeassistant-config
|
||||||
|
namespace: smart-home
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: homeassistant
|
||||||
|
app.kubernetes.io/part-of: smart-home
|
||||||
|
spec:
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
storageClassName: local-path
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 20Gi
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: homeassistant
|
||||||
|
namespace: smart-home
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: homeassistant
|
||||||
|
app.kubernetes.io/part-of: smart-home
|
||||||
|
spec:
|
||||||
|
type: ClusterIP
|
||||||
|
ports:
|
||||||
|
- port: 8123
|
||||||
|
targetPort: 8123
|
||||||
|
protocol: TCP
|
||||||
|
name: http
|
||||||
|
selector:
|
||||||
|
app: homeassistant
|
||||||
Reference in New Issue
Block a user