Skip to content

Commit 7ec27b0

Browse files
authored
Run migrations in a ECS container (#4171)
1 parent 51712a4 commit 7ec27b0

File tree

2 files changed

+44
-23
lines changed

2 files changed

+44
-23
lines changed

.github/workflows/deploy.yml

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,6 @@ jobs:
306306
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
307307
AWS_DEFAULT_REGION: eu-central-1
308308

309-
# TODO Temporary workaround the fact that the lambda takes a bit to update
310-
# so to avoid calling the old deployment, we want 20 seconds
311-
# the 20 seconds is not a meaningful value, it is a random delay
312-
# it might or might not be enough. This is just an hack until we add a solution for this
313-
# e.g lambda versions?
314309
wait-aws-update:
315310
runs-on: ubuntu-latest
316311
needs: [terraform]
@@ -330,24 +325,6 @@ jobs:
330325
done
331326
shell: bash
332327

333-
# Migrate the database
334-
migrate-pycon-backend-db:
335-
runs-on: ubuntu-latest
336-
needs: [terraform, wait-aws-update]
337-
steps:
338-
- uses: actions/checkout@v4
339-
with:
340-
ref: ${{ github.ref }}
341-
- name: Migrate PyCon Backend DB
342-
run: |
343-
aws lambda invoke --function-name ${{ env.TF_WORKSPACE }}-pycon-backend --cli-binary-format raw-in-base64-out --payload '{ "_serverless-wsgi": { "command": "manage", "data": "migrate" } }' response.json
344-
cat response.json
345-
env:
346-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
347-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
348-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
349-
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
350-
351328
deploy-fe:
352329
runs-on: ubuntu-latest
353330
needs: [migrate-pycon-backend-db]

infrastructure/applications/pycon_backend/worker.tf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,50 @@ resource "aws_ecs_task_definition" "worker" {
281281
interval = 10
282282
}
283283

284+
stopTimeout = 300
285+
},
286+
{
287+
name = "migrations"
288+
image = "${data.aws_ecr_repository.be_repo.repository_url}@${data.aws_ecr_image.be_arm_image.image_digest}"
289+
memoryReservation = 200
290+
essential = false
291+
entrypoint = [
292+
"/home/app/.venv/bin/python",
293+
]
294+
295+
command = [
296+
"manage.py", "migrate"
297+
]
298+
299+
environment = local.env_vars
300+
301+
mountPoints = []
302+
systemControls = [
303+
{
304+
"namespace" : "net.core.somaxconn",
305+
"value" : "4096"
306+
}
307+
]
308+
309+
logConfiguration = {
310+
logDriver = "awslogs"
311+
options = {
312+
"awslogs-group" = var.logs_group_name
313+
"awslogs-region" = "eu-central-1"
314+
"awslogs-stream-prefix" = "backend-migrations"
315+
}
316+
}
317+
318+
healthCheck = {
319+
retries = 3
320+
command = [
321+
"CMD-SHELL",
322+
"echo 1"
323+
]
324+
timeout = 3
325+
interval = 10
326+
}
327+
284328
stopTimeout = 300
285329
}
286330
])

0 commit comments

Comments
 (0)