# syntax=docker/dockerfile:1
FROM golang:1.20.4-alpine3.17 AS build
WORKDIR /app
RUN rm /etc/passwd \
 && touch /etc/passwd /etc/group \
 && adduser --disabled-password --shell /sbin/nologin --no-create-home --uid 1000 nonroot
COPY go.* .
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -ldflags "-s -w" -trimpath -o gotography-web main.go

FROM scratch
COPY --from=build /etc/passwd /etc/passwd
COPY --from=build --chown=nonroot /app/gotography-web /app/gotography-web
ENV GIN_MODE release
USER nonroot
ENTRYPOINT ["/app/gotography-web"]
