Skip to content

Commit 1997725

Browse files
committed
Docker configuration for dev environment
1 parent a08e3d6 commit 1997725

File tree

5 files changed

+119
-0
lines changed

5 files changed

+119
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ sphinx_rtd_theme/static/js/html5shiv.min.js
2727
sphinx_rtd_theme/static/js/html5shiv-printshiv.min.js
2828
.direnv/
2929
.envrc
30+
.container_id

Dockerfile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# python:3-alpine contains node 18 so has to go first
2+
# in order to get overwritten
3+
FROM python:3-alpine
4+
FROM node:14-alpine
5+
6+
# Do not use --update since that will also fetch the
7+
# latest node-current package
8+
# 'make' is needed for building documentation
9+
RUN apk add npm make py3-pip py3-wheel
10+
11+
# Add an extra verification that we have the right node
12+
# because the above caused issues
13+
RUN node -v && node -v | grep -q v14
14+
15+
RUN pip install pip --upgrade
16+
17+
RUN mkdir -p /project/src/ &&\
18+
mkdir -p /project/docs/ &&\
19+
mkdir -p /project-static-copy
20+
21+
WORKDIR /project
22+
23+
COPY package.json /project/
24+
25+
# COPY package-lock.json /project/
26+
27+
COPY bin/preinstall.js /project/bin/preinstall.js
28+
29+
RUN cd /project
30+
31+
# It matters that the node environment is installed into the same
32+
# folder, i.e. /project where we will run the environment from
33+
RUN npm install --package-lock-only &&\
34+
npm audit fix &&\
35+
npm install
36+
37+
# This is strictly speaking not necessary, just makes
38+
# running the container faster...
39+
# Install dependencies, then uninstall project itself
40+
COPY . /project-static-copy
41+
RUN cd /project-static-copy &&\
42+
pip install ".[dev]" &&\
43+
/usr/bin/yes | pip uninstall sphinx_rtd_theme
44+
45+
46+
# Copy in stuff we need to run the project
47+
COPY webpack.common.js webpack.dev.js webpack.prod.js /project/
48+
49+
COPY docker-entrypoint.sh /entrypoint.sh
50+
RUN chmod +x /entrypoint.sh
51+
52+
ENTRYPOINT ["/entrypoint.sh"]

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
SHELL := /bin/bash
2+
CWD := $(shell cd -P -- '$(shell dirname -- "$0")' && pwd -P)
3+
4+
docker-images:
5+
docker build -t sphinx_rtd_theme:latest .
6+
7+
docker-run:
8+
rm -f .container_id
9+
docker run --cidfile=.container_id -t -i -p 1919:1919 \
10+
--network host \
11+
--mount type=bind,source="$(CWD)",target=/project-readonly,readonly \
12+
--mount type=volume,dst=/project-readonly/sphinx_rtd_theme.egg-info,volume-driver=local \
13+
--mount type=bind,source="$(CWD)/src",target=/project/src,readonly \
14+
--mount type=bind,source="$(CWD)/docs",target=/project/docs \
15+
sphinx_rtd_theme:latest $(command)
16+
17+
docker-copy-assets:
18+
docker cp "$(shell cat .container_id):/project/sphinx_rtd_theme" .
19+
docker cp "$(shell cat .container_id):/project/package-lock.json" .

docker-entrypoint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
# Install the readonly project in editable mode and make sure
4+
# all dependencies are upgrade. This is mounted in from the
5+
# outside, but it is on purpose that it is readonly!
6+
cd /project-readonly
7+
pip install --upgrade -e ".[dev]"
8+
9+
cd /project
10+
11+
npm run $@

docs/contributing.rst

Lines changed: 36 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,39 @@ 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, such as `SASS`_ , `Wyrm` and `Webpack`_ in the anticipated versions. 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 copy out those artifacts into your external environment.
79+
80+
Use the following steps:
81+
82+
.. code-block:: console
83+
84+
# Builds an updated version of the docker image
85+
$ make docker-images
86+
87+
# Runs the docker environment and builds the assets. The container exits after completing the build.
88+
$ make docker-run command=build
89+
90+
# Runs the development webserver
91+
$ make docker-run command=dev
92+
93+
# Copies out the assets from the most recent docker-run
94+
$ make docker-copy-assets
95+
96+
97+
Every time you change the Node or Python requirements, you will need to rebuild images with ``make docker-images``. If you change SASS or JS, you will need to rebuild assets.
98+
99+
If you need a different setup, refer to ``Makefile`` to see the exact method used to invoke the Docker environment.
100+
65101
Testing
66102
=======
67103

0 commit comments

Comments
 (0)