This blog was started almost 11 years ago, on Octopress 2.0. It was a different world: Ruby 1.x was king of the hill, and Docker wasn’t even a thing yet. It was an amazing thing to use.

Over the years, every time I switched machines, I noticed it was getting harder and harder for me to get the blog and in particular Octopress 2.0 working on it. It was plagued by incompatibility between system versions, tooling, and dependencies on various levels (OS, Gem, Ruby, etc), but I was also getting more and more out of touch with the Ruby world, having long jumped over to other languages.

Still, I loved this Markdown-based blog, and didn’t think it was time to move to a newer version (Octpress 3.0) or another tool (I’d heard good things about Hugo). I simply didn’t have the time to upgrade or port, nor did I feel the need to: it may be using old versions of things, but at the end of the day, it was generating and deploying simple static HTML files that get served. Finally, this year, I decided to take a stab at containerising it so that I could hopefully easily keep using it for years to come (and lose another excuse to not write..).

Overview

References vs what’s new

I didn’t come up with everything from scratch and followed in the footsteps of those who already did most of the heavy lifting.

I just updated some things here and there:

  • Ubuntu LTS 22.04
  • Rancher Desktop

Target audience

  • People who have their own Octopress 2.0 blog already and want to continue to use it. You may have already containerised but it are looking to another take on it.
  • Geeks: Octopress says it’s for “hackers”

Dockerfile

To start with the conclusion, here is the complete Dockerfile in the root dir of my Octopress 2.0 project

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
FROM ubuntu:22.04

# System dependencies, including those required to install Ruby
RUN apt-get update -y && apt-get -y install software-properties-common
RUN add-apt-repository -y ppa:rael-gc/rvm && apt-get update -y && apt-get -y install \
  sudo \
  make \
  git \
  vim less \
  curl \
  build-essential \
  libreadline-dev \
  libssl1.0-dev \
  zlib1g-dev \
  python2.7

# Install gcc-7 for Ruby 2.3 by adding and removing focal source
RUN cp /etc/apt/sources.list /etc/apt/sources.list.bak
RUN echo "deb [arch=amd64] http://archive.ubuntu.com/ubuntu focal main universe" >> /etc/apt/sources.list
RUN apt-get update -y && apt-get -y install g++-7
RUN mv -f /etc/apt/sources.list.bak /etc/apt/sources.list
RUN apt-get update -y

# Install ruby-build & ruby
WORKDIR ~/
RUN curl -L https://github.com/rbenv/ruby-build/archive/refs/tags/v20231225.tar.gz > ruby-build.tar.gz
RUN tar -xzf ruby-build.tar.gz 
RUN PREFIX=/usr/local ./ruby-build-*/install.sh
RUN CC=/usr/bin/gcc-7 ruby-build 2.3.3 /usr/local

# Add blogger user so we don't use the root user and use it
RUN adduser --disabled-password --gecos "" blogger && \
echo "blogger ALL=(root) NOPASSWD:ALL" > /etc/sudoers
USER blogger

# Initialise ruby encording
ENV RUBYOPT -EUTF-8

# Directory for the blog files
RUN sudo mkdir /octopress
WORKDIR /octopress

# Set permissions so blogger can install gems
RUN sudo chown -Rv blogger:blogger /octopress
RUN sudo chown -Rv blogger:blogger /usr/local/lib/ruby
RUN sudo chown -Rv blogger:blogger /usr/local/bin

# # Expose port 4000 so we can preview the blog
EXPOSE 4000

# Add the Gemfile and install the gems
ADD Gemfile /octopress/Gemfile
ADD Gemfile.lock /octopress/Gemfile.lock
RUN gem update --system 3.2.3
RUN gem install bundler -v 2.3
RUN bundle install

# Git config file because Octopress pushes using Git but we might
# not want it to use the exact same settings as our host (e.g. signing)
ADD .gitconfig /home/blogger/.gitconfig

I’ll go through the things that are different from the awesome article at Octopress in a Docker Container. Whatever I don’t call out below should be taken as unchanged from that article, so use it as a reference.

Ubuntu 22.04

The Octopress in a Docker Container article uses Ubuntu but at version 16.04. I love Ubuntu and think it’s a great choice for an Octropess dev env, but since it’s Jan 2024, I wanted to use the latest Ubuntu LTS release (required for Ruby 2.3) install, 22.04, instead (knowing full well that the next LTS is slated for release in a few months..). Hence

1
FROM ubuntu:22.04

That brought interesting challenges, mostly stemming from the fact that the default apt-get install for ruby would be too new for (my) Octopress installation’s dependencies.

Installing Ruby 2.3

There are different ways to install Ruby on a system, but I opted for ruby-build, in particular the standalone install option because it was simple.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# System dependencies, including those required to install Ruby
RUN apt-get update -y && apt-get -y install software-properties-common
RUN add-apt-repository -y ppa:rael-gc/rvm && apt-get update -y && apt-get -y install \
  sudo \
  make \
  git \
  vim less \
  curl \
  build-essential \
  libreadline-dev \
  libssl1.0-dev \
  zlib1g-dev \
  python2.7

# Install gcc-7 for Ruby 2.3 by adding and removing focal source
RUN cp /etc/apt/sources.list /etc/apt/sources.list.bak
RUN echo "deb [arch=amd64] http://archive.ubuntu.com/ubuntu focal main universe" >> /etc/apt/sources.list
RUN apt-get update -y && apt-get -y install g++-7
RUN mv -f /etc/apt/sources.list.bak /etc/apt/sources.list
RUN apt-get update -y

# Install ruby-build & ruby
WORKDIR ~/
RUN curl -L https://github.com/rbenv/ruby-build/archive/refs/tags/v20231225.tar.gz > ruby-build.tar.gz
RUN tar -xzf ruby-build.tar.gz 
RUN PREFIX=/usr/local ./ruby-build-*/install.sh
RUN CC=/usr/bin/gcc-7 ruby-build 2.3.3 /usr/local

The main thing here was installing libssl1.0-dev (I used the RVM PPA), and installing GCC-7 (otherwise I got segfaults using Ruby).

Gemfile.lock file for project dependencies

Since my goal was to get this working with an old Octopress blog and I didn’t want to mess around with version conflicts, I ADDed the Gemfile.lock file as well, before RUNning bundle install

1
2
3
4
5
6
# Add the Gemfile and install the gems
ADD Gemfile /octopress/Gemfile
ADD Gemfile.lock /octopress/Gemfile.lock
RUN gem update --system 3.2.3
RUN gem install bundler -v 2.3
RUN bundle install

Compared with the reference article, we update Rubygems and lock down the bundler version.

Rakefile

This is mentioned in the Octopress in a Docker Container article as well, but I’ll mention it here too: in order to preview the blog, you need to change the Rakefile from

1
rackupPid = Process.spawn("rackup --port #{server_port}")

to

1
rackupPid = Process.spawn("rackup -o 0.0.0.0 --port #{server_port}")

Docker

With Rancher Desktop

Since it’s 2024, I also wanted to try using a Docker Desktop alternative, and chose Rancher Desktop. Overall, the entire experience was really smooth and in my Octopress usage so far, I. haven’t noticed much difference between Rancher Desktop and Docker Desktop, but I’ve only been lightly using docker CLI.

I did notice that the auto-regenerate-based-on-changes feature of rake preview worked better (faster, more reliably) with the VZ emulation mode and virtiofs volume mount type.

Makefile to work with all of the above

I added a Makefile to make it simpler for future me to deal with building the image and working with it

1
2
3
4
5
build-image:
	docker build . -t blog/octopress

start-env:
	docker run -p 4000:4000 --rm --volume $$(pwd):/octopress --volume ${HOME}/.ssh:/home/blogger/.ssh -ti blog/octopress /bin/bash

This is entirely optional/subjective but I find make start-env more manageable for starting an Octopress env that has everything mounted properly.

Conclusion

So that’s it: yet another containerised-Octopress-2.0 article, with this entry being the first beachape.com one that was written and published entirely using it.

Comments