Skip to content

Commit

Permalink
Isolate tools into individual environments with pipx
Browse files Browse the repository at this point in the history
  • Loading branch information
TimPansino committed Oct 1, 2024
1 parent dc662e0 commit cdc0949
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
7 changes: 4 additions & 3 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ FROM ghcr.io/newrelic/newrelic-python-agent-ci:${IMAGE_TAG}

# Setup non-root user
USER root
ARG UID=1000
ARG UID=1001
ARG GID=${UID}
ENV HOME /home/vscode
ENV HOME=/home/vscode
RUN mkdir -p ${HOME} && \
groupadd --gid ${GID} vscode && \
useradd --uid ${UID} --gid ${GID} --home ${HOME} vscode && \
chown -R ${UID}:${GID} /home/vscode

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

# Set user
USER ${UID}:${GID}
17 changes: 14 additions & 3 deletions .github/containers/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ RUN ln -fs "/usr/share/zoneinfo/${TZ}" /etc/localtime && \
dpkg-reconfigure -f noninteractive tzdata

# Use root user
ENV HOME /root
ENV HOME=/root
WORKDIR "${HOME}"

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

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

# Install dependencies for main python installation
COPY ./requirements.txt /tmp/requirements.txt
RUN pyenv exec pip install --upgrade -r /tmp/requirements.txt && \
rm /tmp/requirements.txt
rm /tmp/requirements.txt

# Install tools with pipx in isolated environments
COPY ./requirements-tools.txt /tmp/requirements-tools.txt
ENV PIPX_HOME="/opt/pipx"
ENV PIPX_BIN_DIR="${PIPX_HOME}/bin"
ENV PATH="${PIPX_BIN_DIR}:${PATH}"
RUN mkdir -p "${PIPX_BIN_DIR}" && \
while IFS="" read -r line || [ -n "$line" ]; do \
pyenv exec pipx install --global "${line}"; \
done </tmp/requirements-tools.txt && \
rm /tmp/requirements-tools.txt
6 changes: 6 additions & 0 deletions .github/containers/requirements-tools.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
bandit
black
flake8
flynt
isort
tox
6 changes: 1 addition & 5 deletions .github/containers/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
bandit
black
flake8
isort
pip
pipx
setuptools
tox
virtualenv
wheel

0 comments on commit cdc0949

Please sign in to comment.