Yet Another Octopress 2.0 and TravisCI Guide
So there's only about 30 50 thousand pages on this general topic, but I
found that about half of them were out of date, so I figured I should try and
collect all the info into one big post. I've referenced where I've found some of
the stuff that's harder to find from Googling using the wonders of Octopress
footnotes.
Unfortunately, as I was finishing up this post, the post announcing Octopress 3.0 comes out. While I had known it was coming, I wasn't expecting it to be so soon. Obviously this post will be less useful, but it should still be informative. I've included what I think will need to be modified to function on 3.0 at the bottom.
Table of contents
My Site Flow
- Local
- Private Github Repo
- Built and Deployed using TravisCI to a DigitalOcean droplet
I've got a drafts workflow using a couple tasks I found online[^1] and then promptly modified:
For this to work using rake preview, you'll need to modify your preview task slightly, add the flag --drafts to the jekyll call.
The Build Process
Personally, I don't want to have to deal with building and uploading my site. Instead I use Travis-CI targeted to a specific Github repo branch, and some modified rsync scripts.
Rsync Setup
!Travis CI SSH Key location
You'll need to configure your deployment account's SSH private key in Travis-CI by replacing all new lines with \n, and then escaping that to \n, so that it ends up being one line with \n in between each original line.^2 (NOTE: Make sure the key was generated without ssh-agent running, and set a blank passphrase.) Next, go to your Travis-CI settings, create a new environment variable, name it whatever you want, I used $DEPLOY_PRIVATE_KEY, then paste in your one-line private key into the variable section. Now that it's a environment variable in all Travis workers your builds will use, the before_install tasks will disable strict host key checking (requires input, which Travis doesn't allow), and then echo the contents of DEPLOY_PRIVATE_KEY to id_rsa, then add that key to the ssh-agent, in my case, allowing the worker to connect using the user travis-ci to my droplet.
If the user you're connecting with in your Rakefile's settings isn't the owner of your specific directories on your hosting server, rsync will probably fail to sync properly. In that case, you'll need to add --omit-dir-times to rsync-args in the Rakefile.
After all of this, you should be good to go. If you're using the master deploy method, push your site up to master, and it should build properly on Travis, and deploy to your rsync destination.
Octopress 3.0
For the most part, as far as I can tell, these modifications will mostly still work for 3.0. The drafts changes will no longer be needed anymore, as the Jekyll drafts workflow is now using a separate drafts folder. The .travis.yml will need to be tweaked slightly, as well as the _config.yml having an exclude added to keep Jekyll running on Travis-CI from trying to build the templates in /vendor, but other than that, this post is mostly forwards compatible to Octopress 3.0.
[^1]: Never Stop Building
Discussion in the ATmosphere