|
1 | | -# SPDX-FileCopyrightText: Copyright 2020-2025 Arm Limited and affiliates. |
| 1 | +# SPDX-FileCopyrightText: Copyright 2020-2026 Arm Limited and affiliates. |
2 | 2 | # |
3 | 3 | # SPDX-License-Identifier: Apache-2.0 |
4 | 4 |
|
5 | 5 | # Specify DOCKER_IMAGE_MIRROR if you want to use a mirror of hub.docker.com |
| 6 | +ARG BASE_IMAGE=python:3.12-slim |
6 | 7 | ARG DOCKER_IMAGE_MIRROR="" |
7 | | -FROM ${DOCKER_IMAGE_MIRROR}ubuntu:24.04 AS workshop |
8 | 8 |
|
9 | | -ARG USERNAME |
| 9 | +# ============================ |
| 10 | +# Workshop |
| 11 | +# ============================ |
| 12 | +FROM ${DOCKER_IMAGE_MIRROR}${BASE_IMAGE} AS workshop |
10 | 13 |
|
11 | 14 | ARG TENSORFLOW_WHEEL |
12 | | -ENV TENSORFLOW_WHEEL=$TENSORFLOW_WHEEL |
13 | | - |
14 | | -RUN if ! [ "$(arch)" = "aarch64" ] ; then exit 1; fi |
15 | | - |
16 | | -RUN apt-get update && apt-get install -y \ |
17 | | - # We need pip to install things, this will also bring in a minimal python3 |
18 | | - python3-pip \ |
19 | | - # So that we can create a virtual environment |
20 | | - python3-venv \ |
21 | | - # So that we can call python instead of python3 |
22 | | - python-is-python3 \ |
23 | | - # To allow users to install new things if they want |
24 | | - sudo \ |
25 | | - # Git |
26 | | - git \ |
27 | | - && rm -rf /var/lib/apt/lists/* |
28 | | -RUN apt-get update |
29 | | -RUN apt-get install -y protobuf-compiler |
30 | | -RUN apt-get install -y wget |
31 | | - |
32 | | -# DOCKER_USER for the Docker user |
33 | | -ENV DOCKER_USER=${USERNAME} |
34 | | - |
35 | | -# Create user only if it doesn't already exist |
36 | | -RUN id "$DOCKER_USER" >/dev/null 2>&1 || useradd --create-home -s /bin/bash -m "$DOCKER_USER" |
37 | | - |
38 | | -# Set password and add to sudo group |
39 | | -RUN echo "$DOCKER_USER:ToolSolutionsTensorFlow" | chpasswd && adduser "$DOCKER_USER" sudo || true |
40 | | - |
41 | | -RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers |
42 | | -RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections |
43 | | - |
44 | | -# Import profile for bash |
45 | | -COPY bash_profile /home/$DOCKER_USER/.bash_profile |
46 | | -RUN chown $DOCKER_USER:$DOCKER_USER /home/$DOCKER_USER/.bash_profile |
47 | | - |
48 | | -# Add welcome message to warn about dev quality |
49 | | -COPY welcome.txt /home/$DOCKER_USER/ |
50 | | -RUN echo '[ ! -z "$TERM" -a -r /home/$DOCKER_USER/welcome.txt ] && cat /home/$DOCKER_USER/welcome.txt' >> /etc/bash.bashrc |
51 | | -RUN echo 'export PATH="$HOME/.local/bin:$PATH"' >> /etc/bash.bashrc |
52 | | - |
53 | | -# Grab the SECURITY.md from the root directory |
54 | | -COPY --from=rootdir SECURITY.md /home/$DOCKER_USER/ |
55 | | - |
56 | | -# Remove system Python stuff. Should be safe to wipe after the line above, because |
57 | | -# python3 -m pip now uses the /usr/local install. Also removes unused protobuf |
58 | | -# packages to resolve CVE-2025-4565. |
59 | | -RUN apt-get update && apt-get purge -y \ |
60 | | - python3-pip \ |
61 | | - python3-setuptools \ |
62 | | - python3-pkg-resources \ |
63 | | - python3-wheel \ |
64 | | - python3-distutils \ |
65 | | - python3-lib2to3 \ |
66 | | - python3-dev \ |
67 | | - python3.12-dev \ |
68 | | - libprotobuf32t64 \ |
69 | | - libprotobuf-lite32t64 \ |
70 | | - libprotoc32t64 \ |
71 | | - protobuf-compiler \ |
72 | | - && apt-get autoremove -y \ |
73 | | - && rm -rf /var/lib/apt/lists/* |
74 | | - |
75 | | -# Move to userland |
76 | | -WORKDIR /home/$DOCKER_USER |
| 15 | + |
| 16 | +ENV DEBIAN_FRONTEND=noninteractive |
| 17 | +ENV DOCKER_USER=debian |
| 18 | + |
| 19 | +RUN test "$(arch)" = "aarch64" |
| 20 | + |
| 21 | +# Install OS dependencies |
| 22 | +RUN apt-get update && \ |
| 23 | + apt-get install -y --no-install-recommends protobuf-compiler wget && \ |
| 24 | + rm -rf /var/lib/apt/lists/* |
| 25 | + |
| 26 | +# Create user |
| 27 | +RUN set -eux && id "$DOCKER_USER" >/dev/null 2>&1 || useradd --create-home -s /bin/bash "$DOCKER_USER" |
| 28 | + |
| 29 | +# Copy bash profile and welcome text into user home |
| 30 | +COPY --chown=$DOCKER_USER:$DOCKER_USER bash_profile /home/$DOCKER_USER/.bash_profile |
| 31 | +COPY --chown=$DOCKER_USER:$DOCKER_USER welcome.txt /home/$DOCKER_USER/welcome.txt |
| 32 | + |
| 33 | +# Switch to userland |
77 | 34 | USER $DOCKER_USER |
| 35 | +WORKDIR /home/$DOCKER_USER |
| 36 | + |
| 37 | +# Add ~/.local/bin to PATH to use uv later |
| 38 | +ENV PATH="/home/$DOCKER_USER/.local/bin:${PATH}" |
78 | 39 |
|
79 | | -# Create a per-user virtualenv and use that for everything Python |
80 | | -RUN python -m venv /home/$DOCKER_USER/.venv |
| 40 | +# Install uv for quicker package installations (installed to ~/.local/bin with --user) |
| 41 | +RUN python -m pip install --user uv==0.9.29 |
81 | 42 |
|
82 | | -# Make the venv python/pip first on PATH for all subsequent layers and at runtime |
83 | | -ENV PATH="/home/$DOCKER_USER/.venv/bin:$PATH" |
| 43 | +# Create virtual environment with uv |
| 44 | +RUN uv venv /home/$DOCKER_USER/.venv |
| 45 | +ENV PATH="/home/$DOCKER_USER/.venv/bin:${PATH}" |
84 | 46 |
|
85 | | -# Update to newer pip/setuptools/wheel (setuptools >= 70.0.0 due to CVE-2024-6345 |
86 | | -# and CVE-2025-47273, wheel >= 0.38.0 due to CVE-2022-40898) and delete old system |
87 | | -# version (we essentially use apt:python3-pip to bootstrap pip) |
88 | | -RUN pip install --upgrade pip~=25.2 setuptools~=78.1.1 wheel~=0.45.1 |
| 47 | +# Remove pip and update to newer setuptools/wheel (setuptools >= 70.0.0 due to CVE-2024-6345 |
| 48 | +# and CVE-2025-47273, wheel >= 0.38.0 due to CVE-2022-40898) |
| 49 | +RUN uv pip uninstall pip && uv pip install --upgrade setuptools~=78.1.1 wheel~=0.45.1 |
89 | 50 |
|
90 | | -# Check TENSORFLOW_WHEEL was set and copy |
91 | | -RUN test -n "$TENSORFLOW_WHEEL" |
92 | | -COPY $TENSORFLOW_WHEEL /home/$DOCKER_USER/ |
| 51 | +# Install non-TensorFlow requirements |
| 52 | +COPY --chown=$DOCKER_USER:$DOCKER_USER requirements.txt . |
| 53 | +RUN uv pip install -r requirements.txt --no-deps |
93 | 54 |
|
94 | | -# Install our dev build of TensorFlow. |
95 | | -RUN pip install "$(basename "$TENSORFLOW_WHEEL")" \ |
96 | | - && rm "$(basename "$TENSORFLOW_WHEEL")" |
| 55 | +# Bring wheels into image |
| 56 | +RUN test -n "${TENSORFLOW_WHEEL}" |
| 57 | +COPY --chown=$DOCKER_USER:$DOCKER_USER ${TENSORFLOW_WHEEL} /home/$DOCKER_USER/ |
97 | 58 |
|
98 | | -# Base requirements for examples, excluding TensorFlow |
99 | | -COPY requirements.txt ./ |
100 | | -RUN pip install -r requirements.txt --no-deps |
| 59 | +# Install wheel |
| 60 | +RUN set -eux && uv pip install "$(basename "$TENSORFLOW_WHEEL")" && rm "$(basename "$TENSORFLOW_WHEEL")" |
101 | 61 |
|
102 | | -# Setup Examples and tests |
103 | | -COPY --chown=$DOCKER_USER examples/ /home/$DOCKER_USER/ |
104 | | -COPY --chown=$DOCKER_USER tensorflow/ /home/$DOCKER_USER/tensorflow |
| 62 | +# Copy examples/tests into image |
| 63 | +COPY --chown=$DOCKER_USER:$DOCKER_USER examples/ /home/$DOCKER_USER/ |
| 64 | +COPY --chown=$DOCKER_USER:$DOCKER_USER tensorflow/ /home/$DOCKER_USER/tensorflow |
105 | 65 |
|
106 | | -# Move build into final image as a single layer. |
107 | | -FROM ${DOCKER_IMAGE_MIRROR}ubuntu:24.04 |
| 66 | +# ============================ |
| 67 | +# Final flat image |
| 68 | +# ============================ |
| 69 | +FROM ${DOCKER_IMAGE_MIRROR}${BASE_IMAGE} |
108 | 70 |
|
109 | | -ARG USERNAME |
| 71 | +ENV DEBIAN_FRONTEND=noninteractive |
| 72 | +ENV DOCKER_USER=debian |
110 | 73 |
|
111 | | -ENV DOCKER_USER=${USERNAME} |
| 74 | +# Runtime OS bits + UI |
| 75 | +RUN set -eux && \ |
| 76 | + if ! id "$DOCKER_USER" >/dev/null 2>&1; then useradd --create-home -s /bin/bash "$DOCKER_USER"; fi && \ |
| 77 | + echo '[ -n "$TERM" -a -r "$HOME/welcome.txt" ] && cat "$HOME/welcome.txt"' >> /etc/bash.bashrc && \ |
| 78 | + echo 'export PATH="$HOME/.local/bin:$HOME/.venv/bin:$PATH"' >> /etc/bash.bashrc && \ |
| 79 | + python3 -m pip uninstall -y pip |
112 | 80 |
|
113 | | -COPY --from=workshop / / |
114 | | -RUN chown $DOCKER_USER:$DOCKER_USER /home/$DOCKER_USER |
| 81 | +# Bring in prepped env + code |
| 82 | +COPY --from=workshop --chown=$DOCKER_USER:$DOCKER_USER /home/$DOCKER_USER /home/$DOCKER_USER |
115 | 83 |
|
116 | 84 | USER $DOCKER_USER |
117 | 85 | WORKDIR /home/$DOCKER_USER |
118 | 86 |
|
119 | | -# Ensure the venv is on PATH in the final image as well |
120 | | -ENV PATH="/home/$DOCKER_USER/.venv/bin:$PATH" |
| 87 | +ENV PATH="/home/$DOCKER_USER/.local/bin:/home/$DOCKER_USER/.venv/bin:$PATH" |
121 | 88 |
|
122 | 89 | CMD ["bash", "-l"] |
0 commit comments