If you already use capistrano you already know about the
probably use something like this to keep your PHP libraries across releases:
But sometimes you need to run composer to keep add another dependency and sometimes takes a lot of time to download everything or some composer server stop to respond or suffer a slowdown and your deploy breaks.
I developed a deployment strategy to not forget to run
composer or install
all dependencies everytime.
The ideia is have the
composer.phar available before the deploy starts and faster deploy times. (< 30 seconds)
The magic start with the rake file task who is only invoked one time and only if necessary, so we can install composer just once:
1 2 3
Here is another trick, if you do not put the
composer.lock file on your
composer will try to install all the dependencies and create the
lock file, so here whe create the file and let
composer update their content later to speed next deployments:
1 2 3
remote_file set the first argument as a prerequisite and if the file no
file task with the name
'/tmp/composer.phar' will be called.
'/tmp/composer.phar' is a rake task name and also a path. You can see more about
file task will run and the file will be created on the
And we link these tasks above on the check flow
who happens before the deploy to ensure the
capistrano.lock will be available on the
shared_path and linked to the
1 2 3 4 5
Finally we always run
composer to ensure the dependencies will be on
available to the application:
1 2 3 4 5 6 7 8 9 10 11
The whole thing:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
Try to remove one or another dependency from the vendor directory and see composer installing only the missing piece on the next deploy!
You can find me on Twitter as @fgbreel.
See you next time!