Easy site deployment on Gandi with git and gdeploy

(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:

  1. when you start your project, add the git remote for gandi, as specified in your Gandi Simple Hosting dashboard
  2. develop and run your project locally (using e.g. php artisan serve)
  3. when you want to deploy, you commit the changes to the master branch
    • git commit -a
  4. you then push the changes to the Gandi git server
    • git push gandi master
  5. 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:

Installation

  • what should already be installed: git (obviously), cli.gandi.net
  • 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
    ./gdeploy.sh init
  • this will retrieve the correct git server, web server, user name for this website and store them locally in a hidden folder .gandi.

Easy deployment

  • my most common usage is: ./gdeploy.sh all: 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 commit will do the local git commit
    • ./gdeploy.sh push will push the new commit to the Gandi git server
    • ./gdeploy.sh deploy 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 serve (on port 8000) or ./gdeploy.sh rnd (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 ssh. This uses gandi paas remote to 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 push stage or ./gdeploy.sh push prod to choose where I’m pushing the code,

./gdeploy.sh all

to commit, push and deploy new code to Gandi, in 1 go

1 thought on “Easy site deployment on Gandi with git and gdeploy”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.