feat(deploy): Docker image + Komodo compose stack + Gitea CI pipeline

- Dockerfile: node:24-alpine builds frontend/dist, python:3.13-slim runs
  backend.main as uid 1000 under tini; state on /data via env overrides
- compose.yaml: raw 9000:9000 for the charger's hardcoded ws:// dial-in,
  Traefik labels for the panel, everything Komodo-tunable (ARTIOT_TAG/HOST,
  TRAEFIK_NETWORK, entrypoint, certresolver), curl healthcheck
- .gitea/workflows/build.yml: build -> 65-check smoke gate in the image ->
  push :main + :sha to git.infra.msai.al/art/charging_station -> HMAC-signed
  Komodo stack redeploy (polymarket-bot pattern; same secret names)
This commit is contained in:
2026-07-12 10:32:47 +02:00
parent 5f33eedbb1
commit 268bed5d92
4 changed files with 235 additions and 0 deletions
+95
View File
@@ -0,0 +1,95 @@
name: Build Art IoT image
on:
push:
branches: [main]
paths:
- 'backend/**'
- 'frontend/**'
- 'Dockerfile'
- '.dockerignore'
- 'compose.yaml'
- '.gitea/workflows/build.yml'
workflow_dispatch:
jobs:
build-and-publish:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
# -------------------------------------------------------------------------
# Plain `docker build` (not buildx) so the image is visible to `docker run`
# for the smoke test below — buildx's docker-container driver exports to a
# separate buildkitd cache that `docker run` can't see.
# -------------------------------------------------------------------------
- name: Build image
run: docker build -t artiot:ci .
# -------------------------------------------------------------------------
# Smoke test gate: 65 checks against the freshly built image — REST auth/
# scopes, per-gun cards, pending-card workflow, OCPP WS round-trips via a
# fake charge point, session store, SPA serving. All in-process (fastapi
# TestClient) against a temp db; no network listeners needed.
#
# --user root only because httpx (TestClient's transport, test-only dep)
# isn't shipped in the runtime image and uid 1000 can't pip-install.
# If this fails, the workflow halts and the broken image is never pushed.
# -------------------------------------------------------------------------
- name: Smoke test
timeout-minutes: 3
run: |
docker run --rm --user root artiot:ci sh -c \
"pip install --no-cache-dir -q httpx && python -m backend.smoke_test"
# -------------------------------------------------------------------------
# Registry login — only runs if the smoke test passed.
# -------------------------------------------------------------------------
- name: Login to Gitea registry
uses: docker/login-action@v3
with:
registry: git.infra.msai.al
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
# -------------------------------------------------------------------------
# Two tags:
# :<branch> — mutable; the compose stack's default (ARTIOT_TAG=main).
# :<sha> — immutable; set ARTIOT_TAG=<sha> in Komodo for a pinned
# rollback.
# -------------------------------------------------------------------------
- name: Tag and push image
env:
BRANCH: ${{ github.ref_name }}
SHA: ${{ github.sha }}
IMG: git.infra.msai.al/art/charging_station
run: |
docker tag artiot:ci $IMG:$BRANCH
docker tag artiot:ci $IMG:$SHA
docker push $IMG:$BRANCH
docker push $IMG:$SHA
# -------------------------------------------------------------------------
# Trigger the Komodo Stack redeploy. HMAC-validated webhook — same pattern
# as the polymarket-bot repo. Both secrets must be set on this repo:
# KOMODO_STACK_WEBHOOK_URL, KOMODO_WEBHOOK_SECRET
# -------------------------------------------------------------------------
- name: Trigger Komodo Stack redeploy
if: success()
env:
URL: ${{ secrets.KOMODO_STACK_WEBHOOK_URL }}
SECRET: ${{ secrets.KOMODO_WEBHOOK_SECRET }}
run: |
if [ -z "$URL" ] || [ -z "$SECRET" ]; then
echo "Komodo webhook secrets not set — skipping redeploy trigger."
exit 0
fi
body='{"ref":"refs/heads/${{ github.ref_name }}"}'
sig=$(printf '%s' "$body" | openssl dgst -sha256 -hmac "$SECRET" | awk '{print $2}')
curl -fsS -X POST \
-H 'Content-Type: application/json' \
-H "X-Hub-Signature-256: sha256=$sig" \
-d "$body" \
"$URL"