{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "TL;DR: After a day fighting with travis, my blog get [auto-deployed](https://github.com/Carreau/posts/blob/master/.travis.yml) with Travis using Nikola !" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## A bit of automation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "One of the annoying things when I want to post a blog post like this one, is that I never remember hom to deploy my blog. So, why not completly automatize with a script ? \n", "\n", "Well, that one step, but you know what is really good at runnign scripts ? Travis.\n", "\n", "Travis have the nice ability to run script in the category `after_success` , or [encrypting file](http://docs.travis-ci.com/user/encrypting-files/), whice allow a nice deployment setup." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## A description of the process." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The first step is to create an ssh key with empty pass passphrase;\n", "I like to add it (encrypted) to `.travis` folder in my repository.\n", "Travis have nice [doc](http://docs.travis-ci.com/user/encrypting-files/) for that.\n", "\n", "Copy the public key to the target github repository deploy key in setting.\n", "\n", "In my particular setup the tricky bit where :\n", "\n", "To get IPython and nikola master:\n", " - `- pip install -e git+https://github.com/ipython/ipython.git#egg=IPython`\n", " - `- pip install -e git+https://github.com/getnikola/nikola.git#egg=nikola`\n", " \n", "Get the correct layout of folders:\n", " - blog (gh/carreau/blog)\n", " - posts (gh/carreau/posts)\n", " - output (gh/carreau/carreau.github.io)\n", " \n", "I had to soft link `posts`, as this is the repo which trigger travis build, and is by default cloned into `~/posts` by travis. `carreau/carreau.github.io` is clone via `https` to allow pull request to build (and not push) as the ssh key can only be decrypted on master branch.\n", "\n", "Then run `nikola build`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the `after_success` step (you might want to run unit-test like non-broken link on your blog) you want to check that you are not in a PR, and on master branch before trying to decrypt the ssh key and push the built website:\n", "\n", "\n", "The following snippet works well.\n", "```bash\n", "if [[ $TRAVIS_PULL_REQUEST == false && $TRAVIS_BRANCH == 'master' ]];\n", "```\n", "\n", "Travis CL tool gave you the instruction to decrypt the ssh key, you now \"just\" have to add it \n", "to the keyring.\n", "\n", "```bash\n", "eval `ssh-agent -s`\n", "chmod 600 .travis/travis_rsa\n", "ssh-add .travis/travis_rsa\n", "cd ../blog/output\n", "```\n", "\n", "And add an ssh remote, which user is **git**:\n", "\n", "```bash\n", "git remote add ghpages ssh://git@github.com/Carreau/carreau.github.io\n", "```\n", "\n", "Push, and you are done (don't forget to commit though) ! " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Extra tips" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When testing, do not push on master, push on another branch and open the PR manually to see the diff. \n", "Travis env might defier a bit from yours. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Todo" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Nikola read metadata file from `.meta` file, which is annoying. I should patch it to read metadata from notebook Metadata. ALso need a JS extension to make that easy." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Closing thoughts" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "PR and comments welcommed as usual. " ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.4.2" } }, "nbformat": 4, "nbformat_minor": 0 }