2026-06-25 10:04:59 -04:00
|
|
|
name: Build & Push Images
|
|
|
|
|
|
|
|
|
|
# Builds the frontend + backend Docker images and pushes them to the Forgejo
|
2026-06-25 10:55:15 -04:00
|
|
|
# container registry (registry.snsnetlabs.com/sam/...). Runs on every push to
|
2026-06-25 10:04:59 -04:00
|
|
|
# main, and on-demand via the "Run workflow" button (workflow_dispatch).
|
|
|
|
|
#
|
2026-06-25 10:55:15 -04:00
|
|
|
# NOTE: registry.snsnetlabs.com is the unproxied (DNS-only) registry host so
|
|
|
|
|
# large layers bypass Cloudflare's body cap. The web UI / packages list stays
|
|
|
|
|
# on forgejo.snsnetlabs.com (Cloudflare Access SSO).
|
|
|
|
|
#
|
2026-06-25 10:04:59 -04:00
|
|
|
# Requirements (see deploy/README.md):
|
|
|
|
|
# - Forgejo Actions secret FORGEJO_REGISTRY_TOKEN: a package-scoped token for
|
|
|
|
|
# user `sam`.
|
|
|
|
|
# - The runner must allow Docker builds: container.docker_host = "automount"
|
|
|
|
|
# in the forgejo-runner config (mounts /var/run/docker.sock into the job).
|
|
|
|
|
|
|
|
|
|
on:
|
|
|
|
|
push:
|
|
|
|
|
branches: [main]
|
|
|
|
|
workflow_dispatch:
|
|
|
|
|
|
|
|
|
|
env:
|
2026-06-25 10:55:15 -04:00
|
|
|
REGISTRY: registry.snsnetlabs.com
|
2026-06-25 10:04:59 -04:00
|
|
|
OWNER: sam
|
|
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
|
build:
|
|
|
|
|
runs-on: docker
|
|
|
|
|
steps:
|
|
|
|
|
- name: Checkout
|
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
|
|
|
|
|
- name: Install Docker CLI
|
2026-06-25 11:13:01 -04:00
|
|
|
# Debian bookworm's docker.io is too old (API 1.41) for the host daemon
|
|
|
|
|
# (needs >= 1.44), so install the current docker-ce-cli from Docker's repo.
|
2026-06-25 10:04:59 -04:00
|
|
|
run: |
|
|
|
|
|
apt-get update
|
2026-06-25 11:13:01 -04:00
|
|
|
apt-get install -y --no-install-recommends ca-certificates curl
|
|
|
|
|
install -m 0755 -d /etc/apt/keyrings
|
|
|
|
|
curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
|
|
|
|
|
chmod a+r /etc/apt/keyrings/docker.asc
|
|
|
|
|
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian bookworm stable" > /etc/apt/sources.list.d/docker.list
|
|
|
|
|
apt-get update
|
|
|
|
|
apt-get install -y --no-install-recommends docker-ce-cli
|
2026-06-25 10:04:59 -04:00
|
|
|
docker version
|
|
|
|
|
|
|
|
|
|
- name: Log in to Forgejo registry
|
|
|
|
|
run: |
|
|
|
|
|
echo "${{ secrets.FORGEJO_REGISTRY_TOKEN }}" \
|
|
|
|
|
| docker login "$REGISTRY" -u "$OWNER" --password-stdin
|
|
|
|
|
|
|
|
|
|
- name: Build & push frontend image
|
|
|
|
|
run: |
|
|
|
|
|
docker build \
|
|
|
|
|
-t "$REGISTRY/$OWNER/archnest:${{ github.sha }}" \
|
|
|
|
|
-t "$REGISTRY/$OWNER/archnest:latest" \
|
|
|
|
|
-f Dockerfile .
|
|
|
|
|
docker push "$REGISTRY/$OWNER/archnest:${{ github.sha }}"
|
|
|
|
|
docker push "$REGISTRY/$OWNER/archnest:latest"
|
|
|
|
|
|
|
|
|
|
- name: Build & push backend image
|
|
|
|
|
run: |
|
|
|
|
|
docker build \
|
|
|
|
|
-t "$REGISTRY/$OWNER/archnest-backend:${{ github.sha }}" \
|
|
|
|
|
-t "$REGISTRY/$OWNER/archnest-backend:latest" \
|
|
|
|
|
-f backend/Dockerfile backend
|
|
|
|
|
docker push "$REGISTRY/$OWNER/archnest-backend:${{ github.sha }}"
|
|
|
|
|
docker push "$REGISTRY/$OWNER/archnest-backend:latest"
|
|
|
|
|
|
|
|
|
|
- name: Log out
|
|
|
|
|
if: always()
|
|
|
|
|
run: docker logout "$REGISTRY"
|
2026-06-25 11:34:27 -04:00
|
|
|
|
|
|
|
|
deploy:
|
|
|
|
|
# Auto-deploy to racknerd2 after a successful build. Deploys the exact
|
|
|
|
|
# images just built (pinned to this commit's SHA). For manual/on-demand
|
|
|
|
|
# deploys of an arbitrary tag (e.g. rollback), use the separate
|
|
|
|
|
# "Deploy to racknerd2" workflow (deploy.yml).
|
|
|
|
|
needs: build
|
|
|
|
|
runs-on: docker
|
|
|
|
|
env:
|
|
|
|
|
DEPLOY_HOST: 100.96.217.250
|
|
|
|
|
DEPLOY_DIR: /opt/archnest
|
|
|
|
|
steps:
|
|
|
|
|
- name: Install SSH client
|
|
|
|
|
run: |
|
|
|
|
|
apt-get update
|
|
|
|
|
apt-get install -y --no-install-recommends openssh-client
|
|
|
|
|
|
|
|
|
|
- name: Write deploy key
|
|
|
|
|
run: |
|
|
|
|
|
install -m 700 -d ~/.ssh
|
|
|
|
|
printf '%s\n' "${{ secrets.RACKNERD2_SSH_KEY }}" > ~/.ssh/id_deploy
|
|
|
|
|
chmod 600 ~/.ssh/id_deploy
|
|
|
|
|
|
|
|
|
|
- name: Pull this build's images and restart stack
|
|
|
|
|
run: |
|
|
|
|
|
ssh -i ~/.ssh/id_deploy -o StrictHostKeyChecking=accept-new \
|
|
|
|
|
root@"$DEPLOY_HOST" \
|
|
|
|
|
"cd $DEPLOY_DIR && ARCHNEST_TAG='${{ github.sha }}' docker compose pull && ARCHNEST_TAG='${{ github.sha }}' docker compose up -d --remove-orphans"
|
|
|
|
|
|
|
|
|
|
- name: Health check (backend /api/health via mesh)
|
|
|
|
|
run: |
|
|
|
|
|
ssh -i ~/.ssh/id_deploy -o StrictHostKeyChecking=accept-new \
|
|
|
|
|
root@"$DEPLOY_HOST" \
|
|
|
|
|
"for i in \$(seq 1 30); do curl -fsS http://$DEPLOY_HOST:8080/api/health && echo OK && exit 0; sleep 2; done; echo 'health check failed'; cd $DEPLOY_DIR && docker compose logs --tail=50; exit 1"
|