Skip to content

Commit

Permalink
Support Docker args TAGS, WORKDIR, CGO; speed up repetitive builds
Browse files Browse the repository at this point in the history
  • Loading branch information
tonymet committed Feb 22, 2019
1 parent b4148cd commit 075b17e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
.circleci
docs
examples
Dockerfile
26 changes: 16 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]

0 comments on commit 075b17e

Please sign in to comment.