Gerardo's musings

(not) just another blog, hopefully, this time around

On Github
On LinkedIn
On Twitter

Deploying my Metalsmith-generated, Github-Pages-hosted personal blog from the comfort of `git push`

I'm setting up Travis to automatically deploy my Metalsmith-generated blog files.

  • My blog sources (Markdown and Metalsmith scripts to pregenerate html) repo are at: sanx/sanx-blog-source (master branch)
  • The github-pages repo whose files get published to my user pages is: sanx/ (master branch)


  • cd ~/sanx-blog-source
  • ssh-keygen -f
  • Github web, repo sanx/ Go to repo Settings -> Deploy keys. Generate a new ssh key (I used ssh-keygen -f and specified an empty passphrase twice when prompted). Paste public key on Github's repo Settings -> Deploy keys textarea. Check "Allow write access". Finally, click on "Add key" to give this new ssh key permission to write just to this one repository.

Next steps (setup travis build and store encrypted deploy ssh keys) are based on

  • Check that travis -v is 1.7.0 or later.
  • travis init (since I didn't have a .travis.yml already)
  • travis login
  • travis encrypt-file --add will generate file and it will also modify your .travis.yml file to make the encryption key available to our build when it runs on one of the Travis build servers.

Add this to .travis.yml:

- openssl aes-256-cbc -K $encrypted_57703ae61a7e_key -iv $encrypted_57703ae61a7e_iv
  -in -out ~/.ssh/ -d # this line was
  # originally added by the travis encrypt-file command above, but I modified the part
  # after -out to specify that I want the ssh key to be decrypted and put under ~/.ssh/
- chmod u=rw,og= ~/.ssh/
- echo "Host" >> ~/.ssh/config
- echo "IdentityFile ~/.ssh/" >> ~/.ssh/config
- git config --global ""
- git config --global "Gerardo Moad"
  provider: script
  script: bin/
    branch: master

Create file bin/

#!/usr/bin/env bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

npm install
node index.js

rm -rf || { echo "failed to rm checkout dir"; exit 1; }
mkdir -p || { echo "failed to mkdir checkout dir"; exit 1; }
cd || { echo "failed to cd to checkout dir"; exit 1; }
git clone . || { echo "failed to clone generated blog repo"; exit 1; }

cp -r ../_site/* .
git commit -m "auto commit at: `date`" -a
git push

Last steps before trying it all on the Travis server:

  • git add important not to add the unencrypted private key to any repo!
  • git add .travis.yml
  • git add bin/

Ta-da! I'm all set for my blog's static html pages to be re-generated by Metalsmith running on Travis on every commit that I push to my blog sources repo.