avatars/Dockerfile
nisan 8220922cc9
All checks were successful
Publish Docker Image / build_push (push) Successful in 1m39s
initial commit 🚀
2024-07-31 21:00:37 +03:00

48 lines
1001 B
Docker

FROM golang:1.22.5-alpine3.20 AS builder
# Create appuser.
ENV USER=appuser
ENV UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"
WORKDIR $GOPATH/src/avatars/
COPY . .
# Fetch dependencies.
RUN go mod download
RUN go mod verify
# Build the binary.
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /go/bin/avatars
############################
# STEP 2 build a small image
############################
FROM scratch
# Import the user and group files from the builder.
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group
# Copy our static executable.
COPY --from=builder /go/bin/avatars /go/bin/avatars
# Set Work directory for relative paths of assets
# WORKDIR /go/bin
# Expose API Port
EXPOSE 3382
# Use an unprivileged user.
USER appuser:appuser
# Run the hello binary.
ENTRYPOINT ["/go/bin/avatars"]