generated from esacteksab/go-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
30 lines (21 loc) · 1.21 KB
/
Dockerfile
File metadata and controls
30 lines (21 loc) · 1.21 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
FROM esacteksab/go:1.25.0-2025-10-03@sha256:426d93bbf6fb75cb316688c3679c69b45f50856b8b16c290d47210f3cc2ee41c AS builder
# Set GOMODCACHE explicitly
ENV GOMODCACHE=/go/pkg/mod
WORKDIR /app
# Copy only module files first to maximize caching
COPY go.mod go.sum ./
# Download modules. This layer will be cached if go.mod/go.sum haven't changed.
# The downloaded files will now be part of this layer's filesystem.
RUN go mod download
# Copy the rest of the application code
COPY . .
# Keep cache mounts here for build performance (Go build cache + reusing modules during build)
RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build scripts/build-dev.sh
RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build scripts/help-docker.sh
# --- Test Stage ---
FROM builder AS test-stage
RUN mkdir -p /app/coverdata
ENV GOCOVERDIR=/app/coverdata
# !!! DO NOT ADD A `-v` TO THIS CMD AND ALLOW TO RUN IN GITHUB ACTIONS. YOU **WILL** LEAK GITHUB_TOKEN !!!
# Go test should now find modules in /go/pkg/mod inherited from the builder stage
CMD ["/bin/sh", "-c", "go test -covermode=atomic -coverprofile=/app/coverdata/coverage.out ./... && echo 'Coverage data collected'"]