under docker on DigitalOcean

Unfortunately, no one has infinite time to sort through all the nifty new sites/tools/apps floating around. Fortunately, various ‘trending’ sites like github's trending repos tell us what is hot! That's how I stumbled across the blogging platform: ghost

The ghost site and designs look promising, so why not give it a try? Otherwise, I‘m just going to keep making more github/readme.md files which is not the most elegent solution when it comes to spewing my thoughts to the masses. Plus last time that ended up with over a dozen commits just to get my markdown correct (I don’t have a viewer installed). Ghost provides side by side Markdown editing / preview!

I've also been looking for an excuse to put my newfound favorite virtualization/container engine, docker to work. (Move over vagrant+virtualbox+ansible!).

DigitalOcean provides the last piece of the puzzle: Virtual Private Hosting. $5 a month for your own box!

Okay, so how can one get this show up and running:

Setup a DigitalOcean account:

  1. Search for a promo code. I found one at some sketchy page called OCT15FREE which supposedly gives me $15 of free credit. Seems like it worked, for now.
  2. Create an account at DigitalOcean
  3. Add your billing info (CC / PayPal)
  4. Create a droplet. I like debian, so I went with Debian 7.0 x64.
  5. Wait about 1 minute for until your login credentials to appear in your e-mail.
  6. You can login as root via ssh or use the web console.

Upgrade droplet dist and kernel:

Assuming you chose Debian 7.0 x64, use these instructions. Otherwise you can figure it out for your own preferred flavor. It doesn't matter too much as you can use a different one under docker.

Edit /etc/apt/sources.lst using vi:

deb http://http.debian.net/debian/ jessie main
deb-src http://http.debian.net/debian/ jessie main

deb http://security.debian.org/ jessie/updates main
deb-src http://security.debian.org/ jessie/updates main

deb http://http.debian.net/debian/ jessie contrib non-free

Now do a dist upgrade to get a new kernel:

apt-get update
apt-get dist-upgrade

You could simply change your kernel version using the DigitalOcean dashboard and skip this next step. Apparently, and in my own experience too, the DigitalOcean VPS doesn't pay attention to the grub boot loader configuration. I followed this youtube screencast to set up the kernel that I wanted to run: Custom Kernels on DigitalOcean. I tweaked it a bit for docker, and here is the result:

Edit /etc/init.d/rcS using vi:

if grep -qv ' kexeced$' /proc/cmdline ;then
        kexec --load /vmlinuz --initrd=/initrd.img --append='root=LABEL=DOROOT cgroup_enable=memory swapaccount=1 kexeced' &&
        mount -o ro,remount / &&
        kexec -e
fi

Install a few dependencies and reboot:

apt-get install kexec-tools  # select YES
# you could just reboot now, but might as well
# do docker stuff too to minimize reboots
apt-get install lxc aufs-tools # for docker
echo "net.ipv4.ip_forward=1" > /etc/sysctl.d/docker.conf
echo "cgroup             /sys/fs/cgroup  cgroup  defaults          0       0" >> /etc/fstab
reboot

At this point you can watch the system reboot in the web console. If you got something really wrong, you might have to start from a fresh droplet. I got stuck in an infinite reboot loop the first time I tried it! :)

After the system comes back up, confirm you're running a new Linux kernel e.g. 3.10-2-amd64 by running uname -a. If all is well, move on to installing docker.
Installing docker:

Everything is in place from above for full docker capability, so let's install it into /opt/docker now:

mkdir /opt/docker && cd /opt/docker
wget --output-document=docker https://get.docker.io/builds/Linux/x86_64/docker-latest
chmod +x docker
# run the docker daemon:
./docker -d &
# check your docker version:
./docker version

You should see something like:

Client version: 0.6.4
Go version (client): b0a49a3
Git commit (client): b0a49a3
Server version: 0.6.4
...

Setup Ghost 0.3.3:

Build your docker image from a Dockerfile:

Create a few directoires to hold your data:

mkdir /opt/docker/ghost
mkdir /opt/docker/ghost/data

Create and edit /opt/docker/ghost/Dockerfile

I used this file as the base Dockerfile, but changed it to point to the latest version of Ghost at the time:
Dockerfile

Now build the docker image. You can tag the repo name with your own handle or whatever you'd like:

./docker build -t ubergarm/ghost /opt/docker/ghost/

Wait a few minutes for it to build the image file and then run it according to these comments:

sudo docker run -e GHOST_HTTP_URL=http://your_url.com -e MAIL_FROMADDRESS=ghost@your_url.com -e MAIL_SERVICE=your_mail_service -e MAIL_USERNAME=your_username -e MAIL_PASSWORD=your_password -e NODE_ENV=production -p 80:2368 -v /opt/docker/ghost/data:/content/data -d ubergarm/ghost npm start

Finally, you can setup the blog admin username and start posting by pointing your browser at: http://your_url.com/ghost

Thoughts:

After having written this initial post, I'm not terribly excited about using Ghost! It looks pretty good, and the side-by-side markdown is handy, but not working too well in my browser (iceweasel+vimperator+xmonad). I have to keep using the scroll bars to adjust the display and my cursor gets lost at the bottom under the stylesheet pop-up stuff.

I also don‘t have my vim shortcuts, and it is a hassle to use and style cut and paste which isn’t tied into the mouse middle from my console based vim. (I don't have vim compiled with graphical clipboard support, but rely on xclip tricks). Myself and others have noticed similar difficulties in ipython-notebook.

Finally, there is manul Save Draft functionality, but I'm not sure how to turn on auto-saving. Something feels strange not using git and relying on the SQLite .db file.

Maybe I'll check out some other blogging frameworks that fit my vim/git workfly then add the markdown viewing functionality using a different tool.

EDIT

I ended up going with hexo for now!

What

Set up a Node.js powered flat file blog using hexo hosted on github pages.

Why

  1. You can use your own editor! (hint: vim)
  2. Flat text documents make mouths happy!
  3. You can revision control everything through git!
  4. Cheap as free to get started!
  5. Learn you some hot node.js!
  6. Because ghost seems more hipster than Sriracha sauce

How

  1. Setup a yourgithubusername.github.io page following this guide
  2. Follow the hexo documentation install using Node Version Manager similar to python's virtualenv
  3. Configure the _configure.yml file

ProTips

  1. Play with some of the hexo themes
  2. I kind of liked Greyshade Theme

    $ cd ~/hexoblog/themes
    $ git clone https://github.com/nuklly/hexo-theme-greyshade ./greyshade
    $ vim ~/hexoblog/_config.yml # theme: greyshade

Example Workflow

$ cd ~/hexoblog
$ hexo new page about # do this once to generate your about page
$ hexo new post "Great New Post" # it defaults to post so can omit that word
# <edit the .md file in vim>
$ hexo generate
$ hexo deploy

This is the default first post from hexo. I left it here.

Welcome to Hexo! This is your very first post. Check documentation to learn how to use.

Copyright © 2013 - ubergarm - Powered by Hexo
- Ported theme GreyShade -