-
Notifications
You must be signed in to change notification settings - Fork 0
perf: optimize docker build #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| # syntax=docker/dockerfile:1.7 | ||
| # Use the official golang image to create a binary. | ||
| # This is based on Debian and sets the GOPATH to /go. | ||
| # https://hub.docker.com/_/golang | ||
|
|
@@ -8,7 +9,8 @@ WORKDIR /app | |
|
|
||
| # Cache deps | ||
| COPY go.mod go.sum ./ | ||
| RUN go mod download | ||
| RUN --mount=type=cache,target=/go/pkg/mod \ | ||
| go mod download | ||
|
Comment on lines
+12
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When using |
||
|
|
||
| # Copy source | ||
| COPY . . | ||
|
|
@@ -18,7 +20,9 @@ ARG TARGETOS | |
| ARG TARGETARCH | ||
|
|
||
| # Build static binary for correct platform | ||
| RUN CGO_ENABLED=0 \ | ||
| RUN --mount=type=cache,target=/go/pkg/mod \ | ||
| --mount=type=cache,target=/root/.cache/go-build \ | ||
| CGO_ENABLED=0 \ | ||
|
Comment on lines
+23
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To ensure cache isolation and prevent cache thrashing in shared CI/CD environments, specify unique |
||
| GOOS=$TARGETOS \ | ||
| GOARCH=$TARGETARCH \ | ||
| go build \ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a specific minor version like
1.7for the Dockerfile syntax directive prevents the build from automatically receiving security updates, bug fixes, and performance improvements. It is highly recommended to use# syntax=docker/dockerfile:1to pin to the major version1, which automatically resolves to the latest stable minor release while maintaining backward compatibility.