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.
Step 1
Create a new website in the WebFaction control panel, attaching a
static application (name_of_webapp
) and a domain.
Step 2
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
~/clone/public/
).
Step 3
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
command:
rsync -avz ~/clone/build_directory/ [email protected]:/home/username/webapps/name_of_webapp/
Replace:
-
name_of_webapp
with the name you used for the static application in Step 1. username
with your WebFaction username.-
build_directory
with the directory your SSG writes to. As mentioned above, this ispublic
for Hexo.
Step 4
Follow WebFaction’s
Using SSH keys
to add the Codeship project’s public key to your WebFaction account
authorized_keys
file.
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
~/webapps/name_of_webapp
.
- Last updated on
- Posted in: ci, codeship, tools, webfaction
- Permalink
- See this post on Wayback
- Edit on GitHub
- http://notes.anglepoised.com/2015/09/Continuous-deployment-of-static-sites-from-Codeship-to-WebFaction-with-rsync