build(docker): dockerfile improvements - #1173
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1173 +/- ##
=======================================
Coverage 44.45% 44.45%
=======================================
Files 144 144
Lines 13732 13732
=======================================
Hits 6105 6105
Misses 7054 7054
Partials 573 573 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| RUN go mod tidy | ||
| # Install ca-certificates to ensure TLS verification works | ||
| RUN apk add --no-cache ca-certificates | ||
| RUN mkdir -p /app/tmp/ |
There was a problem hiding this comment.
What is the analysis on the comment for these
Empty directories created but never populated (Low) : Lines 27 and 35 create /app/tmp/ and /.config/device-management-toolkit/ via RUN mkdir, then copy them. Use COPY --from=builder only if the app actually writes to them at runtime. On scratch, pre-created empty dirs are the right approach, but verify the app doesn't expect them at different paths.
There was a problem hiding this comment.
Verified that the app writes TLS certs/temp files to os.TempDir() (ENV TMPDIR=/tmp → tmp) and stores the SQLite DB via os.UserConfigDir() (ENV XDG_CONFIG_HOME=/.config → console.db). Both paths match exactly what's pre-created in the Dockerfile. On scratch, seeding empty dirs via RUN mkdir + COPY --from=builder is the only option since there's no base filesystem, will update the jira accordingly.
|
@DevipriyaS17 This change is related to Docker build configuration, so build(docker): would be a better Conventional Commit type than fix: |
There was a problem hiding this comment.
Pull request overview
This PR improves the project’s Docker build to better support cross-platform builds and faster rebuilds, while fixing missing CA certificates in the final scratch image to enable proper TLS verification.
Changes:
- Installs
ca-certificatesin the builder stage so the final stage’s certificate copy actually includes the bundle. - Switches from a hardcoded
GOARCH=amd64toTARGETARCHfor multi-archdocker buildxbuilds. - Adds BuildKit cache mounts for Go build and module cache paths to speed up iterative builds.
Suppressed comments (1)
Dockerfile:39
GOARCH=$TARGETARCHalone is not sufficient for arm variants; ensureGOARMis set fromTARGETVARIANTwhenTARGETARCH=armsobuildx --platform=linux/arm/v7produces the correct binary.
if [ -n "$BUILD_TAGS" ]; then \
CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH go build -tags="$BUILD_TAGS_GO" -o /bin/app ./cmd/app; \
else \
CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH go build -o /bin/app ./cmd/app; \
fi'
bf4a8a3 to
54eda2a
Compare
Summary
Dockerfile improvements
Changes
DockerfileRUN apk add --no-cache ca-certificatesinbuilder stage. Previously
COPY ca-certificates.crtin the final stage silentlycopied nothing since the package was never installed.
GOARCH=amd64withARG TARGETARCH=amd64to support cross-platform builds via
docker buildx --platform.--mount=type=cachefor/root/.cache/go-buildand/go/pkg/mod/cachefor faster iterative builds.go mod tidy— themodulesstagealready downloads deps; re-running tidy after
COPY . /appinvalidated the cacheon every source change.