Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerfile: use a builder image to further optimize image size #2013

Merged
merged 1 commit into from
Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ build/
.coverage
.tox/
docs/_build
Dockerfile
27 changes: 16 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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