Azure DevOps - Automatically run rails migrations Azure DevOps - Automatically run rails migrations docker docker

Azure DevOps - Automatically run rails migrations


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.