Skip to content

Commit

Permalink
chore: Add default virtual environment on PATH for Docker image (#1484)
Browse files Browse the repository at this point in the history
* Add a venv virtual environment to PATH
   - Adding venv also symlinks the python doing the installing to the virtual environment's python
      -  e.g. `ls -l $(which python)` shows `/usr/local/venv/bin/python -> /usr/local/bin/python`
   - Thanks to Anthony Sottile for recommending this approach
   - c.f. https://youtu.be/2Hg5-Hrsa6w
   - c.f. pyhf/cuda-images#3
* Update hadolint GitHub Action to hadolint/hadolint-action@v1.5.0
  • Loading branch information
matthewfeickert authored Jun 8, 2021
1 parent 6d3ff05 commit e8a182d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ jobs:
- name: Lint with Black
run: |
black --check --diff --verbose .
- name: Lint Dockerfile
uses: brpaz/hadolint-action@v1.1.0
uses: hadolint/hadolint-action@v1.5.0
with:
dockerfile: "docker/Dockerfile"
dockerfile: docker/Dockerfile
8 changes: 6 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ ARG BASE_IMAGE=python:3.8-slim
FROM ${BASE_IMAGE} as base

FROM base as builder
# Set PATH to pickup virtual environment by default
ENV PATH=/usr/local/venv/bin:"${PATH}"
COPY . /code
# hadolint ignore=DL3003,SC2102
RUN apt-get -qq -y update && \
Expand All @@ -11,17 +13,19 @@ RUN apt-get -qq -y update && \
apt-get -y autoclean && \
apt-get -y autoremove && \
rm -rf /var/lib/apt/lists/* && \
python -m venv /usr/local/venv && \
cd /code && \
python -m pip --no-cache-dir install --upgrade pip setuptools wheel && \
python -m pip --no-cache-dir install .[xmlio,contrib] && \
python -m pip list

FROM base
ENV PATH=/usr/local/venv/bin:"${PATH}"
RUN apt-get -qq -y update && \
apt-get -qq -y install --no-install-recommends \
curl && \
apt-get -y autoclean && \
apt-get -y autoremove && \
rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/local /usr/local
ENTRYPOINT ["/usr/local/bin/pyhf"]
COPY --from=builder /usr/local/venv /usr/local/venv
ENTRYPOINT ["/usr/local/venv/bin/pyhf"]

0 comments on commit e8a182d

Please sign in to comment.