nelly202
nelly202

Reputation: 21

Azure DevOps - Automatically run rails migrations

I created a Azure devops project that deploys my code from Github. My project is a Rails app that runs on Docker. When I create the Azure DevOps project, it creates the CI/CD pipelines for me. The deployment works, but I can't figure out how to automatically migrate the database when we deploy. I know I can do it manually, but I prefer not to as we might forget when we deploy.

I tried to run the following commands in the "Post Deployment Actions"

I've also generated my own kuduscript (using kuduscript) to add in the line for migration but it did not work. I don't know if it's because it's not reading my deployment script or if that line doesn't work.

Am I missing something? Should I try to figure out how to migrate through Docker instead? I've looked at all these links but they all run the migration manually.

https://learn.microsoft.com/en-us/azure/app-service/containers/quickstart-ruby https://medium.com/paris-rb/deploying-your-rails-postgresql-app-on-microsoft-azure-180f8a9fab47 https://learn.microsoft.com/en-us/azure/app-service/containers/tutorial-ruby-postgres-app

Upvotes: 2

Views: 831

Answers (1)

cmdub
cmdub

Reputation: 11

So not sure if you ever figured this out but I just had to do this for a migration I'm working on. The best way to do what you're after from what I've found is to setup a stage in your release pipeline like so:

stage setup

Where basically:

  • Your service connection logs into the container registry
  • Pulls the image you just built and pushed to the registry
  • Use a docker run command to then run your image with all the necessary environment variables and anything else needed to run it properly.
  • You can then use another task if needed to run a docker exec bundle exec rake db:migrate

If the migrate task runs successfully it should exit 0 allowing you to then run your app service on the latest tagged image with the correct database changes already done.

Upvotes: 1

Related Questions