Skip to content

Commit 6000856

Browse files
committed
chore: Use multi-stage build and update Poetry in Dockerfile.sphinx
- poetry-builder installs Poetry 2.3.2 and exports requirements.txt. - docs-builder copies that file, installs system packages (curl, cargo), creates the unprivileged user, and installs Python dependencies with pip
1 parent aab9580 commit 6000856

1 file changed

Lines changed: 47 additions & 15 deletions

File tree

scripts/Dockerfile.sphinx

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,56 @@
1-
# in your Dockerfile
2-
FROM sphinxdoc/sphinx:7.4.7
3-
41
ARG USER_UID=1000
52
ARG USER_GID=1000
63

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+
739
WORKDIR /docs
40+
841
# 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+
1045
# 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+
2250
USER user
2351

2452

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

Comments
 (0)