Support Docker args TAGS, WORKDIR, CGO; speed up repetitive builds
authorAnthony Metzidis <anthony.metzidis@gmail.com>
Thu, 7 Feb 2019 01:01:26 +0000 (17:01 -0800)
committerAnthony Metzidis <anthony.metzidis@gmail.com>
Fri, 22 Feb 2019 19:53:17 +0000 (11:53 -0800)
.dockerignore
Dockerfile

index 3342288b470323cd4cfdcb4069c141882535b277..a183f6fcfdf50e6bc20ca60501b7acae84dd00e6 100644 (file)
@@ -6,3 +6,4 @@
 .circleci
 docs
 examples
+Dockerfile
index 2cd4a14d6cf3ae2255b9c2752d9df0a54c4f7d5b..01132e33e379c0241954293e015987fa0640778b 100755 (executable)
@@ -2,25 +2,31 @@
 # Twitter:      https://twitter.com/gohugoio
 # Website:      https://gohugo.io/
 
-FROM golang:1.11-alpine3.7 AS build
+FROM golang:1.11-stretch AS build
 
-ENV CGO_ENABLED=0
-ENV GOOS=linux
-ENV GO111MODULE=on
 
 WORKDIR /go/src/github.com/gohugoio/hugo
-RUN apk add --no-cache \
-    git \
-    musl-dev
+RUN apt-get install \
+    git gcc g++ binutils
 COPY . /go/src/github.com/gohugoio/hugo/
-RUN go install -ldflags '-s -w'
+ENV GO111MODULE=on
+RUN go get -d .
+
+ARG CGO=0
+ENV CGO_ENABLED=${CGO}
+ENV GOOS=linux
+
+# 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}
 
 # ---
 
 FROM scratch
 COPY --from=build /go/bin/hugo /hugo
-WORKDIR /site
-VOLUME  /site
+ARG  WORKDIR="/site"
+WORKDIR ${WORKDIR}
+VOLUME  ${WORKDIR}
 EXPOSE  1313
 ENTRYPOINT [ "/hugo" ]
 CMD [ "--help" ]