diff --git a/infra/docker/deploy-production.sh b/infra/docker/deploy-production.sh index 1326e497a..02cfd5b7c 100755 --- a/infra/docker/deploy-production.sh +++ b/infra/docker/deploy-production.sh @@ -77,5 +77,8 @@ docker compose --env-file "$ENV_FILE" run --rm --no-deps api sh -c ' python /app/scripts/validate_release_env.py --from-environ --strict-external && alembic upgrade head ' -docker compose --env-file "$ENV_FILE" up -d api worker web +docker compose --env-file "$ENV_FILE" up -d api worker +# Recreate web after API so nginx resolves the current API container IP. +# Docker's embedded DNS is resolved by nginx at startup for this static upstream. +docker compose --env-file "$ENV_FILE" up -d --force-recreate web docker compose --env-file "$ENV_FILE" ps diff --git a/tests/unit/test_release_scripts.py b/tests/unit/test_release_scripts.py index aa3be7cf7..ae64310db 100644 --- a/tests/unit/test_release_scripts.py +++ b/tests/unit/test_release_scripts.py @@ -44,6 +44,27 @@ def test_deploy_production_uses_production_infra_and_project(): assert "--env-file \"$ENV_FILE\"" in script assert "python /app/scripts/validate_release_env.py --from-environ --strict-external" in script assert "alembic upgrade head" in script + assert "docker compose --env-file \"$ENV_FILE\" up -d api worker" in script + assert "docker compose --env-file \"$ENV_FILE\" up -d --force-recreate web" in script + assert "nginx resolves the current API container IP" in script + + +def test_production_deploy_recreates_web_after_api_for_nginx_dns(): + script = Path("infra/docker/deploy-production.sh").read_text(encoding="utf-8") + + api_up = script.index('docker compose --env-file "$ENV_FILE" up -d api worker') + web_up = script.index('docker compose --env-file "$ENV_FILE" up -d --force-recreate web') + + assert api_up < web_up + assert "up -d api worker web" not in script + + +def test_production_nginx_static_upstream_requires_web_recreate(): + config = Path("infra/docker/nginx-production.conf").read_text(encoding="utf-8") + script = Path("infra/docker/deploy-production.sh").read_text(encoding="utf-8") + + assert "proxy_pass http://xiaoxia-api-production:8000/api/;" in config + assert "--force-recreate web" in script def test_production_infra_uses_separate_containers_and_ports():