Skip to content

Commit dc559b8

Browse files
committed
add chown to COPY commands to reduce layer count
1 parent 80b91eb commit dc559b8

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

repo2docker/buildpacks/base.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
{% if build_script_files -%}
101101
# If scripts required during build are present, copy them
102102
{% for src, dst in build_script_files|dictsort %}
103-
COPY {{ src }} {{ dst }}
103+
COPY --chown=${NB_USER}:${NB_USER} {{ src }} {{ dst }}
104104
{% endfor -%}
105105
{% endif -%}
106106
@@ -137,24 +137,16 @@
137137
{% if preassemble_script_files -%}
138138
# If scripts required during build are present, copy them
139139
{% for src, dst in preassemble_script_files|dictsort %}
140-
COPY src/{{ src }} ${REPO_DIR}/{{ dst }}
140+
COPY --chown=${NB_USER}:${NB_USER} src/{{ src }} ${REPO_DIR}/{{ dst }}
141141
{% endfor -%}
142142
{% endif -%}
143143
144-
{% if preassemble_script_directives -%}
145-
USER root
146-
RUN chown -R ${NB_USER}:${NB_USER} ${REPO_DIR}
147-
{% endif -%}
148-
149144
{% for sd in preassemble_script_directives -%}
150145
{{ sd }}
151146
{% endfor %}
152147
153-
# Copy and chown stuff. This doubles the size of the repo, because
154-
# you can't actually copy as USER, only as root! Thanks, Docker!
155-
USER root
156-
COPY src/ ${REPO_DIR}
157-
RUN chown -R ${NB_USER}:${NB_USER} ${REPO_DIR}
148+
# Copy stuff.
149+
COPY --chown=${NB_USER}:${NB_USER} src/ ${REPO_DIR}
158150
159151
# Run assemble scripts! These will actually turn the specification
160152
# in the repository into an image.

0 commit comments

Comments
 (0)