0

I'm deploying a Django app to EB - my first EB deployment - and I'm confused about the order of things.

My container commands are these:

container_commands:
   01_migrate:
    command: "django-admin.py migrate"
    leader_only: true
   02_collectstatic:
     command: "django-admin.py collectstatic --noinput"
     leader_only: true

What I've noticed, however, is that each time I deploy, these container commands are run on my old codebase. Suppose my current code is app-v1.zip. I update my models.py, and create a migration. I then eb deploy, which creates app-v2.zip. The migrate command is run on the EB environment, but is run on the old codebase (app-v1.zip), before app-v2.zip is unpacked into /var/app/current, and so my migration isn't applied.

If I then run another eb deploy, it will create app-v3.zip, but will run migrate on the code in app-v2.zip. So, it works, but it means I have to run eb deploy twice any time I want to change either data models or static files (the same issue applies to collectstatic).

There is more explanation and a workaround on this blog post and this SO question, but all the "deploy Django to EB" tutorials do things the way I've done it with container_commands.

What's the correct way?

Community
  • 1
  • 1
awidgery
  • 1,896
  • 1
  • 22
  • 36
  • Are you sure? I have been using EB for a year and I have never seen the behavior you describe. The blog talks about the fact that the commands get run on a staging area before deployment but that staging area should have your new archive. Can you give more details on how you think this is happening? – dkarchmer Feb 28 '16 at 20:42

1 Answers1

0

You made me worry, but I have confirmed that eb deploy does run the commands with the new version of the code. It does this on a staging area, before actually releasing to the server, but it does with the proper version.

You can do eb logs -a after the deployment and look for the eb-activity.log to see how all commands get executed, and the proper migration happens.

As for the flow, I prefer NOT to call collecstatics as part of the EB flow, as I am releasing that code directly into S3 (and CloudFront) using a gulp based flow. So, I just run migrate as part of the deployment (plus other things particular to my application):

 01_migrate:
    command: "django-admin.py migrate --noinput"
    leader_only: true

and everything works as expected.

dkarchmer
  • 5,434
  • 4
  • 24
  • 37