This commit is contained in:
parent
42de49b13d
commit
da6f91b58b
1 changed files with 31 additions and 19 deletions
50
Dockerfile
50
Dockerfile
|
@ -1,24 +1,36 @@
|
||||||
FROM golang:alpine as golang
|
ARG GO_VERSION=1.18
|
||||||
WORKDIR /go/src/app
|
|
||||||
COPY . .
|
|
||||||
|
|
||||||
# Static build required so that we can safely copy the binary over.
|
# STAGE 1: building the executable
|
||||||
RUN CGO_ENABLED=0 go build -o /go/bin/app -ldflags '-extldflags "-static"'
|
FROM golang:${GO_VERSION}-alpine AS build
|
||||||
|
RUN apk add --no-cache git
|
||||||
|
RUN apk --no-cache add ca-certificates
|
||||||
|
|
||||||
FROM alpine:latest as alpine
|
# add a user here because addgroup and adduser are not available in scratch
|
||||||
RUN apk --no-cache add tzdata zip ca-certificates
|
RUN addgroup -S myapp \
|
||||||
WORKDIR /usr/share/zoneinfo
|
&& adduser -S -u 10000 -g myapp myapp
|
||||||
# -0 means no compression. Needed because go's
|
|
||||||
# tz loader doesn't handle compressed data.
|
|
||||||
RUN zip -r -0 /zoneinfo.zip .
|
|
||||||
|
|
||||||
FROM scratch
|
WORKDIR /src
|
||||||
# the test program:
|
COPY ./go.mod ./go.sum ./
|
||||||
COPY --from=golang /go/bin/app /app
|
RUN go mod download
|
||||||
# the timezone data:
|
|
||||||
ENV ZONEINFO /zoneinfo.zip
|
COPY ./ ./
|
||||||
COPY --from=alpine /zoneinfo.zip /
|
|
||||||
# the tls certificates:
|
# Build the executable
|
||||||
COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
RUN CGO_ENABLED=0 go build \
|
||||||
|
-installsuffix 'static' \
|
||||||
|
-o /app .
|
||||||
|
|
||||||
|
# STAGE 2: build the container to run
|
||||||
|
FROM scratch AS final
|
||||||
|
LABEL maintainer="gbaeke"
|
||||||
|
COPY --from=build /app /app
|
||||||
|
|
||||||
|
# copy ca certs
|
||||||
|
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||||
|
|
||||||
|
# copy users from builder (use from=0 for illustration purposes)
|
||||||
|
COPY --from=0 /etc/passwd /etc/passwd
|
||||||
|
|
||||||
|
USER myapp
|
||||||
|
|
||||||
ENTRYPOINT ["/app"]
|
ENTRYPOINT ["/app"]
|
Loading…
Reference in a new issue