Automatically deploy Middleman with Codeship to a VPS
$2.50 for a 512MB RAM VPS got me leaving Digital Ocean for Vultr. That’s more than enough for my small amount of Middleman-made static files, with Cloudflare sitting in front serving most of the traffic through their CDN.
While moving to my new home I realised that I could share how I deploy this thing.
▶︎ Have a repo. Here’s mine.
▶︎ Sign up for Codeship. They have a free plan with some limitations on the amount of builds per month. But if your repo is open then you’re always having free lunches with no limits.
▶︎ Create a user on your VPS for Codeship. Don’t use root.
▶︎ Create a new Codeship project
▶︎ Connect with your SCM (they support GitHub, Bitbucket and GitLab).
▶︎ Pick your repo and branch.
▶︎ Under “Configure your tests”, pick “I want to create my own custom commands” and enter this:
1 2 3 4 rvm use 2.3.1 --install npm install gulp install gulp build
Please peek inside my gulpfile.js to see what’s going on here.
▶︎ Carry on to the “Deployment Pipelines” settings. Pick “Custom Script” and enter your modified version of this:
1 rsync -avz -e "ssh" ./build/ [email protected]_ip_address:/var/www/example.com/html --delete-before
▶︎ Almost there! Now add the SSH public key for that Codeship project to your user so it can access your VPS. You’ll find it under “Settings > General”.
If you need help setting up the VPS I recommend these great guides from Digital Ocean:
Initial Server Setup with Ubuntu 16.04
How To Install Nginx on Ubuntu 16.04
How To Set Up Nginx Server Blocks (Virtual Hosts) on Ubuntu 16.04