From a1567804268162d6f299374e5bdc2f771e5e9454 Mon Sep 17 00:00:00 2001 From: Lars Holmberg Date: Sun, 13 Feb 2022 20:40:37 +0100 Subject: [PATCH] Dockerfile use a builder image --- .dockerignore | 1 + Dockerfile | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/.dockerignore b/.dockerignore index 864086755a..c192f18da7 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,3 +5,4 @@ build/ .coverage .tox/ docs/_build +Dockerfile diff --git a/Dockerfile b/Dockerfile index 6251521cff..4c0c216efa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,25 @@ -FROM python:3.9-slim +FROM python:3.9-slim as base +FROM base as builder -COPY . /build +RUN apt update && apt install -y git # there are no wheels for some packages (geventhttpclient?) for arm64/aarch64, so we need some build dependencies there -RUN export NOWHEELS=$(arch | grep 'arm64\|aarch64') && apt update && apt install -y git && \ - if [ -n "$NOWHEELS" ]; then apt install -y --no-install-recommends gcc python3-dev; fi && \ - cd /build && pip install --no-cache . && \ - if [ -n "$NOWHEELS" ]; then apt purge -y --auto-remove -y gcc python3-dev; fi && \ - apt clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* +RUN if [ -n "$(arch | grep 'arm64\|aarch64')" ]; then apt install -y --no-install-recommends gcc python3-dev; fi -EXPOSE 8089 5557 +RUN python -m venv /opt/venv +ENV PATH="/opt/venv/bin:$PATH" + +COPY . /build +RUN pip install /build/ + +FROM base +ENV PATH="/opt/venv/bin:$PATH" +COPY --from=builder /opt/venv /opt/venv +EXPOSE 8089 5557 +# turn off python output buffering +ENV PYTHONUNBUFFERED=1 RUN useradd --create-home locust USER locust WORKDIR /home/locust ENTRYPOINT ["locust"] - -# turn off python output buffering -ENV PYTHONUNBUFFERED=1