Skip to content

Commit

Permalink
Use virtualenv in dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
jstockwin committed May 14, 2021
1 parent c3752bb commit 152e7de
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@
FROM phusion/baseimage:focal-1.0.0

RUN adduser --disabled-password --gecos "" app_user
RUN echo "alias python=python3" > /home/app_user/.bashrc

RUN apt-get update && \
apt-get -y install software-properties-common \
python3-dev \
python3-pip \
python3-virtualenv \
libmagickwand-dev \
xvfb && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ENV VIRTUAL_ENV_DIR /.venv
RUN python3 -m virtualenv --python=python3.8 $VIRTUAL_ENV_DIR
# Set the virtual environment as the main Python directory
ENV PATH $VIRTUAL_ENV_DIR/bin:$PATH

RUN --mount=type=cache,target=/root/.cache/pip pip3 install --upgrade pip

# Create src dir
Expand All @@ -26,8 +31,9 @@ ADD ./setup.py $PROJECT_DIR/setup.py
ADD ./README.md $PROJECT_DIR/README.md
RUN --mount=type=cache,target=/root/.cache/pip pip3 install -e $PROJECT_DIR[dev]
RUN --mount=type=cache,target=/root/.cache/pip pip3 install -e $PROJECT_DIR[test]
RUN chown -R app_user:app_user $VIRTUAL_ENV_DIR

# Copy code, chown and switch user
ADD ./ $PROJECT_DIR
RUN chown -R app_user: $PROJECT_DIR
RUN chown -R app_user:app_user $PROJECT_DIR
USER app_user

0 comments on commit 152e7de

Please sign in to comment.