1- FROM python:3.7-slim
1+ FROM python:3.7-alpine AS base
22
3- # Create and set the working directory to /pybot
4- WORKDIR /pybot
3+ FROM base as builder
4+
5+ ENV PIP_DISABLE_PIP_VERSION_CHECK on
6+ ENV PYTHONDONTWRITEBYTECODE 1
7+ ENV PYTHONUNBUFFERED 1
8+
9+ RUN apk update && \
10+ apk add --no-cache build-base musl-dev python3-dev
11+
12+ RUN python -m venv /opt/venv
13+ # Make sure we use the virtualenv:
14+ ENV PATH="/opt/venv/bin:$PATH"
515
6- # Copy the pipfile into the pybot directory
716COPY poetry.lock pyproject.toml ./
817
9- # Install anything missing from the slim image, install dependnecies, remove anything only needed for building
10- # This is run as one line so docker caches it as a single layer.
11- RUN apt-get update \
12- && apt-get install -y gcc \
13- && rm -rf /var/lib/apt/lists/* \
14- && pip install poetry \
15- && poetry config settings.virtualenvs.create false \
16- && poetry install \
17- && apt-get purge -y --auto-remove gcc
18-
19- # Copy the rest of our app into the container
20- COPY . /pybot
21-
22- # Run the pybot module
23- ENTRYPOINT ["python3" , "-m" , "pybot" ]
18+ RUN pip install poetry && \
19+ poetry config settings.virtualenvs.create false && \
20+ poetry install --no-dev --no-interaction --no-ansi
21+
22+ # The `built-image` stage is the base for all remaining images
23+ # Pulls all of the built dependencies from the builder stage
24+ FROM base as built-image
25+ ENV PIP_DISABLE_PIP_VERSION_CHECK on
26+ ENV PYTHONDONTWRITEBYTECODE 1
27+ ENV PYTHONUNBUFFERED 1
28+
29+ # copy installed deps from builder image
30+ COPY --from=builder /opt/venv /opt/venv
31+
32+ # Make sure we use the virtualenv
33+ ENV PATH="/opt/venv/bin:$PATH"
34+
35+ # The `app` stage is used as the base for images that don't
36+ # need the development dependencies
37+ FROM built-image as app
38+
39+ COPY . /src
40+ WORKDIR /src
41+
42+ # The `Prod` stage creates an image that will run the application using a
43+ # production webserver and the `environments/production.py` configuration
44+ FROM app As Prod
45+ ENTRYPOINT ["python3" , "-m" , "pybot" ]
0 commit comments