From 06757f40f85cacedd78fefb3c5f13fd73a721c1f Mon Sep 17 00:00:00 2001 From: Francisco Solla Date: Mon, 17 Aug 2026 22:50:22 -0300 Subject: [PATCH] =?UTF-8?q?fix(ops=20OPS53):=20deploy=20=E2=80=94=20compos?= =?UTF-8?q?e=20run=20consome=20o=20stdin=20do=20bash=20-s=20(migrate=20com?= =?UTF-8?q?=20" < scripts/deploy-homeserver.sh`. 4. O script, no **homeserver**: guarda de HEAD (`main` remoto == SHA do job, senão skip) → `flock` (serializa) → build da imagem standalone + migrator - (BuildKit, secrets do `~/stack/teqo-1313.env`, rede `stack_default`) → + (BuildKit, secrets do `~/stack/teqo-1313.env`, `--network host` com proxy + socat `teqo-1313-build-proxy` na `stack_default` para o build alcançar o + `postgres` — o proxy é criado idempotentemente pelo script) → push em `localhost:5000` → swap dos tags de imagem no `~/stack/docker-compose.yml` (backup antes) → **migrations** - (`docker compose --profile maintenance run --rm teqo-1313-migrate`) → + (`docker compose --profile maintenance run --rm teqo-1313-migrate /dev/null 2>&1; then + docker run -d --name teqo-1313-build-proxy \ + --network stack_default \ + --restart unless-stopped \ + -p 127.0.0.1:5433:5433 \ + alpine/socat TCP-LISTEN:5433,fork TCP:postgres:5432 >/dev/null + fi +} + build_image() { local target="$1" image="$2" say "building $target ($image)" - DOCKER_BUILDKIT=1 docker build \ - --network stack_default \ + ensure_db_proxy + # The build's DATABASE_URL points at the loopback proxy; the outer env + # keeps the original value and nothing is echoed. + local build_db_url="${DATABASE_URL/@postgres:5432/@127.0.0.1:5433}" + DATABASE_URL="$build_db_url" DOCKER_BUILDKIT=1 docker build \ + --network host \ --build-arg "NEXT_PUBLIC_SITE_URL=$NEXT_PUBLIC_SITE_URL" \ --secret "id=database_url,env=DATABASE_URL" \ --secret "id=payload_secret,env=PAYLOAD_SECRET" \ @@ -134,7 +153,10 @@ trap 'rollback "unexpected failure"' ERR cd "$STACK_DIR" say "applying pending migrations (maintenance service teqo-1313-migrate)" -docker compose --profile maintenance run --rm teqo-1313-migrate || rollback "migrations failed" +# `< /dev/null`: `compose run` attaches stdin by default; the container would +# consume the rest of the script piped into `bash -s` (bash then hits EOF and +# exits right after the migrate step, skipping the rollout). +docker compose --profile maintenance run --rm teqo-1313-migrate { expect(script).toContain('id=payload_secret,env=PAYLOAD_SECRET') }) - it('builds inside the compose network so the static generation reaches the prod DB', () => { - expect(script).toContain('--network stack_default') + it('reaches the prod DB from the build (loopback proxy on the compose network)', () => { + // BuildKit rejects `--network `; the build uses --network host and + // a socat proxy (on stack_default, published on the host loopback) with a + // rewritten DATABASE_URL. + expect(script).toContain('--network host') + expect(script).toContain('teqo-1313-build-proxy') + expect(script).toContain('TCP:postgres:5432') + expect(script).toContain('127.0.0.1:5433') }) it('applies migrations through the maintenance service before the rollout', () => {