Update dockerfile
This commit is contained in:
51
dockerfile
51
dockerfile
@@ -1,32 +1,21 @@
|
|||||||
FROM golang:1.21.6 as base
|
FROM golang:1.21.6 as base
|
||||||
|
|
||||||
RUN adduser \
|
WORKDIR $GOPATH/src/app/
|
||||||
--disabled-password \
|
|
||||||
--gecos "" \
|
COPY . .
|
||||||
--home "/nonexistent" \
|
|
||||||
--shell "/sbin/nologin" \
|
RUN go mod download
|
||||||
--no-create-home \
|
RUN go mod verify
|
||||||
--uid 65532 \
|
|
||||||
small-user
|
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /main .
|
||||||
|
|
||||||
WORKDIR $GOPATH/src/app/
|
FROM scratch
|
||||||
|
|
||||||
COPY . .
|
COPY --from=base /usr/share/zoneinfo /usr/share/zoneinfo
|
||||||
|
COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||||
RUN go mod download
|
COPY --from=base /etc/passwd /etc/passwd
|
||||||
RUN go mod verify
|
COPY --from=base /etc/group /etc/group
|
||||||
|
|
||||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /main .
|
COPY --from=base /main .
|
||||||
|
|
||||||
FROM scratch
|
|
||||||
|
|
||||||
COPY --from=base /usr/share/zoneinfo /usr/share/zoneinfo
|
|
||||||
COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
|
||||||
COPY --from=base /etc/passwd /etc/passwd
|
|
||||||
COPY --from=base /etc/group /etc/group
|
|
||||||
|
|
||||||
COPY --from=base /main .
|
|
||||||
|
|
||||||
USER small-user:small-user
|
|
||||||
|
|
||||||
CMD ["/main"]
|
CMD ["/main"]
|
Reference in New Issue
Block a user