|
1 | | -# in your Dockerfile |
2 | | -FROM sphinxdoc/sphinx:7.4.7 |
3 | | - |
4 | 1 | ARG USER_UID=1000 |
5 | 2 | ARG USER_GID=1000 |
6 | 3 |
|
| 4 | +ARG PYTHON_VERSION=3.12 |
| 5 | + |
| 6 | +# This first stage install Poetry and exports a requirements.txt, |
| 7 | +# which we will then use in the second stage to install dependencies. |
| 8 | +FROM python:${PYTHON_VERSION}-slim AS poetry-builder |
| 9 | + |
| 10 | +ARG POETRY_VERSION=2.3.2 |
| 11 | + |
| 12 | +ENV POETRY_HOME="/opt/poetry" |
| 13 | +ENV PATH="$POETRY_HOME/bin:$PATH" |
| 14 | + |
| 15 | +WORKDIR /build |
| 16 | + |
| 17 | +RUN python3 -m venv /opt/poetry && \ |
| 18 | + /opt/poetry/bin/pip install "poetry==${POETRY_VERSION}" && \ |
| 19 | + poetry config virtualenvs.create false && \ |
| 20 | + poetry self add poetry-plugin-export |
| 21 | + |
| 22 | +COPY poetry.lock pyproject.toml ./ |
| 23 | +RUN poetry export --output requirements.txt |
| 24 | + |
| 25 | + |
| 26 | +FROM sphinxdoc/sphinx:7.4.7 AS docs-builder |
| 27 | + |
| 28 | +ARG USER_UID |
| 29 | +ARG USER_GID |
| 30 | + |
| 31 | +ENV DEBIAN_FRONTEND=noninteractive |
| 32 | + |
| 33 | +RUN apt-get update && \ |
| 34 | + apt-get install -y curl cargo && \ |
| 35 | + apt-get autoremove --purge && \ |
| 36 | + apt-get clean && \ |
| 37 | + rm -rf /var/lib/apt/lists/* |
| 38 | + |
7 | 39 | WORKDIR /docs |
| 40 | + |
8 | 41 | # add user with right id |
9 | | -RUN addgroup --gid $USER_GID user && adduser --uid $USER_UID --ingroup user --no-create-home --disabled-password --quiet user |
| 42 | +RUN addgroup --gid ${USER_GID} user && \ |
| 43 | + adduser --uid ${USER_UID} --ingroup user --disabled-password --quiet user |
| 44 | + |
10 | 45 | # ensure directories and permisisons |
11 | | -RUN mkdir -p /docs/build && mkdir -p /docs/source && chown user:user /docs |
12 | | -# install poetry, and export dependencies as a requirement.txt |
13 | | -COPY poetry.lock pyproject.toml ./ |
14 | | -RUN apt update && apt install -y curl cargo |
15 | | -RUN ( curl -sSL https://install.python-poetry.org | python3 - ) && \ |
16 | | - /root/.local/bin/poetry self add poetry-plugin-export && \ |
17 | | - /root/.local/bin/poetry export --output requirements.txt |
18 | | -# install those dependencies |
19 | | -RUN pip install -U pip && pip install -r requirements.txt |
20 | | -# install some useful plugin for sphinx |
21 | | -RUN pip install autodoc_pydantic sphinxcontrib-typer |
| 46 | +RUN mkdir -p /docs/build && \ |
| 47 | + mkdir -p /docs/source && \ |
| 48 | + chown -R user:user /docs |
| 49 | + |
22 | 50 | USER user |
23 | 51 |
|
24 | 52 |
|
| 53 | +COPY --from=poetry-builder /build/requirements.txt . |
| 54 | + |
| 55 | +# install those dependencies |
| 56 | +RUN pip install -U pip && pip install -r requirements.txt |
0 commit comments