2024-01-11 22:23:10 +01:00
|
|
|
# syntax=docker/dockerfile:1
|
|
|
|
|
|
|
|
# Build the application from source
|
|
|
|
FROM golang:1.21.4 AS build-stage
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
2024-01-16 12:27:40 +01:00
|
|
|
COPY go.mod go.sum ./
|
2024-01-11 22:23:10 +01:00
|
|
|
RUN go mod download
|
|
|
|
|
|
|
|
COPY *.go ./
|
|
|
|
|
|
|
|
RUN CGO_ENABLED=0 GOOS=linux go build -o /picture-uploader
|
|
|
|
|
|
|
|
# Run the tests in the container
|
|
|
|
FROM build-stage AS run-test-stage
|
|
|
|
RUN go test -v ./...
|
|
|
|
|
|
|
|
# Deploy the application binary into a lean image
|
|
|
|
FROM gcr.io/distroless/base-debian11 AS build-release-stage
|
|
|
|
|
|
|
|
WORKDIR /
|
|
|
|
|
|
|
|
COPY --from=build-stage /picture-uploader /picture-uploader
|
|
|
|
|
|
|
|
EXPOSE 8080
|
|
|
|
|
|
|
|
USER nonroot:nonroot
|
|
|
|
|
|
|
|
ENTRYPOINT ["/picture-uploader"]
|