diff --git a/.github/scripts/modal-custom-domain-smoke.sh b/.github/scripts/modal-custom-domain-smoke.sh deleted file mode 100755 index 02533a68..00000000 --- a/.github/scripts/modal-custom-domain-smoke.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -modal_environment="${MODAL_ENVIRONMENT:-main}" -modal_get_url_script="${MODAL_GET_URL_SCRIPT:-.github/scripts/modal-get-url.sh}" -custom_domain_url="${HOUSEHOLD_MODAL_GATEWAY_CUSTOM_DOMAIN_URL:-https://household.api.policyengine.org}" - -if [ "${modal_environment}" != "main" ]; then - echo "Skipping custom-domain smoke check outside the main Modal environment." - exit 0 -fi - -gateway_url="$(bash "${modal_get_url_script}")" -custom_domain_url="${custom_domain_url%/}" -gateway_url="${gateway_url%/}" - -tmpdir="$(mktemp -d)" -trap 'rm -rf "${tmpdir}"' EXIT - -gateway_versions="${tmpdir}/gateway-versions.json" -custom_versions="${tmpdir}/custom-domain-versions.json" - -echo "Checking generated Modal gateway at ${gateway_url}" -curl -fsS "${gateway_url}/liveness_check" >/dev/null -curl -fsS "${gateway_url}/versions/us" > "${gateway_versions}" - -echo "Checking production custom domain at ${custom_domain_url}" -curl -fsS "${custom_domain_url}/liveness_check" >/dev/null -curl -fsS "${custom_domain_url}/versions/us" > "${custom_versions}" - -python - "${gateway_versions}" "${custom_versions}" <<'PY' -import json -import sys -from pathlib import Path - - -def load_versions(path: str, label: str) -> dict[str, str]: - try: - data = json.loads(Path(path).read_text()) - except json.JSONDecodeError as e: - sys.exit(f"{label} /versions/us did not return JSON: {e}") - - if not isinstance(data, dict): - sys.exit(f"{label} /versions/us returned a non-object JSON value") - return data - - -gateway_versions = load_versions(sys.argv[1], "Generated Modal gateway") -custom_versions = load_versions(sys.argv[2], "Custom domain") - -if gateway_versions != custom_versions: - sys.exit( - "Custom domain /versions/us does not match the generated Modal " - f"gateway. generated={gateway_versions!r} custom={custom_versions!r}" - ) - -print("Custom domain points at the deployed Modal gateway.") -PY diff --git a/.github/scripts/test_modal_custom_domain_smoke.py b/.github/scripts/test_modal_custom_domain_smoke.py deleted file mode 100644 index 53c596a3..00000000 --- a/.github/scripts/test_modal_custom_domain_smoke.py +++ /dev/null @@ -1,141 +0,0 @@ -import os -from pathlib import Path -import subprocess - - -SCRIPT = ".github/scripts/modal-custom-domain-smoke.sh" - - -def test_modal_custom_domain_smoke_passes_when_versions_match(tmp_path): - env = _smoke_env( - tmp_path, - gateway_versions='{"current":"1.691.1","frontier":"1.691.1"}', - custom_versions='{"current":"1.691.1","frontier":"1.691.1"}', - ) - - result = subprocess.run( - ["bash", SCRIPT], - capture_output=True, - env=env, - text=True, - ) - - assert result.returncode == 0, result.stderr - assert ( - "Custom domain points at the deployed Modal gateway." in result.stdout - ) - - -def test_modal_custom_domain_smoke_fails_when_custom_domain_is_not_gateway( - tmp_path, -): - env = _smoke_env( - tmp_path, - gateway_versions='{"current":"1.691.1","frontier":"1.691.1"}', - custom_versions="OK", - ) - - result = subprocess.run( - ["bash", SCRIPT], - capture_output=True, - env=env, - text=True, - ) - - assert result.returncode == 1 - assert "Custom domain /versions/us did not return JSON" in result.stderr - - -def test_modal_custom_domain_smoke_fails_when_versions_differ(tmp_path): - env = _smoke_env( - tmp_path, - gateway_versions='{"current":"1.691.1","frontier":"1.691.1"}', - custom_versions='{"current":"1.690.0","frontier":"1.691.1"}', - ) - - result = subprocess.run( - ["bash", SCRIPT], - capture_output=True, - env=env, - text=True, - ) - - assert result.returncode == 1 - assert "does not match the generated Modal gateway" in result.stderr - - -def test_modal_custom_domain_smoke_skips_non_main_environments(tmp_path): - curl_log = tmp_path / "curl.log" - env = _smoke_env( - tmp_path, - gateway_versions='{"current":"1.691.1"}', - custom_versions='{"current":"1.691.1"}', - ) - env["MODAL_ENVIRONMENT"] = "staging" - env["CURL_LOG"] = str(curl_log) - - result = subprocess.run( - ["bash", SCRIPT], - capture_output=True, - env=env, - text=True, - ) - - assert result.returncode == 0 - assert "Skipping custom-domain smoke check" in result.stdout - assert not curl_log.exists() - - -def _smoke_env( - tmp_path: Path, - *, - gateway_versions: str, - custom_versions: str, -) -> dict[str, str]: - get_url_script = tmp_path / "modal-get-url.sh" - get_url_script.write_text( - "#!/usr/bin/env bash\n" - "set -euo pipefail\n" - "echo https://generated-modal.example\n" - ) - get_url_script.chmod(0o755) - - fake_curl = tmp_path / "curl" - fake_curl.write_text( - """#!/usr/bin/env bash -set -euo pipefail -url="${@: -1}" -if [ -n "${CURL_LOG:-}" ]; then - printf '%s\\n' "${url}" >> "${CURL_LOG}" -fi - -case "${url}" in - https://generated-modal.example/liveness_check|https://custom-domain.example/liveness_check) - echo OK - ;; - https://generated-modal.example/versions/us) - printf '%s\\n' "${GATEWAY_VERSIONS}" - ;; - https://custom-domain.example/versions/us) - printf '%s\\n' "${CUSTOM_VERSIONS}" - ;; - *) - echo "Unexpected URL: ${url}" >&2 - exit 22 - ;; -esac -""" - ) - fake_curl.chmod(0o755) - - return { - **os.environ, - "PATH": f"{tmp_path}:{os.environ['PATH']}", - "MODAL_ENVIRONMENT": "main", - "MODAL_GET_URL_SCRIPT": str(get_url_script), - "HOUSEHOLD_MODAL_GATEWAY_CUSTOM_DOMAIN_URL": ( - "https://custom-domain.example" - ), - "GATEWAY_VERSIONS": gateway_versions, - "CUSTOM_VERSIONS": custom_versions, - } diff --git a/.github/workflows/deploy-staged.yml b/.github/workflows/deploy-staged.yml index ac95c884..bb9bb961 100644 --- a/.github/workflows/deploy-staged.yml +++ b/.github/workflows/deploy-staged.yml @@ -266,9 +266,6 @@ jobs: '${{ needs.resolve-modal-release-config.outputs.config_json }}' \ '${{ needs.resolve-modal-release-config.outputs.deploy_mode }}' - - name: Verify production custom domain - run: bash .github/scripts/modal-custom-domain-smoke.sh - publish: name: Publish to PyPI runs-on: ubuntu-latest diff --git a/changelog.d/1539.fixed.md b/changelog.d/1539.fixed.md new file mode 100644 index 00000000..c231cbd6 --- /dev/null +++ b/changelog.d/1539.fixed.md @@ -0,0 +1 @@ +Remove the production custom-domain smoke gate from Modal deployment so code can deploy before DNS cutover.