I solved it by creating a new directory in the root of my project named .ebextensions
. In that directory I created a script file my-scripts.config
:
.ebextensions/
my-scripts.config
app/
artisan
bootstrap
...
The file my-scripts.config
gets executed when EBS deploys, is a YAML file and looks like this:
container_commands:
01-migration:
command: "php /var/app/ondeck/artisan --env=staging migrate"
leader_only: true
Add the directory and file to git, commit, and run git aws.push
and it will migrate.
Explanations on how stuff in .ebextensions
works can be found here.
The path /var/app/ondeck
is where your application lives when your script runs, it will afterwards be copied into /var/app/current
.
The artisan option --env=staging
is useful for telling artisan what environment it should run in, so that it can find the correct database settings from app/config/staging/database.php
If you need a quick and dirty way to log why the migrate command fails you might want to try out something like "php /var/app/ondeck/artisan --env=staging migrate > /tmp/artisan-migrate.log"
so that you can log into your ec2 instance and check the log.