To be honest,
- cd /var/www
- git reset –hard (sometimes..)
- git pull origin <branch name>
- composer self-update
- composer update / install
- composer dump-autoload
- php artisan vendor:publish
- php artisan migrate
I’m lazy! I decided to create a simple script that will do all this for me in just a jiffy.
In Linux it is possible to create a shell script that will execute series of commands for you. So first of all, open up that terminal, and lets create the file.
I decided to name it deploy
Now put in some comments; perhaps:
#!/bin/sh # ## store the arguments given to the script
First, we want to tell the user that their command has been received, so lets put a new line in our file:
## Record the fact that the deploy command has been received echo "\033[33;32m Received deploy request at $( date +%F )"
Let it switch to the right working directory
## Switch to right directory cd /var/www/; \ echo "\033[33;31m Switched to" pwd
Then, some git commands, first reset. I do this so I won’t have problems with temporary testing changes.
## GIT RESET echo "\033[33;31m GIT reset old code" git reset --hard
Then, pull the bastard out of his cave (or repository, your choice of words)
## Start the pull echo "\033[33;31m Starting Pull of branch $1 \033[33;32m" git pull origin "$1"
I switch alot of branches on my test server, so thats why I’m making sure to always pull the right branch into action:
## After pull, make sure to checkout the branch echo "\033[33;31m Starting checkout of branch $1 \033[33;32m" git checkout "$1"
Lets go and start the composer tasks, self update, update and dump autoload. Always fun to watch.
## Start composer tasks echo "\033[33;31m Initiating composer self-update" composer self-update echo "\033[33;31m Initiating composer update" composer install echo "\033[33;31m Initiating composer dump autoload" composer dump-autoload
Clean up the mess artisan sometimes leaves:
## Some cleanup tasks echo "\033[33;31m Initiating Artisan clear cache" php artisan cache:clear
Vendor publish for the right settings that a publisher might have published. (Err, yes. Something like that.)
echo "\033[33;31m Initiating Artisan vendor publish" php artisan vendor:publish And migrate...
echo "\033[33;31m Initiating Migration of database" php artisan migrate
Last beautiful shot, lets tell our user WE ARE DONE!
echo "\033[33;35m All tasks completed succesfully \033[33;32m"
Now you might think, how the crap do I use this? Well, in your terminal, try typing in: deploy master (in which master is your branch name).
Voila, you have your own deployment script!
Complete script? Find it at Github.