I use gitlab and its built-in CI for my person blog (see details). Today I was trying to “update” hugo in the docker image, and I found myself making a couple of mistakes, including losing the dockerfile for the base image I built a long time ago! I decide to recreate a new one and push the Dockerfile to public repo so that everyone can reuse it.

A few benefits of automated builds:

  • Dockerfile is public and everyone can see the content in a dedicated tab.
  • Docker hub provides a “mini CI” to build your images and you don’t have push entire image to docker hub.
  • Builds can be triggered by changes on the repo
  • git tags can be used for image tags too.

Recreate the image

Remember you can always run “into” the image by attaching tty when running the image: docker run -it alpine:latest. This will allow you to test image without actually building it.

All I need in the image is hugo and firebase-cli. I referenced giantswarm/hugo and use official node:8.4.0-alpine directly as the base image since firebase-cli uses npm.

The final dockerfile I have:

FROM node:8.4.0-alpine

# labels
LABEL maintainer="nohitme@gmail.com"

# variables
ENV HUGO_VERSION 0.26

# install hugo
RUN set -x && \
  apk add --update wget ca-certificates && \
  cd /tmp &&\
  wget https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_${HUGO_VERSION}_Linux-64bit.tar.gz -O hugo.tar.gz && \
  tar xzf hugo.tar.gz && \
  mv hugo /usr/bin/hugo && \
  rm -r * && \
  apk del wget ca-certificates && \
  rm /var/cache/apk/*

# install firebase-cli
RUN npm install -g firebase-tools

I tweaked the portion of installing hugo a bit since there are some changes to the repo name and file structure.

Configure a Automated Build on docker hub

Now I have a working image and pushed the dockerfile to a public github repo (link).

Go ahead and “Create Automated Build”

create

Select your repository either from github or bucket (right, no gitlab for now)

select

Configure details in your image registry page

Now you should see your image is marked as AUTOMATED BUILD on top left and three extra tabs showed up: Dockerfile, Build Details, and Build Settings.

registry

# Dockerfile

By default docker hub will look for Dockerfile at repo’s root. You can change it in the setting page too. If you have it in the repo, you can see the content in this page.

dockerfile

Note that Dockerfile MUST have the right cases in filename. On OSX cases do not really matter, you can build image just fine with dockerfile. But when building on docker hub, lowercase dockerfile will fail. (I tried it)

# Build Details

In this page you can see each build’s status. You can also click on each build to see the full console out for the build.

details

# Build Settings

Here you can configure how you want to tag the docker image. You can specify a branch or tag by regex matching, and further use the matched result to tag your image.

Currently I have master branch for latest and a simple tag matching to product tag like 0.26.

details

Thoughts

  • You should probably create automated builds for all your public images on docker hub. (who does not like sharing?)
  • Feel free to copy my images if they’re useful to you.
  • Happy dockering!