-
Notifications
You must be signed in to change notification settings - Fork 424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: What is the best way to run database migrations with copilot pipeline? #2992
Comments
I'm using Github actions for the release process, but it should be pretty easy to do the same using Pipelines: using hooks in your pipelines specs, you can define after_install script to run See example here at step 14: |
I asked the same question here: https://gitter.im/aws/copilot-cli?at=617ef102a41fd20699178d80 -- still haven't had success but trying to work through it and will post any clean solution I come up with. |
Following up -- I am getting this to work by putting the following in the pipeline.yml file underneath test_commands:
I do think a feature that runs commands after tests would be useful, as this isn't really a test command. Also, if your healthcheck depends on your migrations being run (which usually should be the case, I believe), it's possible (and likely) that your deploy step will fail before the migration completes, which leaves you in some bad water if the migration was only halfway done (duplicate column errors the next time you try to run it for django specifically). |
Thank you @wstewarttennes for the great answer! Yes the request totally makes sense. Actually we have another issue just opened up for tracking this feature request: #3007. I'll close this issue for now. Feel free to reopen if #3007 doesn't look good to your use case. |
What is your current workaround for db migrations ? |
Hello @hugoduportet! Does the workaround mentioned in the above #2992 (comment) work for you? In this solution, if you need to do db migration with pipeline, you can take advantage of the In addition, we have opened an issue for this use case. If this sounds good to you, would you mind giving it a thumb-up to help us prioritize? Let me know if this helps! |
I don´t use copilot right now but I ran into the same issue with both App Runner and ECS. IMO a nice solution is to use lock-exec. It's a CLI distributed locking helper using a DynamoDB table. I copy the binary to my docker container's /usr/local/bin folder, set up the DynamoDB table with AWS CDK and pass the table name to my service using an environment variable (LOCK_EXEC_TABLE). My docker-entrypoint.sh looks like this: #!/bin/bash
set -euxo pipefail
lock-exec run key 'python3 manage.py migrate --noinput' --table $LOCK_EXEC_TABLE
python3 manage.py collectstatic --noinput
python3 manage.py createsuperuser --noinput 2>/dev/null || true
exec "$@" It typically goes like this:
The table uses pay-per-request pricing so you can have like a million requests and it costs you about $1. |
I tried the
but am running into a docker runtime-version issue with that copilot version:
is there a way to select the docker runtime version when in the |
Hello @gabrieljoelc !
|
@KollaAdithya That's great, but my |
you are right. It should be 20 if you are using version v1.27.0. you can just remove that docker runtime version in the |
@KollaAdithya so removing |
That's true. As mentioned over here #4721 (comment) you can navigate to the |
@KollaAdithya thank you so much for your help! to be extra clear, can I change it in the here's what the top of my version: 0.2
phases:
install:
runtime-versions:
docker: 20
ruby: 3.1
nodejs: 16 |
Hey @gabrieljoelc ! I provided more context on which Basically you do not need to edit the |
Hi!
I have a Django application that is deployed using copilot and I am using copilot Pipelines to automate the release process of the app. But I am not able to figure out how to do the database migration step process (
python manage.py migrate --noinput
) in a safely manner...Until now we were using Kubernetes and had a manifest like this one:
Help is very much appreciated.
Thanks,
Adrián
The text was updated successfully, but these errors were encountered: