11#! /usr/bin/env bash
22set -euo pipefail
33
4- config_json=" ${1:? Usage: modal-deploy-release.sh CONFIG_JSON} "
4+ config_json=" ${1:? Usage: modal-deploy-release.sh CONFIG_JSON [DEPLOY_MODE]} "
5+ deploy_mode=" ${2:- release} "
56output_file=" ${GITHUB_OUTPUT:- } "
7+ modal_extract_versions_script=" ${MODAL_EXTRACT_VERSIONS_SCRIPT:- .github/ scripts/ modal_extract_versions.py} "
8+ modal_sync_secrets_script=" ${MODAL_SYNC_SECRETS_SCRIPT:- .github/ scripts/ modal-sync-secrets.sh} "
9+ modal_active_worker_apps_script=" ${MODAL_ACTIVE_WORKER_APPS_SCRIPT:- .github/ scripts/ modal_active_worker_apps.py} "
10+ modal_cleanup_apps_script=" ${MODAL_CLEANUP_APPS_SCRIPT:- .github/ scripts/ modal-cleanup-apps.sh} "
11+ modal_get_url_script=" ${MODAL_GET_URL_SCRIPT:- .github/ scripts/ modal-get-url.sh} "
612
713require_env () {
814 local missing=()
@@ -34,6 +40,18 @@ github_output() {
3440 fi
3541}
3642
43+ deploy_worker_app () {
44+ local app_name=" ${1:? app name is required} "
45+ local package_versions_json=" ${2:- } "
46+
47+ HOUSEHOLD_MODAL_WORKER_APP_NAME=" ${app_name} " \
48+ HOUSEHOLD_MODAL_PACKAGE_VERSIONS_JSON=" ${package_versions_json} " \
49+ MODAL_ENVIRONMENT=" ${modal_environment} " \
50+ uv run modal deploy \
51+ --env " ${modal_environment} " \
52+ -m policyengine_household_api.modal_release.worker_app
53+ }
54+
3755require_env \
3856 MODAL_ENVIRONMENT \
3957 USER_ANALYTICS_DB_USERNAME \
@@ -42,6 +60,15 @@ require_env \
4260
4361modal_environment=" ${MODAL_ENVIRONMENT} "
4462
63+ case " ${deploy_mode} " in
64+ code|release)
65+ ;;
66+ * )
67+ echo " ::error::Unsupported Modal deploy mode: ${deploy_mode} "
68+ exit 1
69+ ;;
70+ esac
71+
4572uv run alembic upgrade head
4673analytics_database_revision=" $(
4774 uv run python -m policyengine_household_api.modal_release.analytics_revision
@@ -54,7 +81,7 @@ github_output "analytics_database_revision" "${analytics_database_revision}"
5481
5582versions_output=" $( mktemp) "
5683trap ' rm -f "${versions_output}"' EXIT
57- uv run python .github/scripts/modal_extract_versions.py \
84+ uv run python " ${modal_extract_versions_script} " \
5885 --github-output " ${versions_output} "
5986if [ -n " ${output_file} " ]; then
6087 cat " ${versions_output} " >> " ${output_file} "
@@ -64,34 +91,47 @@ worker_app_name="$(
6491 " ${versions_output} "
6592) "
6693
67- bash .github/scripts/modal-sync-secrets.sh
94+ bash " ${modal_sync_secrets_script} "
6895
69- new_app_target=" $( config_value new_app_target) "
70- if [ " ${new_app_target} " != " none" ]; then
71- HOUSEHOLD_MODAL_WORKER_APP_NAME=" ${worker_app_name} " \
72- MODAL_ENVIRONMENT=" ${modal_environment} " \
73- uv run modal deploy \
74- --env " ${modal_environment} " \
75- -m policyengine_household_api.modal_release.worker_app
76- fi
96+ if [ " ${deploy_mode} " = " code" ]; then
97+ active_apps_tsv=" $( mktemp) "
98+ trap ' rm -f "${versions_output}" "${active_apps_tsv}"' EXIT
99+
100+ uv run python " ${modal_active_worker_apps_script} " \
101+ --modal-environment " ${modal_environment} " \
102+ --output-tsv " ${active_apps_tsv} "
77103
78- uv run python -m policyengine_household_api.modal_release.update_manifest \
79- --config-json " ${config_json} " \
80- --new-app-name " ${worker_app_name} " \
81- --source-commit " ${GITHUB_SHA} " \
82- --analytics-database-revision " ${analytics_database_revision} " \
83- --modal-environment " ${modal_environment} " \
84- --cleanup-output modal-cleanup.json \
85- --manifest-output modal-manifest.json
104+ while IFS=$' \t ' read -r active_app_name package_versions_json; do
105+ if [ -z " ${active_app_name} " ]; then
106+ continue
107+ fi
108+ deploy_worker_app " ${active_app_name} " " ${package_versions_json} "
109+ done < " ${active_apps_tsv} "
110+ else
111+ new_app_target=" $( config_value new_app_target) "
112+ if [ " ${new_app_target} " != " none" ]; then
113+ deploy_worker_app " ${worker_app_name} " " "
114+ fi
115+
116+ uv run python -m policyengine_household_api.modal_release.update_manifest \
117+ --config-json " ${config_json} " \
118+ --new-app-name " ${worker_app_name} " \
119+ --analytics-database-revision " ${analytics_database_revision} " \
120+ --modal-environment " ${modal_environment} " \
121+ --cleanup-output modal-cleanup.json \
122+ --manifest-output modal-manifest.json
123+ fi
86124
87125uv run modal deploy \
88126 --env " ${modal_environment} " \
89127 -m policyengine_household_api.modal_release.gateway_app
90128
91- cleanup_target=" $( config_value cleanup_target) "
92- if [ " ${cleanup_target} " != " none" ]; then
93- bash .github/scripts/modal-cleanup-apps.sh modal-cleanup.json
129+ if [ " ${deploy_mode} " = " release" ]; then
130+ cleanup_target=" $( config_value cleanup_target) "
131+ if [ " ${cleanup_target} " != " none" ]; then
132+ bash " ${modal_cleanup_apps_script} " modal-cleanup.json
133+ fi
94134fi
95135
96- gateway_url=" $( bash .github/scripts/modal-get-url.sh ) "
136+ gateway_url=" $( bash " ${modal_get_url_script} " ) "
97137curl -fsS " ${gateway_url} /liveness_check"
0 commit comments