Skip to content

Commit ef1048e

Browse files
authored
chore: update testrunner image to use non-root user (#14106)
Updates the testrunner dockerfile to: - Use non-root user - Bonus: collapse some of the install steps so we can reduce the resulting image size (7.27 GB vs 13.4 GB) ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [ ] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
1 parent f9689bf commit ef1048e

File tree

1 file changed

+50
-57
lines changed

1 file changed

+50
-57
lines changed

docker/Dockerfile

Lines changed: 50 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,37 @@
44
FROM debian:bookworm-slim
55

66
ARG TARGETARCH
7-
ARG HATCH_VERSION=1.12.0
7+
ARG HATCH_VERSION=1.14.1
88
ARG RIOT_VERSION=0.20.1
99

1010
# http://bugs.python.org/issue19846
1111
# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK.
12-
ENV LANG C.UTF-8
12+
ENV LANG=C.UTF-8
1313

14-
# https://support.circleci.com/hc/en-us/articles/360045268074-Build-Fails-with-Too-long-with-no-output-exceeded-10m0s-context-deadline-exceeded-
15-
ENV PYTHONUNBUFFERED=1
16-
# Configure PATH environment for pyenv
17-
ENV PYENV_ROOT=/root/.pyenv
18-
ENV CARGO_ROOT=/root/.cargo
19-
ENV PATH=${PYENV_ROOT}/shims:${PYENV_ROOT}/bin:${CARGO_ROOT}/bin:$PATH
20-
ENV PYTHON_CONFIGURE_OPTS=--enable-shared
14+
# Use root user to install dependencies
15+
USER root
2116

22-
WORKDIR /root/
23-
24-
# Use .python-version to specify all Python versions for testing
25-
COPY .python-version /root/
17+
# Create our bits user
18+
RUN useradd -ms /bin/bash bits
2619

2720
# Install system dependencies
2821
RUN apt-get update \
29-
&& apt-get install -y --no-install-recommends \
22+
&& apt-get install -y --no-install-recommends ca-certificates curl gnupg \
23+
&& curl https://mariadb.org/mariadb_release_signing_key.pgp | gpg --dearmor > /etc/apt/trusted.gpg.d/mariadb.gpg \
24+
&& echo "deb [arch=amd64,arm64] https://mirror.mariadb.org/repo/11.rolling/debian/ bookworm main" > /etc/apt/sources.list.d/mariadb.list \
25+
&& apt-get update \
26+
&& apt-get install -y --no-install-recommends \
3027
apt-transport-https \
3128
build-essential \
32-
ca-certificates \
3329
clang-format \
34-
curl \
3530
gdb \
3631
git \
37-
gnupg \
3832
jq \
3933
libbz2-dev \
4034
libffi-dev \
4135
liblzma-dev \
36+
libmariadb-dev \
37+
libmariadb-dev-compat \
4238
libmemcached-dev \
4339
libmemcached-dev \
4440
libncurses5-dev \
@@ -49,61 +45,58 @@ RUN apt-get update \
4945
libsqlite3-dev \
5046
libsqliteodbc \
5147
libssh-dev \
48+
nodejs \
49+
npm \
5250
patch \
5351
unixodbc-dev \
5452
wget \
5553
zlib1g-dev \
56-
awscli
57-
58-
# Allow running datadog-ci in CI with npx
59-
RUN apt-get install -y --no-install-recommends nodejs npm \
60-
&& npm install -g @datadog/datadog-ci
54+
awscli \
55+
# Allow running datadog-ci in CI with npx
56+
&& npm install -g @datadog/datadog-ci \
57+
# Install azure-functions-core-tools-4, only supported on amd64 architecture for Linux
58+
# https://github.com/Azure/azure-functions-core-tools/issues/3112
59+
&& if [ "$TARGETARCH" = "amd64" ]; \
60+
then \
61+
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg \
62+
&& mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg \
63+
&& echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-bookworm-prod bookworm main" > /etc/apt/sources.list.d/dotnetdev.list \
64+
&& apt-get update \
65+
&& apt-get install -y --no-install-recommends azure-functions-core-tools-4=4.0.6280-1; \
66+
fi \
67+
# Google Chrome is needed for selenium contrib tests but is currently only available on amd64
68+
&& if [ "$TARGETARCH" = "amd64" ]; \
69+
then \
70+
curl https://dl.google.com/linux/linux_signing_key.pub |gpg --dearmor > /etc/apt/trusted.gpg.d/google.gpg \
71+
&& echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' > /etc/apt/sources.list.d/google-chrome.list \
72+
&& apt-get update \
73+
&& apt-get install -y --no-install-recommends google-chrome-stable ; \
74+
fi \
75+
# Cleaning up apt cache space
76+
&& rm -rf /var/lib/apt/lists/*
6177

62-
# MariaDB is a dependency for tests
63-
RUN curl https://mariadb.org/mariadb_release_signing_key.pgp | gpg --dearmor > /etc/apt/trusted.gpg.d/mariadb.gpg \
64-
&& echo "deb [arch=amd64,arm64] https://mirror.mariadb.org/repo/11.rolling/debian/ bookworm main" > /etc/apt/sources.list.d/mariadb.list \
65-
&& apt-get update \
66-
&& apt-get install -y --no-install-recommends libmariadb-dev libmariadb-dev-compat
6778

68-
# Install azure-functions-core-tools-4, only supported on amd64 architecture for Linux
69-
# https://github.com/Azure/azure-functions-core-tools/issues/3112
70-
RUN if [ "$TARGETARCH" = "amd64" ]; \
71-
then \
72-
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg \
73-
&& mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg \
74-
&& echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-bookworm-prod bookworm main" > /etc/apt/sources.list.d/dotnetdev.list \
75-
&& apt-get update \
76-
&& apt-get install -y --no-install-recommends azure-functions-core-tools-4=4.0.6280-1; \
77-
fi
79+
USER bits
80+
WORKDIR /home/bits/
7881

79-
# Google Chrome is needed for selenium contrib tests but is currently only available on amd64
80-
RUN if [ "$TARGETARCH" = "amd64" ]; \
81-
then \
82-
curl https://dl.google.com/linux/linux_signing_key.pub |gpg --dearmor > /etc/apt/trusted.gpg.d/google.gpg \
83-
&& echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' > /etc/apt/sources.list.d/google-chrome.list \
84-
&& apt-get update \
85-
&& apt-get install -y --no-install-recommends google-chrome-stable ; \
86-
fi
87-
88-
# Cleaning up apt cache space
89-
RUN rm -rf /var/lib/apt/lists/*
82+
ENV PYTHONUNBUFFERED=1
83+
ENV PYENV_ROOT=/home/bits/.pyenv
84+
ENV CARGO_ROOT=/home/bits/.cargo
85+
ENV PATH=/home/bits/.local/bin:${PYENV_ROOT}/shims:${PYENV_ROOT}/bin:${CARGO_ROOT}/bin:$PATH
86+
ENV PYTHON_CONFIGURE_OPTS=--enable-shared
9087

9188
# Install Rust toolchain
9289
RUN curl https://sh.rustup.rs -sSf | \
9390
sh -s -- --default-toolchain stable -y
9491

92+
# Use .python-version to specify all Python versions for testing
93+
COPY .python-version /home/bits/
94+
9595
# Install pyenv and necessary Python versions
96-
RUN git clone --depth 1 --branch v2.4.22 https://github.com/pyenv/pyenv "${PYENV_ROOT}" \
96+
RUN git clone --depth 1 --branch "v2.6.4" https://github.com/pyenv/pyenv "${PYENV_ROOT}" \
9797
&& pyenv local | xargs -L 1 pyenv install \
9898
&& cd -
9999

100-
RUN if [ "$TARGETARCH" = "amd64" ]; \
101-
then curl -L https://github.com/pypa/hatch/releases/download/hatch-v${HATCH_VERSION}/hatch-x86_64-unknown-linux-gnu.tar.gz | tar zx; \
102-
else curl -L https://github.com/pypa/hatch/releases/download/hatch-v${HATCH_VERSION}/hatch-aarch64-unknown-linux-gnu.tar.gz | tar zx; \
103-
fi \
104-
&& install -t /usr/local/bin hatch \
105-
&& hatch -q
106-
107-
RUN pip install --no-cache-dir -U "riot==${RIOT_VERSION}"
100+
RUN pip install --no-cache-dir -U "riot==${RIOT_VERSION}" "hatch==${HATCH_VERSION}"
108101

109102
CMD ["/bin/bash"]

0 commit comments

Comments
 (0)