Continuous deployment of static sites from Codeship to WebFaction with rsync
Mmm, that’s a a bit of a mouthful.
This example is written with Hexo, Codeship and WebFaction in mind but should work with any static site generator, other CI services (e.g. CircleCI, Travis CI) and any server that allows authentication via key-based SSH.
It’s a little more fiddly than hosting static sites on Amazon S3, but putting a site behind Apache or Nginx can be useful if you need to use redirects or proper authentication.
Create a new website in the WebFaction control panel, attaching a static application (
name_of_webapp) and a domain.
Create a new Codeship project (or use an existing one).
Add your build commands in the “Setup Commands” field under the “Test” configuration (if you’re using Hexo, it’s
hexo generate). You can add any test commands you may have under “Configure Test Pipelines”, if you like.
Push a new commit to check that everything is building correctly and passing tests.
Once you have a green build, it’s worth opening an SSH debug session and making sure the generated files are present and as expected. Find the debug session tool on the right hand side of the appropriate build log page. Look in
~/clone/ for the folder your SSG generates (for Hexo, this is
Go to “Deployment” in the Codeship project settings and add a custom script for the branch you want to deploy. I use the following
rsync -avz ~/clone/build_directory/ firstname.lastname@example.org:/home/username/webapps/name_of_webapp/
name_of_webappwith the name you used for the static application in Step 1.
usernamewith your WebFaction username.
build_directorywith the directory your SSG writes to. As mentioned above, this is
Follow WebFaction’s Using SSH keys to add the Codeship project’s public key to your WebFaction account
Go back to Codeship and run the most recent build again to trigger a deploy. One the build has finished, you should be able to see the static site on the domain you set up in Step 1.
If this doesn’t work, here are some ideas for working out what might have gone wrong:
- Check the Codeship build log and look for issues
- Open another Codeship SSH debug session and check that the build step is generating the files.
- Check that the site files are under your WebFaction account in
Posted in: ci, codeship, tools, webfaction
Written by Paul Love who lives and works in Edinburgh building useful things.