Dockerize your hugo

I like to automate when I can. Sometimes it is it boring stuff, sometimes it's for the fun of figuring it out. When I first started using hugo I found that having the latest hugo installed on each of my machines was, at times, a tiresum exercise when all I wanted to do was write a post. So, I made a custom docker image and makefile to automate it.

If I want to build the latest hugo, I run make hugo.

If I want to host a hugo server, I run make server.

If I want to public my static site, I run make public. I use this as part of my DroneCI automation whenever I push a commit.

Makefile

  
.PHONY: default hugo public server

CWD=$(shell pwd)

default: public

# build hugo docker image
hugo: 
  install -d ./tmp/hugo
  cp Dockerfile.hugo ./tmp/hugo/Dockerfile
  docker build --no-cache -t hugo  ./tmp/hugo

# generate site into public folder
public:
  docker run -i --rm \
    --mount type=bind,source="${CWD}",target=/hugo \
    hugo

# host a server with the docker image created
server:
  docker run -i --rm \
    --mount type=bind,source="${CWD}",target=/hugo \
    -e 1313 \
    -p 1313:1313 \
    hugo \
    hugo server -D --bind="0.0.0.0"    
  

Dockerfile.hugo

  
FROM golang:1.9

# Install govendor, then install hugo as per their directions 
RUN go get -u github.com/kardianos/govendor && \
  govendor get github.com/gohugoio/hugo && \
  go install github.com/gohugoio/hugo

# we bind mount our hugo folder here
VOLUME ["/hugo"]

WORKDIR /hugo

EXPOSE 1313

CMD ["hugo"]
  
comments powered by Disqus