Skip to content

Commit eb3fb18

Browse files
authored
Merge pull request #1319 from benjaoming/dockerize
Supplemental development process for Docker
2 parents b553aa6 + ba059c7 commit eb3fb18

File tree

6 files changed

+154
-0
lines changed

6 files changed

+154
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ sphinx_rtd_theme/static/js/html5shiv.min.js
2727
sphinx_rtd_theme/static/js/html5shiv-printshiv.min.js
2828
.direnv/
2929
.envrc
30+
# Used for dockerized builds
31+
.container_id

Dockerfile

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# This implicitely includes Python 3.10
2+
FROM node:14-alpine
3+
4+
# Do not use --update since that will also fetch the
5+
# latest node-current package
6+
# 'make' is needed for building documentation
7+
RUN apk add npm make py3-pip py3-wheel
8+
9+
# Add an extra verification that we have the right node
10+
# because the above caused issues
11+
RUN node -v && node -v | grep -q v14 &&\
12+
python3 --version && python3 --version | grep -q "3.10"
13+
14+
RUN pip install pip --upgrade
15+
16+
RUN mkdir -p /project/src/ &&\
17+
mkdir -p /project/docs/build/ &&\
18+
mkdir -p /project-minimal-copy/sphinx_rtd_theme &&\
19+
touch /project-minimal-copy/sphinx_rtd_theme/__init__.py
20+
21+
# This is the main working directory where node_modules
22+
# gets built. During runtime, it's mixed with directories
23+
# from an external environment through a bind mount
24+
WORKDIR /project
25+
26+
# Copy files necessary to run "npm install" and save
27+
# installed packages in the docker image (makes the runtime
28+
# so much faster)
29+
COPY package.json /project/
30+
COPY bin/preinstall.js /project/bin/preinstall.js
31+
32+
RUN cd /project
33+
34+
# It matters that the node environment is installed into the same
35+
# folder, i.e. /project where we will run the environment from
36+
RUN npm install --package-lock-only &&\
37+
npm audit fix &&\
38+
npm install
39+
40+
# This is strictly speaking not necessary, just makes
41+
# running the container faster...
42+
# Install dependencies, then uninstall project itself
43+
COPY setup.py README.rst /project-minimal-copy/
44+
RUN cd /project-minimal-copy &&\
45+
pip install ".[dev]" &&\
46+
/usr/bin/yes | pip uninstall sphinx_rtd_theme
47+
48+
49+
# Copy in files that we need to run the project. These files
50+
# will not be mounted into the runtime from external environment
51+
# so we copy them during build.
52+
COPY webpack.common.js webpack.dev.js webpack.prod.js /project/
53+
54+
# Copy in the entrypoint and we're done
55+
COPY docker-entrypoint.sh /entrypoint.sh
56+
RUN chmod +x /entrypoint.sh
57+
58+
ENTRYPOINT ["/entrypoint.sh"]

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
SHELL := /bin/bash
2+
CWD := $(shell cd -P -- '$(shell dirname -- "$0")' && pwd -P)
3+
4+
docker-images:
5+
docker-compose build
6+
7+
docker-npm-build:
8+
rm -f .container_id
9+
docker-compose run -d sphinx_rtd_theme build > .container_id
10+
docker container wait "$(shell cat .container_id)"
11+
docker cp "$(shell cat .container_id):/project/sphinx_rtd_theme" .
12+
docker cp "$(shell cat .container_id):/project/package-lock.json" .
13+
@echo "Done building"
14+
15+
docker-npm-dev:
16+
docker-compose run sphinx_rtd_theme dev
17+
18+
docker-build-all: docker-images docker-npm-build

docker-compose.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: "3.2"
2+
services:
3+
4+
sphinx_rtd_theme:
5+
build: .
6+
volumes:
7+
- type: "bind"
8+
source: "./"
9+
target: "/project-readonly"
10+
read_only: true
11+
- type: "volume"
12+
target: "/project-readonly/sphinx_rtd_theme.egg-info"
13+
- type: "bind"
14+
source: "./src"
15+
target: "/project/src"
16+
read_only: true
17+
- type: "bind"
18+
source: "./docs"
19+
target: "/project/docs"
20+
read_only: false #todo: fix this
21+
- type: "volume"
22+
target: "/project/docs/_build"
23+
24+
network_mode: host
25+
ports:
26+
- "1919:1919"

docker-entrypoint.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
# Update latest Python dependencies in case they have changed
4+
cd /project-readonly
5+
pip install --upgrade -e ".[dev]"
6+
7+
# This helps a potential permission issue, but might be removed
8+
# pending some more investigation of docker host file system
9+
# permissions in the bind mount
10+
# npm cache clean --force
11+
# npm install
12+
13+
cd /project
14+
cp -r /project-readonly/sphinx_rtd_theme .
15+
16+
echo "Going to invoke: npm run $@"
17+
npm run $@

docs/contributing.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ This project follows the Read the Docs :doc:`code of conduct
66
<rtd:code-of-conduct>`. If you are not familiar with our code of conduct policy,
77
take a minute to read the policy before starting with your first contribution.
88

9+
.. tip::
10+
There is a new dockerized build environment, see :ref:`dockerized-build`.
11+
912
Modifying the theme
1013
===================
1114

@@ -62,6 +65,36 @@ can be used to test built assets:
6265
.. _Wyrm: http://www.github.com/snide/wyrm/
6366
.. _Sphinx: http://www.sphinx-doc.org/en/stable/
6467

68+
69+
_dockerized-build::
70+
71+
Dockerized development
72+
======================
73+
74+
If you have Docker available on your platform, you can get started building CSS and JS artifacts a bit faster and won't have to worry about any of the setup spilling over into your general environment.
75+
76+
When building with Docker, we create an image containing the build dependencies. Some of these are quite outdated and therefore ideal to isolate a container. The image is tagged as ``sphinx_rtd_theme:latest``.
77+
78+
Inside the running docker image, we mount the working copy of the repository, build the artifacts and finally observe that the artifacts have been built and left in your current git checkout.
79+
80+
Use the following steps:
81+
82+
.. code-block:: console
83+
84+
# Builds an updated version of the docker image
85+
$ docker-compose build
86+
87+
# Runs the development webserver
88+
$ docker-compose run sphinx_rtd_theme dev
89+
90+
# If you want to copy stuff out of the Docker environment, run this make
91+
# target or read the actual Makefile to see what is going on.
92+
# We suggest running this command every time that you want to quickly build
93+
# new CSS/JS assets
94+
$ make docker-build-all
95+
96+
Every time you change the Node or Python requirements, you will need to rebuild images with ``docker-compose run sphinx_rtd_theme build``. If you change SASS or JS, you will need to rebuild assets.
97+
6598
Testing
6699
=======
67100

0 commit comments

Comments
 (0)