Easy site deployment on Gandi with git and gdeploy (bash)06 Apr 2020
(Use this link to get 6 months of free hosting on Gandi!).
I’m doing more and more Laravel development and I’m hosting these projects on Gandi.net Simple Hosting. I’ve also switched completely to Gandi’s deploy with git method, since it lets me do full and easy deployment from my laptop’s command line. I’ve even created a bash script
gdeploy.sh to make this faster, Let me explain how it works:
- when you start your project, add the
git remotefor gandi, as specified in your Gandi Simple Hosting dashboard
- develop and run your project locally (using e.g.
php artisan serve)
- when you want to deploy, you commit the changes to the master branch
git commit -a
- you then push the changes to the Gandi git server
git push gandi master
- you then start deployment from the Gandi git server to the web server. This will also do a
composer install(if there is a composer.lock file) and a
npm install(if there is a package-lock.json file)
ssh <id>@<gitserver> deploy <website>.git
I have multiple Gandi Simple Hosting servers and I found it confusing to keep track of what server I was supposed to deploy to for each site. So I developed gandi_deploy. This is how that works:
- what should already be installed:
- clone this repository somewhere on your machine
git clone https://github.com/pforret/gandi_deploy.git
- from any of your Gandi git-managed project, add a symbolic link to gdeploy.sh
ln -s /path/to/gandi_deploy/gdeploy.sh .
- initialise the script for your project, type the domain name of your site if it cannot be guessed from the folder name
- this will retrieve the correct git server, web server, user name for this website and store them locally in a hidden folder
- my most common usage is:
./gdeploy.sh <strong>all</strong>: this does all 3 steps: commit-push-deploy one after the other, It might take more than 30 secs, but I just have to wait for it to finish.
- I can also choose to run them one by one:
./gdeploy.sh <strong>commit</strong>will do the local git commit
./gdeploy.sh <strong>push</strong>will push the new commit to the Gandi git server
./gdeploy.sh <strong>deploy</strong>will push new commit to the Gandi web server,
- for non-Laravel PHP sites, when there is no
php artisan serve, I can start a local webserver with
./gdeploy.sh <strong>serve</strong>(on port 8000) or
./gdeploy.sh <strong>rnd</strong>(on a random port between 8000 and 8099). It uses the PHP built-in server.
- to login to the remote SSH serve, I can use
./gdeploy.sh <strong>ssh</strong>. This uses
gandi paas remoteto start the SSH access.
- for sites where I have a staging server and a production server, I can define different remotes (
git remote add stage ...) and then use
./gdeploy.sh <strong>push stage</strong>or
./gdeploy.sh <strong>push prod</strong>to choose where I’m pushing the code,
./gdeploy.sh allto commit, push and deploy new code to Gandi, in 1 go