Skip to content

Instantly share code, notes, and snippets.

@mikeclarke
Created November 4, 2014 01:52
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mikeclarke/f044d4161d36ff864d37 to your computer and use it in GitHub Desktop.
Save mikeclarke/f044d4161d36ff864d37 to your computer and use it in GitHub Desktop.
.ebextension file for migrating a database with docker
container_commands:
sync_db:
command: "docker run --env DATABASE_URL=`/opt/elasticbeanstalk/bin/get-config environment | jq -r .DATABASE_URL` aws_beanstalk/current-app:latest lein lobos migrate"
leader_only: true
@jufemaiz
Copy link

Dumb question, when did this "/opt/elasticbeanstalk/bin/get-config" come into being?!

@codebender
Copy link

me gusta! thanks for posting this

@Tuuleh
Copy link

Tuuleh commented Oct 1, 2015

Just as a note - EB momentarily runs two containers between deploys - the one with your old application version, and one with a new version. I've been using a similar migration script, and it runs before the new container is renamed to aws_beanstalk/current-app:latest and deployed. Consequently, the migrations run in the container for the previous application version, which can lead to some inconsistencies (old migrations applied to a fresh deploy).

@xuebingli
Copy link

@Tuuleh do you mind sharing how you solved this problem that you described?

@cseeger
Copy link

cseeger commented Dec 23, 2015

@mikeclarke -- Thank you.

@bpicolo
Copy link

bpicolo commented Jun 12, 2016

I'm late here, but this was incredibly helpful, thanks!

@xuebingli for you and moreso people who stumble on this in the future, aws_beanstalk/staging-app:latest would be the incoming app.
I figured this out by adding a 'docker images' command to container_commands, and then pulling the beanstalk logs.

@jschr
Copy link

jschr commented Jan 2, 2017

Thanks for the followup @bpicolo, you saved me a bunch of time.

In case this helps anyone else, heres my working version of the .ebextension file for migrating with docker using aws_beanstalk/staging-app:latest: https://gist.github.com/jschr/873a4ad8591760202c20ea702e6d3c99.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment