Skip to content

Commit cdc0949

Browse files
committed
Isolate tools into individual environments with pipx
1 parent dc662e0 commit cdc0949

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

.devcontainer/Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ FROM ghcr.io/newrelic/newrelic-python-agent-ci:${IMAGE_TAG}
44

55
# Setup non-root user
66
USER root
7-
ARG UID=1000
7+
ARG UID=1001
88
ARG GID=${UID}
9-
ENV HOME /home/vscode
9+
ENV HOME=/home/vscode
1010
RUN mkdir -p ${HOME} && \
1111
groupadd --gid ${GID} vscode && \
1212
useradd --uid ${UID} --gid ${GID} --home ${HOME} vscode && \
1313
chown -R ${UID}:${GID} /home/vscode
1414

1515
# Fix pyenv installation
1616
RUN echo 'eval "$(pyenv init -)"' >>${HOME}/.bashrc && \
17-
chown -R vscode:vscode ${PYENV_ROOT}
17+
chown -R vscode:vscode "${PYENV_ROOT}" && \
18+
chown -R vscode:vscode "${PIPX_HOME}"
1819

1920
# Set user
2021
USER ${UID}:${GID}

.github/containers/Dockerfile

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ RUN ln -fs "/usr/share/zoneinfo/${TZ}" /etc/localtime && \
8484
dpkg-reconfigure -f noninteractive tzdata
8585

8686
# Use root user
87-
ENV HOME /root
87+
ENV HOME=/root
8888
WORKDIR "${HOME}"
8989

9090
# Install pyenv
@@ -96,11 +96,22 @@ RUN echo 'eval "$(pyenv init -)"' >>${HOME}/.bashrc && \
9696

9797
# Install Python
9898
ARG PYTHON_VERSIONS="3.12 3.11 3.10 3.9 3.8 3.7 3.13 pypy3.10-7.3.17"
99-
COPY --chown=1000:1000 --chmod=755 ./install-python.sh /tmp/install-python.sh
99+
COPY --chown=0:0 --chmod=755 ./install-python.sh /tmp/install-python.sh
100100
RUN /tmp/install-python.sh && \
101101
rm /tmp/install-python.sh
102102

103103
# Install dependencies for main python installation
104104
COPY ./requirements.txt /tmp/requirements.txt
105105
RUN pyenv exec pip install --upgrade -r /tmp/requirements.txt && \
106-
rm /tmp/requirements.txt
106+
rm /tmp/requirements.txt
107+
108+
# Install tools with pipx in isolated environments
109+
COPY ./requirements-tools.txt /tmp/requirements-tools.txt
110+
ENV PIPX_HOME="/opt/pipx"
111+
ENV PIPX_BIN_DIR="${PIPX_HOME}/bin"
112+
ENV PATH="${PIPX_BIN_DIR}:${PATH}"
113+
RUN mkdir -p "${PIPX_BIN_DIR}" && \
114+
while IFS="" read -r line || [ -n "$line" ]; do \
115+
pyenv exec pipx install --global "${line}"; \
116+
done </tmp/requirements-tools.txt && \
117+
rm /tmp/requirements-tools.txt
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
bandit
2+
black
3+
flake8
4+
flynt
5+
isort
6+
tox
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
bandit
2-
black
3-
flake8
4-
isort
51
pip
2+
pipx
63
setuptools
7-
tox
84
virtualenv
95
wheel

0 commit comments

Comments
 (0)