-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
58 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,54 @@ | ||
# Taken from https://github.com/chemidy/smallest-secured-golang-docker-image | ||
|
||
FROM golang@sha256:244a736db4a1d2611d257e7403c729663ce2eb08d4628868f9d9ef2735496659 as builder | ||
|
||
# Install git + SSL ca certificates. | ||
# Git is required for fetching the dependencies. | ||
# Ca-certificates is required to call HTTPS endpoints. | ||
RUN apk update && apk add --no-cache git ca-certificates tzdata && update-ca-certificates | ||
|
||
# Create appuser | ||
ENV USER=appuser | ||
ENV UID=10001 | ||
|
||
# See https://stackoverflow.com/a/55757473/12429735 | ||
RUN adduser \ | ||
--disabled-password \ | ||
--gecos "" \ | ||
--home "/nonexistent" \ | ||
--shell "/sbin/nologin" \ | ||
--no-create-home \ | ||
--uid "${UID}" \ | ||
"${USER}" && \ | ||
mkdir /build && \ | ||
chown -R "${USER}":"${USER}" /build | ||
WORKDIR /build | ||
"${USER}" | ||
WORKDIR $GOPATH/src/mypackage/myapp/ | ||
COPY . . | ||
RUN go get -d -v && \ | ||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ | ||
|
||
# Fetch dependencies. | ||
RUN go get -d -v | ||
|
||
# Build the binary | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ | ||
-ldflags='-w -s -extldflags "-static"' -a \ | ||
-o shomon . | ||
USER appuser:appuser | ||
ENTRYPOINT [ "./shomon" ] | ||
-o /go/bin/shomon . | ||
|
||
############################ | ||
# STEP 2 build a small image | ||
############################ | ||
FROM scratch | ||
|
||
# Import from builder. | ||
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo | ||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
COPY --from=builder /etc/passwd /etc/passwd | ||
COPY --from=builder /etc/group /etc/group | ||
|
||
# Copy our static executable | ||
COPY --from=builder /go/bin/shomon /go/bin/shomon | ||
|
||
# Use an unprivileged user. | ||
USER appuser:appuser | ||
WORKDIR /go/bin/ | ||
# Run the shomon binary. | ||
ENTRYPOINT ["/go/bin/shomon"] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters