GitHub Pages are an amazing way to host Jekyll pages, but in some cases, you might be interested in running your Jekyll page on a different host (like Azure Web Apps, Heroku, AWS). For DNS and ownership reasons, we had to move a GitHub page to a host we fully control - at the same time, I did not want to setup a full Ruby server. After all, the magic of Jekyll is that I don't have to host something fancy, it just generates static HTML pages.
Travis CI to the Rescue
I'm already using Travis CI to build and test all my pages for errors - specifically to ensure that the page builds fine and that all image and text links are reachable. Naturally, I simply extended my Travis configuration to also deploy my built site using Git.
Travis CI specifically includes a
deploy phase, allowing you to deploy existing provider adapters or using a custom script. For the sake of keeping things general, I just used a script. Here's the workflow in detail:
- Create a new commit, triggering Travis CI
- Install Ruby, Jekyll, HTMLProofer, and all dependencies
- Compile the page
- Test that all images and links work (using HTMLProofer)
- If the test passed, enter the generated
_sitedirectory and create a new empty Git repository
- Add and commit all static files
- Force-push the result to a desired remote Git repo, suppressing any potentially compromising log messages
The files of interest here are
scripts/deploy.sh. The Travis configuration file instructs Travis, to build, test, and deploy using
_config_ci.yml as Jekyll configuration and
scripts/deploy.sh as the custom deployment provider.
To use this for your own project, update
.travis.yml with your own white- and blacklisted branches. Then, check
build.sh and ensure that the settings for
jekyll build and HTMLProofer are fit for your site (in most cases, they should be). Finally, go to your Travis Profile to edit the settings for your source repository. In there, add three environment variables:
git_targetGit target repository url (without
To use this with your own project, simply head over to GitHub and get the files.