Skip to content

Commit d89fa08

Browse files
committed
fix: use migration task for migration
1 parent 1b43a40 commit d89fa08

File tree

1 file changed

+24
-57
lines changed

1 file changed

+24
-57
lines changed

.github/workflows/build-and-deploy-dev.yml

Lines changed: 24 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -85,80 +85,47 @@ jobs:
8585
exit 1
8686
fi
8787
88+
MIGRATION_TASK_DEFINITION=$(get_param "migration-task-definition-arn")
89+
90+
if [ -z "${MIGRATION_TASK_DEFINITION}" ] || [ "${MIGRATION_TASK_DEFINITION}" = "None" ]; then
91+
echo "Unable to determine migration task definition for ${SERVICE_NAME}" >&2
92+
exit 1
93+
fi
94+
8895
echo "cluster=${CLUSTER_NAME}" >> "${GITHUB_OUTPUT}"
8996
echo "service=${SERVICE_NAME}" >> "${GITHUB_OUTPUT}"
9097
echo "task_definition=${TASK_DEFINITION}" >> "${GITHUB_OUTPUT}"
9198
echo "network_configuration=${NETWORK_CONFIGURATION}" >> "${GITHUB_OUTPUT}"
99+
echo "migration_task_definition=${MIGRATION_TASK_DEFINITION}" >> "${GITHUB_OUTPUT}"
92100
93101
- name: Run database migrations (dev)
94102
env:
95103
CLUSTER: ${{ steps.backend_params.outputs.cluster }}
96104
TASK_DEFINITION: ${{ steps.backend_params.outputs.task_definition }}
97105
NETWORK_CONFIGURATION: ${{ steps.backend_params.outputs.network_configuration }}
106+
MIGRATION_TASK_DEFINITION: ${{ steps.backend_params.outputs.migration_task_definition }}
98107
run: |
99108
set -euo pipefail
100-
if [ -z "${CLUSTER}" ] || [ -z "${TASK_DEFINITION}" ]; then
109+
if [ -z "${CLUSTER}" ]; then
101110
echo "Missing ECS configuration; cannot run migrations" >&2
102111
exit 1
103112
fi
104113
105-
printf '%s' "${NETWORK_CONFIGURATION}" > network-config.json
106-
107-
write_overrides() {
108-
local include_scheduler="$1"
109-
if [ "${include_scheduler}" = "true" ]; then
110-
jq -n '{
111-
containerOverrides: [
112-
{
113-
name: "BackendApplication",
114-
command: ["uv", "run", "python", "scripts/bootstrap.py", "migrate"]
115-
},
116-
{
117-
name: "SchedulerContainer",
118-
command: ["sh", "-c", "echo Skipping scheduler during migration"]
119-
}
120-
]
121-
}'
122-
else
123-
jq -n '{
124-
containerOverrides: [
125-
{
126-
name: "BackendApplication",
127-
command: ["uv", "run", "python", "scripts/bootstrap.py", "migrate"]
128-
}
129-
]
130-
}'
131-
fi
132-
}
114+
if [ -z "${MIGRATION_TASK_DEFINITION}" ]; then
115+
echo "Missing migration task definition; cannot run migrations" >&2
116+
exit 1
117+
fi
133118
134-
INCLUDE_SCHEDULER=true
135-
write_overrides true > overrides.json
136-
137-
run_migration_task() {
138-
aws ecs run-task \
139-
--cluster "${CLUSTER}" \
140-
--task-definition "${TASK_DEFINITION}" \
141-
--launch-type FARGATE \
142-
--network-configuration file://network-config.json \
143-
--overrides file://overrides.json \
144-
--started-by "github-actions-dev-migration" \
145-
--query 'tasks[0].taskArn' \
146-
--output text
147-
}
119+
printf '%s' "${NETWORK_CONFIGURATION}" > network-config.json
148120
149-
TASK_ARN=""
150-
if ! TASK_ARN=$(run_migration_task 2>migration-error.log); then
151-
if [ "${INCLUDE_SCHEDULER}" = "true" ] && grep -q 'is not a container in the TaskDefinition' migration-error.log; then
152-
echo "Retrying migration without SchedulerContainer override" >&2
153-
INCLUDE_SCHEDULER=false
154-
write_overrides false > overrides.json
155-
TASK_ARN=$(run_migration_task 2>migration-error.log)
156-
else
157-
cat migration-error.log >&2
158-
exit 1
159-
fi
160-
fi
161-
rm -f migration-error.log
121+
TASK_ARN=$(aws ecs run-task \
122+
--cluster "${CLUSTER}" \
123+
--task-definition "${MIGRATION_TASK_DEFINITION}" \
124+
--launch-type FARGATE \
125+
--network-configuration file://network-config.json \
126+
--started-by "github-actions-dev-migration" \
127+
--query 'tasks[0].taskArn' \
128+
--output text)
162129
163130
if [ -z "${TASK_ARN}" ] || [ "${TASK_ARN}" = "None" ]; then
164131
echo "Failed to start migration task" >&2
@@ -168,7 +135,7 @@ jobs:
168135
aws ecs wait tasks-stopped --cluster "${CLUSTER}" --tasks "${TASK_ARN}"
169136
aws ecs describe-tasks --cluster "${CLUSTER}" --tasks "${TASK_ARN}" > migration-status.json
170137
171-
FAILURES=$(jq '[.tasks[0].containers[] | select((.name == "BackendApplication" or .name == "SchedulerContainer") and ((.exitCode? // 0) != 0 or (.reason? != null and .reason? != "")))] | length' migration-status.json)
138+
FAILURES=$(jq '[.tasks[0].containers[] | select(.name == "DatabaseMigration" and ((.exitCode? // 0) != 0 or (.reason? != null and .reason? != "")))] | length' migration-status.json)
172139
173140
if [ "${FAILURES}" -gt 0 ]; then
174141
jq '.tasks[0].containers[] | {name, exitCode, reason, lastStatus, stoppedReason}' migration-status.json >&2

0 commit comments

Comments
 (0)