build(docker): suppress hadolint warnings and add cache flag#491
build(docker): suppress hadolint warnings and add cache flag#491liam-icheng-lai wants to merge 1 commit intomainfrom
Conversation
🔐 Commit Signature Verification✅ All 1 commit(s) passed verification
Summary
Required key type: Last verified: 2026-03-30 17:54 UTC |
Greptile SummaryThis PR makes two targeted improvements to the multi-stage Dockerfile: it suppresses hadolint DL3018 (unpinned Key findings:
Confidence Score: 4/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["FROM golang:1.24.11-alpine\nAS builder"] --> B["ARG VERSION='HEAD'\n⚠️ scoped to builder only"]
B --> C["RUN apk add --no-cache ...\n# hadolint ignore=DL3018 ✅ NEW"]
C --> D["COPY go.mod go.sum"]
D --> E["COPY ./"]
E --> F["RUN make build"]
F --> G["binary: build/staking-api-service"]
H["FROM alpine:3.16\nAS run"] --> I["RUN addgroup + adduser"]
I --> J["RUN apk add --no-cache bash curl jq\n# hadolint ignore=DL3018 ✅ FIXED"]
J --> K["LABEL source=...VERSION\n⚠️ VERSION is empty here"]
K --> L["COPY --from=builder binary"]
L --> M["COPY --from=builder entrypoint.sh"]
M --> N["USER staking-api-service"]
N --> O["ENTRYPOINT entrypoint.sh"]
G -.->|"multi-stage copy"| L
Reviews (1): Last reviewed commit: "build(docker): suppress hadolint warning..." | Re-trigger Greptile |
| RUN apk add --no-cache bash curl jq | ||
|
|
||
| # Label should match your github repo | ||
| LABEL org.opencontainers.image.source="https://github.com/babylonlabs-io/staking-api-service:${VERSION}" |
There was a problem hiding this comment.
ARG VERSION out of scope in final stage
In Docker multi-stage builds, ARG declarations are scoped to the build stage in which they are defined. ARG VERSION="HEAD" is declared in the builder stage (line 3), so ${VERSION} in this LABEL instruction (which is in the run stage) will always expand to an empty string — the version tag will never appear correctly in the image label.
To fix this, ARG VERSION needs to be re-declared in the run stage:
| LABEL org.opencontainers.image.source="https://github.com/babylonlabs-io/staking-api-service:${VERSION}" | |
| ARG VERSION="HEAD" | |
| LABEL org.opencontainers.image.source="https://github.com/babylonlabs-io/staking-api-service:${VERSION}" |
The re-declaration does not need a default value if it is always passed via --build-arg VERSION=..., but including "HEAD" as the default is a safe fallback consistent with the current intent.
| # hadolint ignore=DL3018 | ||
| RUN apk add --no-cache bash curl jq |
There was a problem hiding this comment.
Suppressing version-pinning warning rather than pinning versions
The # hadolint ignore=DL3018 comment suppresses the hadolint warning about unpinned apk package versions rather than fixing the underlying issue. Without pinned versions (e.g. bash=5.2.21-r0), builds are not fully reproducible — a new package release could silently change the image contents between builds.
This applies to both the builder stage (line 5–6) and this run stage. If reproducibility is not a concern here, the suppression is reasonable, but it's worth documenting the rationale in a comment (e.g. # pinning not required; latest stable is acceptable).
|
|
||
| ARG VERSION="HEAD" | ||
|
|
||
| # hadolint ignore=DL3018 |
There was a problem hiding this comment.
https://github.com/hadolint/hadolint/wiki/DL3018
We need to hardcode the package version
FROM alpine:3.7
RUN apk --no-cache add foo=~1.2.3
There was a problem hiding this comment.
actually, let me get consensus from devops team
This improves Dockerfile linting compliance while maintaining build efficiency by preventing package index caching.