|
1 | 1 | # base image |
2 | | -FROM python:3.10.8-slim as python-base |
| 2 | +FROM python:3.10.8-alpine as python-base |
3 | 3 |
|
4 | | -ENV PYTHONUNBUFFERED=1 \ |
| 4 | +ENV PYTHONFAULTHANDLER=1 \ |
| 5 | + PYTHONHASHSEED=random \ |
| 6 | + PYTHONUNBUFFERED=1 \ |
5 | 7 | PYTHONDONTWRITEBYTECODE=1 \ |
6 | | - PIP_NO_CACHE_DIR=off \ |
7 | | - PIP_DISABLE_PIP_VERSION_CHECK=on \ |
8 | | - PIP_DEFAULT_TIMEOUT=100 \ |
9 | | - POETRY_HOME="/opt/poetry" \ |
10 | | - POETRY_VIRTUALENVS_IN_PROJECT=true \ |
11 | | - POETRY_NO_INTERACTION=1 \ |
12 | | - APP_PATH="/app" \ |
13 | | - VENV_PATH="/app/.venv" |
14 | | - |
15 | | -# prepend poetry and venv to path |
16 | | -ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH" |
17 | | - |
| 8 | + VENV_PATH="/app/venv" \ |
| 9 | + APP_PATH="/app" |
| 10 | +# prepend venv to path |
| 11 | +ENV PATH="$VENV_PATH/bin:$PATH" |
18 | 12 | WORKDIR $APP_PATH |
19 | 13 |
|
20 | 14 |
|
21 | 15 | # Build |
22 | 16 | FROM python-base as builder-base |
23 | 17 |
|
24 | | -SHELL ["/bin/bash", "-o", "pipefail", "-c"] |
| 18 | +SHELL ["/bin/ash", "-o", "pipefail", "-c"] |
| 19 | + |
| 20 | +ENV PIP_DEFAULT_TIMEOUT=100 \ |
| 21 | + PIP_DISABLE_PIP_VERSION_CHECK=1 \ |
| 22 | + PIP_NO_CACHE_DIR=1 |
25 | 23 |
|
26 | 24 | # get poetry |
27 | | -# hadolint ignore=DL3008 |
28 | | -RUN apt-get update \ |
29 | | - && apt-get --no-install-recommends install -y curl \ |
30 | | - && apt-get clean \ |
31 | | - && rm -rf /var/lib/apt/lists/* \ |
| 25 | +RUN apk update \ |
| 26 | + && apk add --update --no-cache curl==7.87.0-r1 \ |
32 | 27 | && curl -sSL https://install.python-poetry.org | python - |
33 | 28 |
|
34 | | -ENV PATH="${PATH}:/root/.poetry/bin" |
| 29 | +RUN python -m venv "$VENV_PATH" |
| 30 | + |
| 31 | +ENV PATH="${PATH}:/root/.local/bin" |
35 | 32 |
|
36 | 33 |
|
37 | 34 | COPY pyproject.toml poetry.lock ./ |
38 | 35 |
|
39 | | -# install deps |
40 | | -RUN poetry install --only main --no-root |
| 36 | +RUN poetry export -f requirements.txt | "$VENV_PATH/bin/pip" install -r /dev/stdin |
| 37 | + |
| 38 | +COPY . . |
| 39 | + |
| 40 | +RUN poetry build && "$VENV_PATH/bin/pip" install dist/*.whl \ |
| 41 | + && rm -rf dist/ |
| 42 | + |
| 43 | + |
| 44 | +# Static base |
| 45 | +FROM builder-base as static-base |
| 46 | + |
| 47 | +RUN python manage.py collectstatic |
| 48 | + |
| 49 | +# Static |
| 50 | +FROM nginx:mainline-alpine as static |
| 51 | +COPY --from=static-base /app/assets /usr/share/nginx/html |
41 | 52 |
|
42 | 53 | # Prod |
43 | 54 | FROM python-base as production |
|
0 commit comments