Fixed dockerfile
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Hamcha 2022-03-25 20:14:02 +01:00
parent 42de49b13d
commit da6f91b58b
Signed by: hamcha
GPG key ID: 1669C533B8CF6D89

View file

@ -1,24 +1,36 @@
FROM golang:alpine as golang
WORKDIR /go/src/app
COPY . .
ARG GO_VERSION=1.18
# Static build required so that we can safely copy the binary over.
RUN CGO_ENABLED=0 go build -o /go/bin/app -ldflags '-extldflags "-static"'
# STAGE 1: building the executable
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
RUN apk --no-cache add tzdata zip ca-certificates
WORKDIR /usr/share/zoneinfo
# -0 means no compression. Needed because go's
# tz loader doesn't handle compressed data.
RUN zip -r -0 /zoneinfo.zip .
# add a user here because addgroup and adduser are not available in scratch
RUN addgroup -S myapp \
&& adduser -S -u 10000 -g myapp myapp
FROM scratch
# the test program:
COPY --from=golang /go/bin/app /app
# the timezone data:
ENV ZONEINFO /zoneinfo.zip
COPY --from=alpine /zoneinfo.zip /
# the tls certificates:
COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
WORKDIR /src
COPY ./go.mod ./go.sum ./
RUN go mod download
COPY ./ ./
# Build the executable
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"]