Files
Flight-Ops/.gitea/workflows/ci.yml
T
2026-09-18 19:53:05 +00:00

117 lines
4.8 KiB
YAML

name: CI
on:
push:
branches: [master]
pull_request:
branches: [master]
workflow_dispatch:
jobs:
ci:
name: build + unit + e2e
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
# Full-dind runner: job containers already reach the runner's own docker daemon
# (pre-set DOCKER_HOST and/or a mounted /var/run/docker.sock) — no dind service.
# Find a working endpoint and export it as DOCKER_HOST for all later steps.
- name: Resolve docker daemon
run: |
set -u
# 1) A pre-set DOCKER_HOST that answers is used as-is, no probing.
if [ -n "${DOCKER_HOST:-}" ]; then
i=0
while [ "$i" -lt 5 ]; do
if docker version --format '{{.Server.Version}}' >/dev/null 2>&1; then
echo "using pre-set DOCKER_HOST=$DOCKER_HOST"
echo "DOCKER_HOST=$DOCKER_HOST" >> "$GITHUB_ENV"
exit 0
fi
i=$((i+1)); sleep 2
done
fi
# 2) Otherwise probe candidates in order (short retry each).
tried=""
for ep in "${DOCKER_HOST:-}" unix:///var/run/docker.sock tcp://localhost:2375 tcp://localhost:2376 tcp://docker:2375 tcp://docker:2376; do
[ -n "$ep" ] || continue
case " $tried " in *" $ep "*) continue ;; esac
tried="$tried $ep"
i=0
while [ "$i" -lt 10 ]; do
if DOCKER_HOST="$ep" docker version --format '{{.Server.Version}}' >/dev/null 2>&1; then
echo "using probed endpoint $ep"
echo "DOCKER_HOST=$ep" >> "$GITHUB_ENV"
exit 0
fi
i=$((i+1)); sleep 2
done
done
echo "::error::no reachable docker daemon (tried: ${DOCKER_HOST:-<unset>}, unix:///var/run/docker.sock, tcp://localhost:2375, tcp://localhost:2376, tcp://docker:2375, tcp://docker:2376)" >&2
exit 1
# Job and app containers share the daemon, so put them on one user-defined network
# and reach the app by service DNS — no endpoint-derived URLs (the job's netns has
# no default route on this runner). The alias `app` is declared in docker-compose.ci.yml.
- name: Prepare e2e network
run: |
set -u
docker network inspect flight-ci-e2e >/dev/null 2>&1 || docker network create flight-ci-e2e
if ! docker network connect flight-ci-e2e "$(hostname)"; then
echo "::error::failed to attach job container '$(hostname)' to flight-ci-e2e — the job must run in a container on the shared daemon (check runner config)" >&2
exit 1
fi
docker network inspect flight-ci-e2e --format 'containers on flight-ci-e2e: {{range .Containers}}{{.Name}} {{end}}'
echo "E2E_BASE_URL=http://app:3000" >> "$GITHUB_ENV"
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22
# bun drives installs (repo ships bun.lock, no package-lock.json); pinned to the
# same major as oven/bun in the Dockerfile.
- name: Install bun
run: npm i -g bun@1.4.2
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Build
run: npm run build
- name: Unit tests
run: npx vitest run
# Browsers run locally in CI (PW_REMOTE_BROWSER=0 below): the shared remote browser
# server at 192.168.1.4 cannot reach a stack inside dind, and local chromium keeps
# the job self-contained.
- name: Install browsers (local)
run: npx playwright install --with-deps chromium
# E2E against an isolated stack on the shared daemon — never the production instance.
# docker-compose.ci.yml joins the flight-ci-e2e network prepared above; project name
# flight-ci keeps it distinct from production. E2E_DEPLOY_CMD makes the config's
# webServer block deploy + wait for readiness (http://app:3000 via service DNS);
# E2E_COMPOSE_ARGS points state.spec.ts' mid-run `docker compose restart flight` at
# the same file + project. DOCKER_HOST/E2E_BASE_URL come from GITHUB_ENV above.
- name: E2E (isolated stack in dind)
env:
PW_REMOTE_BROWSER: "0"
E2E_DEPLOY_CMD: docker compose -f docker-compose.ci.yml -p flight-ci up -d --build
E2E_COMPOSE_ARGS: "-f docker-compose.ci.yml -p flight-ci"
run: npx playwright test
# The daemon is shared with production — never leave our stack or network behind.
# -v drops the named DB volume so every run seeds fresh (no schema drift between PRs).
- name: Cleanup e2e stack + network
if: always()
run: |
docker compose -f docker-compose.ci.yml -p flight-ci down --remove-orphans -v || true
docker network remove flight-ci-e2e 2>/dev/null || true