My Take at Nikola, orgmode, docker

This site is built with Nikola and runs on GitLab. Moreover, it is deployed automatically using Travis CI. I recently needed to set up for Nikola and orgmode and figured, why not write about it so that I can have my own reference if I had to do it again.

Docker

I use docker in this case. Nikola is written in Python and could be easily installed both system-wide or in virtualenv but I opted for a docker image to keep it streamlined and have the ability to use the same docker image for the Travis CI. Install docker. I used the available at the time dockerfile (https://gitlab.com/paddy-hack/nikola) which needed a small tweak: emacs (and thus orgmode) support. My setup, including .gitlab-ci.yml is here: https://gitlab.com/djiamnot/nikola-docker

Note: At the time, I just wanted to get started on something. Today, I notice that there is another dockerfile using docker-compose available: https://madflex.de/posts/nikola-setup-using-docker/. YMMV, I guess.

Install docker

sudo -S apt-get remove docker docker-engine docker.io

(The added bonus is that the code in the .org source file can be executed directly with C-c C-c)

sudo apt-get install \
     apt-transport-https \
     ca-certificates \
     curl \
     software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

On Ubuntu:

sudo add-apt-repository \
    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
    $(lsb_release -cs) \
    stable"

(other distributions, see: https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/#install-from-a-package)

sudo apt update
sudo apt-get install docker-ce

You will probably want to add your user to docker group.

Nikola

To be honest, I chose Nikola because it's Python. I've considered Jekyll, I've flirted with Pelican (Python as well) but got a good Nikola vibe. I have not yet customized anything, I did not write a line of code. Well, I admit, one feature that tipped over in favor of Nikola was orgmode support.

Orgmode

I have been using orgmode for several years now. I have been using it as a ToDo list, project management, agenda, I have done some writing in it, I toyed with music typesetting with orgmode and Lilypond, literate programming is a bit tempting as well. Orgmode works for me also just as a simple markup language and it will export your sweat into many, many formats.

Workflow

Initial setup

  • Install docker.
  • Get my docker file git clone https://gitlab.com/djiamnot/nikola-docker.git
  • Inside the checked dorectory: docker build -t nikola .
  • Then read about docker registry: https://docs.docker.com/registry/introduction/
    • Once I've figured out my access to the gitlab registry, I do:
    • docker login registry.gitlab.com
    • from the docker repo: docker build -t registry.gitlab.com/djiamnot/djiamnot.gitlab.io . and then docker push registry.gitlab.com/djiamnot/djiamnot.gitlab.io

I can run the nikola docker image locally as such

docker run --rm -v $PWD:/site -w /site -u $(id -u):$(id -g) -p 8877:8000 nikola nikola

Writing, deploying.

To create this post I used the following command

docker run --rm -v $PWD:/site -w /site -u $(id -u):$(id -g) -p 8877:8000 nikola nikola new_post -f orgmode -t "My Take at Nikola, orgmode, docker" -a MiS --tags="orgmode,docker,nikola" -e

This command will serve serve the thing for inspecting locally on port 8877.

docker run --rm -v $PWD:/site -w /site -u $(id -u):$(id -g) -p 8877:8000 nikola nikola serve

Commit and push to gitlab repo, once configured, will automatically build the site.

Komentarze

Comments powered by Disqus