diff --git a/docs/ops/teqo-1313-deploy.md b/docs/ops/teqo-1313-deploy.md index f6509030..8b5cc0c5 100644 --- a/docs/ops/teqo-1313-deploy.md +++ b/docs/ops/teqo-1313-deploy.md @@ -12,10 +12,12 @@ com a suite verde publica o site em `jorgesolla1313.com.br` — sem passo manual `ssh homeserver "bash -s -- " < 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