summaryrefslogtreecommitdiffstats
path: root/Dockerfile
diff options
context:
space:
mode:
authorJake Jarvis <jake@jarv.is>2019-10-09 11:27:08 -0400
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-10-31 09:53:49 +0100
commited2682325aeb8fd1c8139077d14a5f6906757a4e (patch)
tree80e778a02444522db376b5110812d87c35bea8ab /Dockerfile
parent66fe68ffc98974936e157b18cf6bd9266ee081a4 (diff)
Dockerfile: Switch to mage builds, various optimizations
- Use Alpine for both stages for consistency. - Switch to mage from go install as dictated in the latest docs. - Easy switch to building Hugo Extended by directly setting HUGO_BUILD_TAGS flag at image build time: `docker build --build-arg HUGO_BUILD_TAGS=extended .` - Update to Go 1.13 and Alpine 3.10. - The only possibly breaking change: Moved the `hugo` binary in the final stage from /hugo to /usr/bin/hugo so one can simply run `hugo` without having to search around for its location.
Diffstat (limited to 'Dockerfile')
-rwxr-xr-xDockerfile52
1 files changed, 32 insertions, 20 deletions
diff --git a/Dockerfile b/Dockerfile
index 4728a0f2e..02a150992 100755
--- a/Dockerfile
+++ b/Dockerfile
@@ -2,32 +2,44 @@
# Twitter: https://twitter.com/gohugoio
# Website: https://gohugo.io/
-FROM golang:1.11-stretch AS build
+FROM golang:1.13-alpine AS build
+# Optionally set HUGO_BUILD_TAGS to "extended" when building like so:
+# docker build --build-arg HUGO_BUILD_TAGS=extended .
+ARG HUGO_BUILD_TAGS
+
+ARG CGO=1
+ENV CGO_ENABLED=${CGO}
+ENV GOOS=linux
+ENV GO111MODULE=on
WORKDIR /go/src/github.com/gohugoio/hugo
-RUN apt-get install \
- git gcc g++ binutils
+
COPY . /go/src/github.com/gohugoio/hugo/
-ENV GO111MODULE=on
-RUN go get -d .
-ARG CGO=0
-ENV CGO_ENABLED=${CGO}
-ENV GOOS=linux
+# gcc/g++ are required to build SASS libraries for extended version
+RUN apk update && \
+ apk add --no-cache gcc g++ musl-dev && \
+ go get github.com/magefile/mage
-# default non-existent build tag so -tags always has an arg
-ARG BUILD_TAGS="99notag"
-RUN go install -ldflags '-w -extldflags "-static"' -tags ${BUILD_TAGS}
+RUN mage hugo && mage install
# ---
-FROM alpine:3.9
-RUN apk add --no-cache ca-certificates
-COPY --from=build /go/bin/hugo /hugo
-ARG WORKDIR="/site"
-WORKDIR ${WORKDIR}
-VOLUME ${WORKDIR}
-EXPOSE 1313
-ENTRYPOINT [ "/hugo" ]
-CMD [ "--help" ]
+FROM alpine:3.10
+
+COPY --from=build /go/bin/hugo /usr/bin/hugo
+
+# libc6-compat & libstdc++ are required for extended SASS libraries
+# ca-certificates are required to fetch outside resources (like Twitter oEmbeds)
+RUN apk update && \
+ apk add --no-cache ca-certificates libc6-compat libstdc++
+
+VOLUME /site
+WORKDIR /site
+
+# Expose port for live server
+EXPOSE 1313
+
+ENTRYPOINT ["hugo"]
+CMD ["--help"]