django - AWS: CodeDeploy for a Docker Compose project? -
my current objective have travis deploy our django+docker-compose project upon successful merge of pull request our git master branch. have done work setting our aws codedeploy since travis has builtin support it. when got appspec , actual deployment part, @ first tried have afterinstall script docker-compose build
, have applicationstart script docker-compose up
. containers have images pulled web our postgresql container (named db
, image aidanlister/postgres-hstore
usual postgres
image plus hstore extension), redis container (uses redis
image), , selenium container (image selenium/standalone-firefox
). other 2 containers, web
, worker
, django server , celery worker respectively, use same dockerfile build image. main command is:
cmd paver docker_run
which uses pavement.py
file:
from paver.easy import task paver.easy import sh @task def docker_run(): migrate() collectstatic() updaterequirements() startserver() @task def migrate(): sh('./manage.py makemigrations --noinput') sh('./manage.py migrate --noinput') @task def collectstatic(): sh('./manage.py collectstatic --noinput') # find updates existing packages, install new packages @task def updaterequirements(): sh('pip install --upgrade -r requirements.txt') @task def startserver(): sh('./manage.py runserver 0.0.0.0:8000')
here (think i) need make happen each time pull request merged:
- have travis deploy changes using codedeploy, based on
deploy
section in.travis.yml
tailored our codedeploy setup - start our docker containers on aws after successful deployment using our
docker-compose.yml
how second step happen? i'm pretty sure ecs not needed here. current status right can docker started sudo service docker start
cannot docker-compose up
successful. though deployments reported "successful", because docker-compose up
command run in background in validate service section script. in fact, when try docker-compose up
manually when ssh'd ec2 instance, stuck building 1 of containers, right before cmd paver docker_run
part of dockerfile.
this took long time work out, figured out way deploy django+docker-compose project codedeploy without docker-machine or ecs.
one thing important make alternate docker-compose.yml
excluded selenium
container--all did cause problems , useful local testing. in addition, important choose instance type handle building containers. reason why containers couldn't built our dockerfile instance did not have memory complete build. instead of t1.micro instance, m3.medium worked. important have sufficient disk space--8gb far small. safe, 256gb ideal.
it important have after install script run service docker start
when doing necessary docker installation , setup (including installing docker-compose). explicitly start running docker daemon--without command, error could not connect docker daemon
. when installing docker-compose, important place in /opt/bin/
binary used via /opt/bin/docker-compose
. there problems placing in /usr/local/bin
(i don't remember problems, it's related particular linux distribution amazon linux ami). after install script needs run root (runas: root
in appspec.yml
afterinstall section).
additionally, final phase of deployment, starting containers docker-compose up
(more /opt/bin/docker-compose -f docker-compose-aws.yml up
), needs run in background stdin , stdout redirected /dev/null
:
/opt/bin/docker-compose -f docker-compose-aws.yml -d > /dev/null 2> /dev/null < /dev/null &
otherwise, once server started, deployment hang because final script command (in applicationstart section of appspec.yml
in case) doesn't exit. result in deployment failure after default deployment timeout of 1 hour.
if goes well, site can accessed @ instance's public dns , port in browser.
Comments
Post a Comment