Run DB Migration before every deploy #4052
mvn-bachhuynh-dn
started this conversation in
Ideas
Replies: 2 comments
-
This is super helpful, thank you @mvn-bachhuynh-dn ! Have you seen the discussion here: #3007 (comment) We're planning to support in the pipeline manifest two new fields: stages:
- name: test
pre_deployments:
buildspec: ./migrate.buildspec.yaml
post_deployments:
buildspec: ./cleanup.buildspec.yaml Do you feel like this would simplify the |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi @efekarakus , With my additional command could resolve the problem. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi all,
As you know, when deploy a service, we often run DB Migration first.
Some project, I could add the command to migration DB before run the service.
Just like that:
but If we run many tasks in a service, so many command db:migrate will be run, and sometime it makes the DB got many connection about migration...beside that, migrate take time, make warm-up time of a container longer.
So, I will separated it, container of Service only run the app, migration task will be handled by Codebuild.
So the script only needs:
In Codebuild, we will run a task for migration, and only migration success will make the build success...if not, the build failed and the pipeline failed as well => good for deployment.
Here is what I added into Buildspec.yml (in the end of post_build section)
image
is the latest image after the imaged uploaded of the current build.the second command will override command and image line of the output of the command
copilot task run --generate-cmd AppName/AppEnv/ServiceName
And now, Migration task was already handled by Codebuild, and it will be run every build of the service.
Hope it will help someone use this architect like me.
P/S: One more thing I'm still considering,
--generate-cmd
is depend on current running task definition, ENVs are only from the task definition. If you update more ENV in this build (by updating the manifest.yml), you have to modify my script...But I believe when migration, only need some needed env as DB_HOST, DB_NAME, DB_USER, DB_PASSWORD ....If anyone could handle the db-migration with another way, please discuss here! Thank you!
Beta Was this translation helpful? Give feedback.
All reactions