Skip to content

fix: Dockerfile standalone#5797

Merged
moolen merged 1 commit intomainfrom
gc-fix-dockerfile-standalong
Jan 5, 2026
Merged

fix: Dockerfile standalone#5797
moolen merged 1 commit intomainfrom
gc-fix-dockerfile-standalong

Conversation

@gusfcarvalho
Copy link
Copy Markdown
Member

@gusfcarvalho gusfcarvalho commented Jan 5, 2026

Dockerfile.standalone Changes

Modified the builder stage's dependency handling:

  • Removed the comment about preserving go mod download cache
  • Removed the selective COPY of go.mod and go.sum before dependency download
  • Changed to copy the entire application context first (COPY . /app/), then execute RUN go mod download
  • Removed extra whitespace for tighter formatting

This simplifies the build process but removes a caching optimization that previously prevented cache invalidation when only source code changed.

Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com>
@github-actions github-actions bot added kind/bug Categorizes issue or PR as related to a bug. size/xs labels Jan 5, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 5, 2026

Walkthrough

The Dockerfile.standalone builder stage was restructured by moving the go mod download command to execute after copying the application context. A cache invalidation comment was removed, and formatting was tightened by eliminating an extra blank line.

Changes

Cohort / File(s) Summary
Docker Build Configuration
Dockerfile.standalone
Reordered build step: go mod download now executes after COPY . /app/ instead of before. Removed cache invalidation comment. Removed extraneous blank line before next stage.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Jan 5, 2026

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Fix all issues with AI Agents 🤖
In @Dockerfile.standalone:
- Around line 11-12: The Dockerfile currently runs "RUN go mod download" after
"COPY . /app/", which invalidates layer caching; change the Dockerfile to first
COPY only dependency files (COPY go.mod go.sum ./), run "go mod download" to
cache module downloads, and then COPY the rest of the application source (e.g.,
COPY . /app/) so that modifying app code won't re-run the module download step.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 15aeab3 and 2f9fb17.

📒 Files selected for processing (1)
  • Dockerfile.standalone
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: publish-artifacts (Dockerfile.ubi, CGO_ENABLED=0 GOEXPERIMENT=boringcrypto, amd64 ppc64le, linux/... / Build and Publish
  • GitHub Check: publish-artifacts (Dockerfile, CGO_ENABLED=0, amd64 arm64 s390x ppc64le, linux/amd64,linux/arm64,... / Build and Publish
  • GitHub Check: publish-artifacts (Dockerfile.ubi, CGO_ENABLED=0, amd64 arm64 ppc64le, linux/amd64,linux/arm64,li... / Build and Publish
  • GitHub Check: unit-tests
  • GitHub Check: check-diff
  • GitHub Check: Analyze project (actions, none)
  • GitHub Check: Analyze project (go, autobuild)
  • GitHub Check: integration-trusted

Comment on lines 11 to +12
COPY . /app/
RUN go mod download
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Docker layer caching is broken by this change.

Moving go mod download after COPY . /app/ breaks Docker's layer caching optimization. Now, any application code change invalidates the COPY layer, forcing dependencies to re-download on every build even when go.mod/go.sum haven't changed.

Best practice: copy only dependency files first, download modules, then copy the rest of the code.

🔎 Proposed fix to restore layer caching
 WORKDIR /app
-COPY . /app/
+COPY go.mod go.sum /app/
 RUN go mod download
+COPY . /app/
 RUN go build -o external-secrets main.go

This ensures go mod download is cached unless go.mod or go.sum changes, dramatically speeding up builds when only application code is modified.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
COPY . /app/
RUN go mod download
WORKDIR /app
COPY go.mod go.sum /app/
RUN go mod download
COPY . /app/
RUN go build -o external-secrets main.go
🤖 Prompt for AI Agents
In @Dockerfile.standalone around lines 11-12, The Dockerfile currently runs "RUN
go mod download" after "COPY . /app/", which invalidates layer caching; change
the Dockerfile to first COPY only dependency files (COPY go.mod go.sum ./), run
"go mod download" to cache module downloads, and then COPY the rest of the
application source (e.g., COPY . /app/) so that modifying app code won't re-run
the module download step.

@moolen moolen merged commit 7b160ce into main Jan 5, 2026
32 checks passed
@moolen moolen deleted the gc-fix-dockerfile-standalong branch January 5, 2026 17:05
@coderabbitai coderabbitai bot mentioned this pull request Mar 13, 2026
5 tasks
dsp0x4 pushed a commit to dsp0x4/external-secrets that referenced this pull request Mar 22, 2026
Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug. size/xs

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants