-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
37 lines (26 loc) · 1.17 KB
/
Dockerfile
File metadata and controls
37 lines (26 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Build the application from source
FROM golang:1.24.3 AS build-stage
WORKDIR /go/src/lokix
# Dependency Caching
COPY go.mod go.sum ./
RUN go mod download
COPY . .
# vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string.
# vet uses heuristics that do not guarantee all reports are genuine problems, but it can find errors not caught by the compilers.
RUN go vet -v ./...
# RUN go test -v
# CGO_ENABLED=0 as my project doesn't use cgo, and I'll be running the binary on a distroless base-image
# This creates a statically linked binary suitable for distroless
# IF a library uses CGO, the build will FAIL
RUN CGO_ENABLED=0 go build -o /go/bin/lokix cmd/lokix/main.go
# Run the tests in the container
FROM build-stage AS run-test-stage
RUN go test -v ./...
# Deploying the application binary into a lean image
# Using a distroless base-image to minimize the image size and maximize security
# Copying only the binary to this image from the build stage
FROM gcr.io/distroless/base-debian12 AS build-release-stage
WORKDIR /
COPY --from=build-stage /go/bin/lokix /lokix
USER nonroot:nonroot
ENTRYPOINT ["/lokix"]