-
Notifications
You must be signed in to change notification settings - Fork 91
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}" | ||||||||||||||
|
Contributor
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. I think this
Member
Author
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. For readability, would it be better to keep them on separate lines?
Contributor
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. I think this is fine from readability side. Appending two elements to a list is not hard to understand. |
||||||||||||||
| 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" | ||||||||||||||
|
Contributor
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. ENV consolidation contradicts prior agreement to keep lines split. Lines 21-23 consolidate PATH and related settings into a multi-line ENV statement. However, based on learnings from PR #1414 and the prior agreement in PR #1166, ENV directives should remain split into separate lines for readability, especially since later ENV settings depend on earlier ones (e.g., Apply this diff to split the ENV statements: ENV CLP_HOME="/opt/clp"
ENV PATH="${CLP_HOME}/bin:${PATH}"
-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"📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Member
Author
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. we now only split if consolidation into the same command is not possible
Contributor
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. @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:
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
🧠 Learnings used |
||||||||||||||
|
|
||||||||||||||
| USER 1000:1000 | ||||||||||||||
| COPY --link ./build/clp-package ${CLP_HOME} | ||||||||||||||
|
|
||||||||||||||
| COPY --link ./build/clp-package /opt/clp | ||||||||||||||
|
|
||||||||||||||
| # Flatten the image | ||||||||||||||
| FROM scratch | ||||||||||||||
| COPY --link --from=base / / | ||||||||||||||
| RUN useradd --uid 1000 --shell /bin/bash --home-dir ${CLP_HOME} ${USER} | ||||||||||||||
| USER ${USER} | ||||||||||||||
| WORKDIR ${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"