Skip to content

Commit ba059c7

Browse files
committed
Wrapping up the Docker work, using docker cp again in order to copy assets out of containers
1 parent 4393bd2 commit ba059c7

File tree

6 files changed

+60
-19
lines changed

6 files changed

+60
-19
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: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,25 @@ RUN apk add npm make py3-pip py3-wheel
88

99
# Add an extra verification that we have the right node
1010
# because the above caused issues
11-
RUN python3 --version
1211
RUN node -v && node -v | grep -q v14 &&\
1312
python3 --version && python3 --version | grep -q "3.10"
1413

1514
RUN pip install pip --upgrade
1615

1716
RUN mkdir -p /project/src/ &&\
18-
mkdir -p /project/docs/ &&\
17+
mkdir -p /project/docs/build/ &&\
1918
mkdir -p /project-minimal-copy/sphinx_rtd_theme &&\
2019
touch /project-minimal-copy/sphinx_rtd_theme/__init__.py
2120

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
2224
WORKDIR /project
2325

26+
# Copy files necessary to run "npm install" and save
27+
# installed packages in the docker image (makes the runtime
28+
# so much faster)
2429
COPY package.json /project/
25-
26-
# COPY package-lock.json /project/
27-
2830
COPY bin/preinstall.js /project/bin/preinstall.js
2931

3032
RUN cd /project
@@ -37,16 +39,19 @@ RUN npm install --package-lock-only &&\
3739

3840
# This is strictly speaking not necessary, just makes
3941
# running the container faster...
40-
# Install dependencies, then uninstall project itsel
42+
# Install dependencies, then uninstall project itself
4143
COPY setup.py README.rst /project-minimal-copy/
4244
RUN cd /project-minimal-copy &&\
4345
pip install ".[dev]" &&\
4446
/usr/bin/yes | pip uninstall sphinx_rtd_theme
4547

4648

47-
# Copy in stuff we need to run the project
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.
4852
COPY webpack.common.js webpack.dev.js webpack.prod.js /project/
4953

54+
# Copy in the entrypoint and we're done
5055
COPY docker-entrypoint.sh /entrypoint.sh
5156
RUN chmod +x /entrypoint.sh
5257

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: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,21 @@ services:
66
volumes:
77
- type: "bind"
88
source: "./"
9-
target: "/project-working-copy"
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+
1024
network_mode: host
1125
ports:
1226
- "1919:1919"

docker-entrypoint.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#!/bin/sh
22

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-
cp -r /project/node_modules /project-working-copy/
7-
cd /project-working-copy
3+
# Update latest Python dependencies in case they have changed
4+
cd /project-readonly
85
pip install --upgrade -e ".[dev]"
96

107
# This helps a potential permission issue, but might be removed
118
# pending some more investigation of docker host file system
129
# permissions in the bind mount
13-
npm cache clean --force
14-
npm install
10+
# npm cache clean --force
11+
# npm install
12+
13+
cd /project
14+
cp -r /project-readonly/sphinx_rtd_theme .
1515

1616
echo "Going to invoke: npm run $@"
1717
npm run $@

docs/contributing.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,14 @@ Use the following steps:
8484
# Builds an updated version of the docker image
8585
$ docker-compose build
8686
87-
# Runs the docker environment and builds the assets. The container exits after completing the build.
88-
$ docker-compose run sphinx_rtd_theme build
89-
9087
# Runs the development webserver
9188
$ docker-compose run sphinx_rtd_theme dev
92-
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
9395
9496
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.
9597

0 commit comments

Comments
 (0)