Git Workflow, Deployment and Hooks
Git Deployment
We use a simple post-receive git hook to make a production ready repository that we can push to from our local machines. We’ve also setup SSH keys on the servers we deploy to so we don’t need to enter passwords.
Git Hooks
post-receive
The most important hook that allows us to add the application repository on the server as a remote on our local machines
#!/bin/sh cd .. unset GIT_DIR env -i git reset --hard git checkout -f
i.e.
~$ git remote add production user@server:/var/www/some-application.com
post-update
Our post update hooks run Laravel’s built in migrations and Composer’s update function so our packages stay up to date.
#!/bin/sh cd /path/to/laravel echo "----------" echo "Running PRODUCTION migrations..." /usr/bin/php artisan migrate --env=production echo "----------" echo " " echo "**********" echo "Running Composer Update" unset GIT_DIR; /usr/bin/php /path/to/composer update echo "**********"
Which gives us the output of php artisan migrate and composer update in our local shell when we push to a remote repository.