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.


.PHONY: default hugo public server

CWD=$(shell pwd)

default: public

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

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

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


FROM golang:1.9

# Install govendor, then install hugo as per their directions 
RUN go get -u && \
  govendor get && \
  go install

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



CMD ["hugo"]
comments powered by Disqus