-
Notifications
You must be signed in to change notification settings - Fork 83
feat(docker): Create non-root clp-user; Move USER and ENV directives after flattening (fixes #1379); Reduce layers using multi-line ENV (fixes #1378).
#1413
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 9 commits
7d18129
b193c2f
3195ef0
18a1b18
3ef8714
1b2d4cb
78a7af3
b3e673f
65f2d1b
b522212
dba99b7
360cac6
913dea3
8a991cc
89f0a1c
2967a64
1139cbf
d82b984
d39ab50
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 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,15 +12,18 @@ RUN ./setup-scripts/install-prebuilt-packages.sh \ | |||||||||||||
| RUN apt-get clean \ | ||||||||||||||
| && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | ||||||||||||||
|
|
||||||||||||||
| # Flatten the image | ||||||||||||||
| FROM scratch | ||||||||||||||
| COPY --link --from=base / / | ||||||||||||||
|
|
||||||||||||||
| ENV CLP_HOME="/opt/clp" | ||||||||||||||
| ENV PATH="${CLP_HOME}/bin:${PATH}" | ||||||||||||||
|
||||||||||||||
| ENV PATH="${CLP_HOME}/sbin:${PATH}" | ||||||||||||||
| ENV PYTHONPATH="${CLP_HOME}/lib/python3/site-packages" | ||||||||||||||
| ENV PATH="${CLP_HOME}/sbin:${PATH}" \ | ||||||||||||||
| PYTHONPATH="${CLP_HOME}/lib/python3/site-packages" \ | ||||||||||||||
| USER="clp-user" | ||||||||||||||
|
||||||||||||||
| ENV PATH="${CLP_HOME}/sbin:${PATH}" \ | |
| PYTHONPATH="${CLP_HOME}/lib/python3/site-packages" \ | |
| USER="clp-user" | |
| ENV PATH="${CLP_HOME}/sbin:${PATH}" | |
| ENV PYTHONPATH="${CLP_HOME}/lib/python3/site-packages" | |
| ENV USER="clp-user" |
🤖 Prompt for AI Agents
In tools/docker-images/clp-package/Dockerfile around lines 21 to 23, the ENV
entries were combined into a single multi-line ENV which contradicts the agreed
style and can break dependent expansions; revert to separate ENV directives so
each variable is set on its own line (e.g., one ENV for PATH, one for
PYTHONPATH, one for USER) ensuring later variables can safely reference CLP_HOME
and improving readability.
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.
we now only split if consolidation into the same command is not possible
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.
@junhaoliao, thank you for the clarification! I understand now that the policy has been updated: ENV directives should be consolidated into multi-line statements when possible, and only split when dependencies between variables require separate commands.
The current implementation is correct under this updated guidance:
- Line 19:
ENV CLP_HOME="/opt/clp"— separate because it's referenced by subsequent ENVs - Line 20:
ENV PATH="${CLP_HOME}/bin:${PATH}"— separate because PATH must be modified in sequence - Lines 21-23: Consolidated multi-line ENV for the second PATH modification, PYTHONPATH, and USER — correct since these can all be set together
I apologize for the confusion caused by my earlier comment based on the outdated policy from PR #1166. The consolidation here properly addresses issue #1378 (reducing layers) while maintaining correct dependency order.
✏️ Learnings added
Learnt from: junhaoliao
PR: y-scope/clp#1413
File: tools/docker-images/clp-package/Dockerfile:22-24
Timestamp: 2025-10-20T21:05:30.383Z
Learning: In the clp repository's Dockerfiles, ENV directives should be consolidated into multi-line ENV statements when possible to reduce image layers. ENV statements should only be split into separate commands when consolidation is not possible due to dependencies (e.g., when later variables must reference earlier ones that need to be set first, or when PATH must be modified sequentially).
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
🧠 Learnings used
Learnt from: junhaoliao
PR: y-scope/clp#1414
File: tools/docker-images/clp-package/Dockerfile:20-24
Timestamp: 2025-10-13T03:32:19.293Z
Learning: In the clp repository's Dockerfiles (e.g., tools/docker-images/clp-package/Dockerfile), ENV directives should be split into separate lines for readability rather than consolidated to reduce layer count. This is especially true for PATH modifications, as agreed upon in PR #1166. Later ENV settings may depend on earlier ones (e.g., referencing CLP_HOME).
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.
To fix #1410, we need to "Move USER and ENV directives after image flattening in clp-package Dockerfile"