owntracks/go/Dockerfile

29 lines
499 B
Text
Raw Normal View History

2025-03-26 22:47:15 +00:00
# syntax=docker/dockerfile:1
2025-01-19 18:46:23 +01:00
2025-03-26 22:47:15 +00:00
# Build the application from source
FROM golang:1.21.4 AS build-stage
2025-01-19 18:46:23 +01:00
2025-03-26 22:47:15 +00:00
WORKDIR /app
2025-01-19 18:46:23 +01:00
2025-03-26 22:47:15 +00:00
COPY * ./
RUN go mod download
2025-01-19 18:46:23 +01:00
2025-03-26 22:47:15 +00:00
RUN CGO_ENABLED=0 GOOS=linux go build -o /main
# 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 /main /main
2025-01-19 18:46:23 +01:00
EXPOSE 8080
2025-03-26 22:47:15 +00:00
USER nonroot:nonroot
ENTRYPOINT ["/main"]