Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Dockerfile to a multi-stage build #4518

Merged
merged 1 commit into from
Jun 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.md
*.log
*.txt
.git
.github
.circleci
docs
examples
34 changes: 19 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
FROM golang:1.9.0-alpine3.6 AS build
# GitHub: https://github.com/gohugoio
# Twitter: https://twitter.com/gohugoio
# Website: https://gohugo.io/

RUN apk add --no-cache --virtual git musl-dev
RUN go get github.com/golang/dep/cmd/dep
FROM golang:1.10.0-alpine3.7 AS build

ENV CGO_ENABLED=0
ENV GOOS=linux

WORKDIR /go/src/github.com/gohugoio/hugo
ADD . /go/src/github.com/gohugoio/hugo/
RUN dep ensure
RUN go install -ldflags '-s -w'
RUN apk add --no-cache \
git \
musl-dev && \
go get github.com/golang/dep/cmd/dep
COPY . /go/src/github.com/gohugoio/hugo/
RUN dep ensure -vendor-only && \
go install -ldflags '-s -w'

# ---

FROM alpine:3.6
RUN \
adduser -h /site -s /sbin/nologin -u 1000 -D hugo && \
apk add --no-cache \
dumb-init
COPY --from=build /go/bin/hugo /bin/hugo
USER hugo
FROM scratch
COPY --from=build /go/bin/hugo /hugo
WORKDIR /site
VOLUME /site
EXPOSE 1313

ENTRYPOINT ["/usr/bin/dumb-init", "--", "hugo"]
ENTRYPOINT [ "/hugo" ]
CMD [ "--help" ]