Compare commits
9 Commits
fea4db704f
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 73fe328336 | |||
| a079ae8ffd | |||
| dbecd67471 | |||
| 2881eb1167 | |||
| 755d68a844 | |||
| f40a899200 | |||
| d30aad3058 | |||
| 6149826bc6 | |||
| 0d2b30a83a |
@@ -1,51 +0,0 @@
|
|||||||
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 -x
|
|
||||||
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 "config created - ${GITHUB_TEMP}/.kube/config"
|
|
||||||
ls -lah ${GITHUB_TEMP}/.kube/config
|
|
||||||
echo "KUBECONFIG=${GITHUB_TEMP}/.kube/config" >> "${GITHUB_ENV}"
|
|
||||||
|
|
||||||
# curl -vk \
|
|
||||||
# --cacert ca.crt \
|
|
||||||
# -H "Authorization: Bearer $KUBE_TOKEN" \
|
|
||||||
# https://<server>:6443/version
|
|
||||||
@@ -1,23 +1,35 @@
|
|||||||
name: Casa Home Assistant CI/CD Pipeline (testing)
|
name: Casa Home Assistant CI/CD Pipeline
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- fix/*
|
- fix/*
|
||||||
- main
|
- main
|
||||||
|
- master
|
||||||
pull_request:
|
pull_request:
|
||||||
|
schedule:
|
||||||
|
- cron: '0 16 * * 0' # every sunday 4 pm
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
deploy:
|
||||||
runs-on: casa-vlan-cicd
|
runs-on: casa-vlan-cicd
|
||||||
env:
|
env:
|
||||||
GITHUB_TEMP: ${{ runner.temp }}
|
GITHUB_TEMP: ${{ runner.temp }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Fetch limbo public actions
|
||||||
|
env:
|
||||||
|
RUNNER_TEMP: "${{ runner.temp }}"
|
||||||
|
WORKSPACE: "${{ gitea.workspace }}"
|
||||||
|
run: |
|
||||||
|
curl -fsSL https://git.limbosolutions.com/kb/gitea/raw/branch/main/cloud-scripts/setup-limbo-actions.sh | bash 2>&1
|
||||||
|
|
||||||
- name: Setup kubectl
|
- name: Setup kubectl
|
||||||
uses: ./.gitea/actions/kubectl-setup
|
uses: ./.gitea/limbo_actions/kubectl-setup
|
||||||
with:
|
with:
|
||||||
kube_server: ${{ secrets.CASA_VLAN_KUBE_SERVER }}
|
kube_server: ${{ secrets.CASA_VLAN_KUBE_SERVER }}
|
||||||
kube_ca_base64: ${{ secrets.CASA_VLAN_KUBE_CA_BASE64 }}
|
kube_ca_base64: ${{ secrets.CASA_VLAN_KUBE_CA_BASE64 }}
|
||||||
@@ -25,15 +37,6 @@ jobs:
|
|||||||
|
|
||||||
- name: Deploy Home Assistant
|
- name: Deploy Home Assistant
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
|
||||||
ENDPOINT_IP: "${{ secrets.CASA_HOMEASSISTANT_ENDPOINT_IP }}"
|
|
||||||
SERVICE_PORT: "${{ secrets.CASA_HOMEASSISTANT_ENDPOINT_SERVICE_PORT }}"
|
|
||||||
INGRESS_ROUTES_MATCH: "${{ secrets.CASA_HOMEASSISTANT_INGRESS_ROUTES_MATCH }}"
|
|
||||||
INGRESS_TLS_SECRET_NAME: "${{ secrets.CASA_HOMEASSISTANT_INGRESS_TLS_SECRET_NAME }}"
|
|
||||||
run: |
|
run: |
|
||||||
#set -x for debugging
|
./ops-scripts/apply-app.sh
|
||||||
set -e
|
|
||||||
cd ${{ gitea.workspace }}
|
|
||||||
kubectl apply -f ./deploy/deployment.yaml
|
|
||||||
envsubst < ./deploy/service.template.yaml
|
|
||||||
|
|
||||||
@@ -2,10 +2,9 @@
|
|||||||
|
|
||||||
Welcome to my Home Assistant setup repository.
|
Welcome to my Home Assistant setup repository.
|
||||||
This repository documents and maintains the Home Assistant instance running in my home, hosted on casa server k3s cluster.
|
This repository documents and maintains the Home Assistant instance running in my home, hosted on casa server k3s cluster.
|
||||||
All essential containers, such as MQTT and speech recognition, are hosted on the same server for seamless integration.
|
Related containers, such as MQTT and speech recognition, are hosted on same cluster.
|
||||||
|
|
||||||
<!-- omit in toc -->
|
**Table of Contents:**
|
||||||
## Table of Contents
|
|
||||||
|
|
||||||
- [Devices](#devices)
|
- [Devices](#devices)
|
||||||
- [Broadlink - RM4 Pro](#broadlink---rm4-pro)
|
- [Broadlink - RM4 Pro](#broadlink---rm4-pro)
|
||||||
@@ -255,4 +254,6 @@ Home Assistant authenticates with Xbox Live through OAuth2 using the Home Assist
|
|||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
[Deploy documentation](./deploy/README.md).
|
``` bash
|
||||||
|
./ops-scripts/apply-app.sh
|
||||||
|
```
|
||||||
|
|||||||
7
deploy/app/kustomization.yaml
Normal file
7
deploy/app/kustomization.yaml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
resources:
|
||||||
|
- pvc.yaml
|
||||||
|
- statefulset.yaml
|
||||||
|
generatorOptions:
|
||||||
|
disableNameSuffixHash: true
|
||||||
12
deploy/app/pvc.yaml
Normal file
12
deploy/app/pvc.yaml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: PersistentVolumeClaim
|
||||||
|
metadata:
|
||||||
|
name: home-assistant-config
|
||||||
|
namespace: home-assistant
|
||||||
|
spec:
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 8Gi
|
||||||
|
storageClassName: local-path
|
||||||
@@ -1,19 +1,3 @@
|
|||||||
---
|
|
||||||
|
|
||||||
apiVersion: v1
|
|
||||||
kind: PersistentVolumeClaim
|
|
||||||
metadata:
|
|
||||||
name: home-assistant-config
|
|
||||||
namespace: home-assistant
|
|
||||||
spec:
|
|
||||||
accessModes:
|
|
||||||
- ReadWriteOnce
|
|
||||||
resources:
|
|
||||||
requests:
|
|
||||||
storage: 8Gi
|
|
||||||
storageClassName: local-path
|
|
||||||
---
|
|
||||||
|
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: StatefulSet
|
kind: StatefulSet
|
||||||
metadata:
|
metadata:
|
||||||
@@ -33,17 +17,18 @@ spec:
|
|||||||
spec:
|
spec:
|
||||||
dnsPolicy: ClusterFirstWithHostNet # ensures pod uses cluster DNS (CoreDNS) for service discovery even with host networking
|
dnsPolicy: ClusterFirstWithHostNet # ensures pod uses cluster DNS (CoreDNS) for service discovery even with host networking
|
||||||
hostNetwork: true
|
hostNetwork: true
|
||||||
# delays start so host have time to start on low memory resources
|
nodeName: casa # force deploy to master node cluster
|
||||||
# initContainers:
|
tolerations:
|
||||||
# - name: delay-start
|
- key: "node-role.kubernetes.io/control-plane" # allow installation on control-plane
|
||||||
# image: busybox:latest
|
operator: "Exists"
|
||||||
# command: ["sh", "-c", "sleep 60"]
|
effect: "NoSchedule"
|
||||||
containers:
|
containers:
|
||||||
- name: home-assistant
|
- name: home-assistant
|
||||||
image: "homeassistant/home-assistant"
|
image: "homeassistant/home-assistant"
|
||||||
|
imagePullPolicy: Always
|
||||||
env:
|
env:
|
||||||
- name: TZ
|
- name: TZ
|
||||||
value: Europe/Lisbon # set timezone
|
value: Europe/Lisbon
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: home-assistant-config
|
- name: home-assistant-config
|
||||||
mountPath: /config
|
mountPath: /config
|
||||||
@@ -54,6 +39,7 @@ spec:
|
|||||||
limits:
|
limits:
|
||||||
memory: "724Mi"
|
memory: "724Mi"
|
||||||
cpu: "1000m"
|
cpu: "1000m"
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
- name: home-assistant-config
|
- name: home-assistant-config
|
||||||
persistentVolumeClaim:
|
persistentVolumeClaim:
|
||||||
@@ -44,8 +44,8 @@ All Environment variables requirements as set as secrets.
|
|||||||
|
|
||||||
[gitea workflow](../.gitea/workflows/deploy.yaml)
|
[gitea workflow](../.gitea/workflows/deploy.yaml)
|
||||||
|
|
||||||
## RBAC
|
## cicd RBAC
|
||||||
|
|
||||||
```bash { cwd=../ }
|
```bash { cwd=../ }
|
||||||
kubectl apply -f ./deploy/rbac.yaml
|
kubectl apply -f ./deploy/cicd-rbac.yaml
|
||||||
```
|
```
|
||||||
55
docs/tests.md
Normal file
55
docs/tests.md
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
# tests
|
||||||
|
|
||||||
|
## logs from loki
|
||||||
|
|
||||||
|
```python
|
||||||
|
# loki-get-last-to-sensor.py
|
||||||
|
import sys, os, requests, datetime, time, json
|
||||||
|
|
||||||
|
url = os.environ.get("LOKI_ADDRESS")
|
||||||
|
|
||||||
|
if not url:
|
||||||
|
print(json.dumps({"state": "error", "log_message": "LOKI_ADDRESS is not set or empty"}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
query = os.environ.get("LOKI_QUERY")
|
||||||
|
if not query:
|
||||||
|
print(json.dumps({"state": "error", "log_message": "LOKI_ADDRESS is not set or empty"}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
end = int(time.time()) * 1_000_000_000
|
||||||
|
start = (int(time.time()) - 24*60*60) * 1_000_000_000
|
||||||
|
|
||||||
|
|
||||||
|
params = {
|
||||||
|
"query": query,
|
||||||
|
"limit": 1,
|
||||||
|
"direction": "backward",
|
||||||
|
"start": str(start),
|
||||||
|
"end": str(end),
|
||||||
|
}
|
||||||
|
|
||||||
|
resp = requests.get(url, params=params)
|
||||||
|
data = resp.json()
|
||||||
|
|
||||||
|
try:
|
||||||
|
ns = int(data["data"]["result"][0]["values"][0][0])
|
||||||
|
ts = ns / 1_000_000_000
|
||||||
|
dt = datetime.datetime.fromtimestamp(ts).strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
print(json.dumps({
|
||||||
|
"state": dt,
|
||||||
|
}))
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
print(json.dumps({"state": "unknown"}))
|
||||||
|
```
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# example of the sensor
|
||||||
|
name: git_limbosolutions_com_last_pbs_backup
|
||||||
|
command: >
|
||||||
|
LOKI_ADDRESS=${LOKI_ADDRESS} LOKI_QUERY="{job=\"git-limbosolutions-com/pbs-backup\"} |= \"INFO: Finished Backup\"" python3 /config/scripts/loki-get-last-to-sensor.py
|
||||||
|
value_template: "{{ value }}"
|
||||||
|
```
|
||||||
5
ops-scripts/apply-app.sh
Executable file
5
ops-scripts/apply-app.sh
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
echo "Executing app deploy."
|
||||||
|
|
||||||
|
kubectl kustomize deploy/app | kubectl apply -f -
|
||||||
5
ops-scripts/apply-infra.sh
Executable file
5
ops-scripts/apply-infra.sh
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
echo "Executing infra deploy."
|
||||||
|
|
||||||
|
kubectl kustomize deploy/infra | kubectl apply -f -
|
||||||
Reference in New Issue
Block a user