Dockerfile (783B)
1 FROM golang:1.21-alpine AS builder 2 3 ENV UID=10001 4 5 RUN adduser \ 6 --disabled-password \ 7 --gecos "" \ 8 --shell "/sbin/nologin" \ 9 --no-create-home \ 10 --uid "${UID}" \ 11 "appuser" 12 13 WORKDIR /app 14 15 # Copy go mod and sum files 16 COPY go.mod go.sum ./ 17 18 # Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed 19 RUN go mod download 20 RUN go mod verify 21 22 # Copy the source from the current directory to the Working Directory inside the container 23 COPY . . 24 25 RUN go build -v -tags prod -o /bin/functions ./cmd/functions 26 27 28 FROM scratch 29 30 COPY --from=builder /etc/passwd /etc/passwd 31 COPY --from=builder /etc/group /etc/group 32 COPY --from=builder /bin/functions /bin/functions 33 34 USER appuser:appuser 35 36 WORKDIR / 37 38 ENTRYPOINT ["/bin/functions"]