Search code examples
ruby-on-railsdockeramazon-ecs

Rails migration on ECS


I am trying to figure out how to run rake db:migrate on my ECS service but only on one machine after deployment.

Anyone has experience with that?

Thanks


Solution

  • You may do it via Amazon ECS one-off task.

    1. Build a docker image with rake db migrate as "CMD" in your docker file.
    2. Create a task definition. You may choose one task per host while creating the task-definition and desired task number as "1".
    3. Run a one-off ECS task inside your cluster. Make sure to make it outside service. Once It completed the task then the container will stop automatically.

    You can write a script to do this before your deployment. After that, you can define your other tasks as usual.

    You can also refer to the container lifecycle in Amazon ECS here: http://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_life_cycle.html. However, this is the default behavior of the docker.

    Let me know if it works for you.