Skip to content

Commit e3e3a11

Browse files
authored
Miscellaneous cleanup. (#16)
* Improve handling of temporary files. - Verify /tmp is empty before setup runs. - Remove leftover files in /tmp after setup completes. - Do not delete setup file since it's persisted in a layer. * Purge /var/lib/apt/lists/* after second install. * Use deadsnakes GPG key in repo. This avoids the use of pipes and the deprecated apt-key utility. * Remove update.txt marker. This file is no longer needed since containmint builds are not cached. * Disable writing Python bytecode during setup. This will reduce container image size, while having negligible impact on setup times.
1 parent 3e1c7ed commit e3e3a11

File tree

6 files changed

+18
-12
lines changed

6 files changed

+18
-12
lines changed

Dockerfile

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
FROM quay.io/bedrock/ubuntu:focal-20220801
22

3-
# increment the number in this file to force a full container rebuild
4-
COPY files/update.txt /dev/null
5-
63
VOLUME /sys/fs/cgroup /run/lock /run /tmp
74

85
RUN apt-get update -y && \
@@ -38,9 +35,7 @@ RUN apt-get update -y && \
3835
apt-get clean && \
3936
rm -rf /var/lib/apt/lists/*
4037

41-
# podman build fails with 'apt-key adv ...' but this works for both
42-
RUN curl -sL "http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xF23C5A6CF475977595C89F51BA6932366A755776" | apt-key add
43-
38+
COPY files/deadsnakes.gpg /etc/apt/keyrings/deadsnakes.gpg
4439
COPY files/deadsnakes.list /etc/apt/sources.list.d/deadsnakes.list
4540

4641
# Install Python versions available from the deadsnakes PPA.
@@ -61,7 +56,8 @@ RUN apt-get update -y && \
6156
python3.11-distutils \
6257
python3.11-venv \
6358
&& \
64-
apt-get clean
59+
apt-get clean && \
60+
rm -rf /var/lib/apt/lists/*
6561

6662
RUN rm /etc/apt/apt.conf.d/docker-clean && \
6763
ln -s python2.7 /usr/bin/python2 && \
@@ -89,7 +85,7 @@ CMD ["/sbin/init"]
8985

9086
# Install pip last to speed up local container rebuilds.
9187
COPY files/*.py /usr/share/container-setup/
92-
RUN python3.10 /usr/share/container-setup/setup.py && rm /usr/share/container-setup/setup.py
88+
RUN python3.10 -B /usr/share/container-setup/setup.py
9389

9490
# Make sure the pip entry points in /usr/bin are correct.
9591
RUN rm -f /usr/bin/pip2 && cp -av /usr/local/bin/pip2 /usr/bin/pip2 && /usr/bin/pip2 -V && \

files/deadsnakes.gpg

1.1 KB
Binary file not shown.

files/deadsnakes.list

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
deb http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal main
2-
deb-src http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal main
1+
deb [signed-by=/etc/apt/keyrings/deadsnakes.gpg] http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal main
2+
deb-src [signed-by=/etc/apt/keyrings/deadsnakes.gpg] http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal main

files/installer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def __init__(self, python: Python) -> None:
8383

8484
directory = os.path.dirname(os.path.abspath(__file__))
8585

86-
self._pip_command = [python.path, os.path.join(directory, 'quiet_pip.py')]
86+
self._pip_command = [python.path, '-B', os.path.join(directory, 'quiet_pip.py')]
8787
self._get_pip_path = f'/tmp/get_pip_{self.version.replace(".", "_")}.py'
8888

8989
def have_get_pip(self) -> bool:

files/setup.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""Find installed Python interpreters and install pip in each one."""
22
from __future__ import annotations
33

4+
import pathlib
5+
46
from installer import (
57
Pip,
68
Python,
@@ -11,9 +13,18 @@
1113

1214
def main() -> None:
1315
"""Main entry point."""
16+
tmp = pathlib.Path('/tmp')
17+
18+
if unexpected := list(tmp.iterdir()):
19+
raise Exception(f'Unexpected temporary files: {unexpected}')
20+
1421
for python in iterate_pythons():
1522
setup_python(python)
1623

24+
for path in tmp.iterdir():
25+
display.info(f'Removing temporary file: {path}')
26+
path.unlink()
27+
1728

1829
def setup_python(python: Python) -> None:
1930
"""Setup the specified Python interpreter."""

files/update.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)