Skip to content

Commit 6a34746

Browse files
move doc building into container (#1171)
1 parent 1d107bc commit 6a34746

File tree

2 files changed

+69
-14
lines changed

2 files changed

+69
-14
lines changed

.github/workflows/build-docs.yml

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,53 @@ jobs:
88
steps:
99
- uses: actions/checkout@v4
1010

11-
- name: Setup Pages
12-
id: pages
13-
uses: actions/configure-pages@v5
11+
- uses: docker/setup-buildx-action@v3
12+
id: setup
1413

15-
- name: Set up Python 3.13
16-
uses: actions/setup-python@v5
14+
- name: Cache Build
15+
uses: actions/cache@v4
16+
id: cache
1717
with:
18-
python-version: '3.13'
19-
20-
- name: Install Dev dependencies
21-
run: >
22-
python3 -m pip install --disable-pip-version-check -r requirements-pip.txt &&
23-
pip3 install --disable-pip-version-check --group doc
24-
25-
- name: Build HTML
18+
# if the list or anything in these folders expected to change, then cache needs to be cleared and rebuilt, because it is keyed only by pyproject.toml hash
19+
path: .cache
20+
key: build-doc-${{ hashFiles('pyproject.toml','Dockerfile.build-doc') }}
21+
restore-keys: |
22+
build-doc-
23+
24+
- name: Create folders on cache miss
2625
run: |
27-
sphinx-build docs docs/_build/html
26+
mkdir -p .cache/var/cache/apt
27+
mkdir -p .cache/var/lib/apt
28+
mkdir -p .cache/root/.cache/pip
29+
mkdir -p .cache/root/.distrib/rust
30+
mkdir -p .cache/root/.cargo/registry
31+
32+
- name: Inject docker cache
33+
uses: reproducible-containers/buildkit-cache-dance@v3.1.2
34+
with:
35+
cache-map: |
36+
{
37+
".cache/var/cache/apt": "/var/cache/apt",
38+
".cache/var/lib/apt": "/var/lib/apt",
39+
".cache/root/.cache/pip": "/root/.cache/pip",
40+
".cache/root/.cargo/registry": "/root/.cargo/registry",
41+
".cache/root/.distrib/rust": "/root/.distrib/rust"
42+
}
43+
44+
- name: Build Doc
45+
uses: docker/build-push-action@v6
46+
with:
47+
push: false
48+
platforms: linux/arm64
49+
# do not cache layers
50+
file: Dockerfile.build-doc
51+
outputs: type=local,dest=docs/_build/html
52+
provenance: false
53+
context: .
54+
55+
- name: Setup Pages
56+
id: pages
57+
uses: actions/configure-pages@v5
2858

2959
- name: Upload artifact
3060
uses: actions/upload-pages-artifact@v3

Dockerfile.build-doc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# build (local):
2+
# docker buildx create --use --driver=docker-container --name container --bootstrap
3+
# docker buildx build . --cache-to type=local,dest=.cache,mode=max --cache-from type=local,src=.cache --platform=linux/arm64 --builder=container --progress plain -o docs/_build/html -f Dockerfile.build-doc
4+
5+
FROM python:3.13 AS builder
6+
WORKDIR /app
7+
COPY LICENSE.md .
8+
COPY README.md .
9+
COPY requirements-pip.txt .
10+
COPY pyproject.toml .
11+
COPY docs docs/
12+
RUN \
13+
--mount=type=cache,target=/root/.cache/pip,sharing=shared \
14+
python3 -m venv .venv && \
15+
. .venv/bin/activate && \
16+
python3 -m pip install --disable-pip-version-check -r requirements-pip.txt && \
17+
pip3 install --disable-pip-version-check --group doc
18+
RUN \
19+
. .venv/bin/activate && \
20+
echo "Building docs..." && \
21+
sphinx-build docs docs/_build/html
22+
23+
FROM scratch
24+
WORKDIR /
25+
COPY --from=builder /app/docs/_build/html .

0 commit comments

Comments
 (0)