Skip to content

Commit 8e5c00b

Browse files
committed
Improve execution of pip during container building
- Make pip less verbose as this makes harder to investigate container building due to being too verbose. - Use a bind mount to prevent pip cache from being written inside the container but still make use of it. This will speed-up the build process considerably.
1 parent 16a5dce commit 8e5c00b

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/ansible_builder/containerfile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ def prepare(self) -> None:
9494
self.steps.append('RUN /output/scripts/pip_install $PYCMD')
9595

9696
if self.definition.ansible_ref_install_list:
97-
self.steps.append('RUN $PYCMD -m pip install --no-cache-dir $ANSIBLE_INSTALL_REFS')
97+
self.steps.append(
98+
'RUN --mount=type=cache,dst=/root/.cache/pip $PYCMD -m pip install -q $ANSIBLE_INSTALL_REFS')
9899

99100
self._insert_custom_steps('append_base')
100101

test/unit/test_containerfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def test_v3_various(build_dir_and_ee_yml):
184184
assert "RUN $PYCMD -m pip install --no-cache-dir 'dumb-init==x.y.z'" in c.steps
185185
assert "USER myuser" in c.steps
186186
assert "RUN $PKGMGR install $PYPKG -y ; if [ -z $PKGMGR_PRESERVE_CACHE ]; then $PKGMGR clean all; fi" in c.steps
187-
assert "RUN $PYCMD -m pip install --no-cache-dir $ANSIBLE_INSTALL_REFS" in c.steps
187+
assert "RUN --mount=type=cache,dst=/root/.cache/pip $PYCMD -m pip install -q $ANSIBLE_INSTALL_REFS" in c.steps
188188
assert 'ENTRYPOINT ["dumb-init"]' in c.steps
189189
assert 'CMD ["csh"]' in c.steps
190190

0 commit comments

Comments
 (0)