name: CI/CD on: push: pull_request: # Registry on the local Gitea instance (HTTP — add to Docker insecure-registries if needed) env: REGISTRY: 192.168.0.234:8765 # Deployment directory on the host — compose file lives here so relative # volume paths (./infra/traefik/...) resolve correctly on the host. DEPLOY_DIR: /opt/ems jobs: # ── Test ────────────────────────────────────────────────────────────────── # Runs on every push and every PR. test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Install Go 1.23 run: | wget -qO go.tar.gz https://go.dev/dl/go1.23.4.linux-arm64.tar.gz sudo tar -C /usr/local -xzf go.tar.gz rm go.tar.gz echo "/usr/local/go/bin" >> $GITHUB_PATH - name: Run unit tests run: go test ./... - name: Build binary (compile check) run: CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /dev/null . # ── Build & Push ────────────────────────────────────────────────────────── # Builds the Docker image and pushes it to the Gitea container registry. # Runs on house/lutz and main; skipped on other branches and PRs. # # Required secret: # GITEA_TOKEN — personal access token with write:packages permission build-push: needs: test runs-on: ubuntu-latest if: github.ref == 'refs/heads/house/lutz' || github.ref == 'refs/heads/main' steps: - uses: actions/checkout@v4 - name: Log in to Gitea registry run: | echo "${{ secrets.MY_GITEA_CI_TOKEN }}" | \ docker login ${{ env.REGISTRY }} -u ${{ gitea.actor }} --password-stdin - name: Build and push image run: | IMAGE=${{ env.REGISTRY }}/${{ gitea.repository_owner }}/ems docker build \ -t ${IMAGE}:${{ gitea.sha }} \ -t ${IMAGE}:latest \ . docker push ${IMAGE}:${{ gitea.sha }} docker push ${IMAGE}:latest echo "IMAGE=${IMAGE}:${{ gitea.sha }}" >> $GITHUB_ENV # ── Deploy ──────────────────────────────────────────────────────────────── # Syncs compose + infra files to DEPLOY_DIR on the host, then restarts # only the EMS container. Traefik keeps running untouched. # # Uses a docker:cli helper container so that: # - relative paths in docker-compose.yml resolve from DEPLOY_DIR on the host # - Docker socket gives access to the host daemon from within the job container deploy: needs: build-push runs-on: ubuntu-latest if: github.ref == 'refs/heads/house/lutz' || github.ref == 'refs/heads/main' steps: - uses: actions/checkout@v4 - name: Log in to Gitea registry run: | echo "${{ secrets.MY_GITEA_CI_TOKEN }}" | \ docker login ${{ env.REGISTRY }} -u ${{ gitea.actor }} --password-stdin - name: Sync files and restart EMS run: | IMAGE=${{ env.REGISTRY }}/${{ gitea.repository_owner }}/ems:${{ gitea.sha }} SHA=${{ gitea.sha }} REPO_URL=http://x:${{ secrets.MY_GITEA_CI_TOKEN }}@192.168.0.234:8765/${{ gitea.repository }}.git # The helper container mounts /opt/ems from the HOST (absolute path — works). # It clones/updates the repo there so relative paths in docker-compose.yml # (./infra/traefik/...) resolve correctly when Docker Compose runs. docker run --rm \ -v /var/run/docker.sock:/var/run/docker.sock \ -v ${{ env.DEPLOY_DIR }}:${{ env.DEPLOY_DIR }} \ -e EMS_IMAGE=${IMAGE} \ docker:cli sh -c " set -e apk add -q git git config --global --add safe.directory ${{ env.DEPLOY_DIR }} if [ -d ${{ env.DEPLOY_DIR }}/.git ]; then git -C ${{ env.DEPLOY_DIR }} fetch --quiet else git clone --quiet ${REPO_URL} ${{ env.DEPLOY_DIR }} fi git -C ${{ env.DEPLOY_DIR }} checkout --quiet ${SHA} cd ${{ env.DEPLOY_DIR }} docker compose pull ems docker compose up -d ems " - name: Verify health run: | sleep 10 wget -qO- http://localhost:9099/health && echo " — OK"