Skip to content

Commit eb945c6

Browse files
committed
fix: simplify Docker setup
Especially the user and group IDs can simply be passed into the Docker container without the need of an entrypoint script.
1 parent 2c3e47e commit eb945c6

File tree

3 files changed

+108
-108
lines changed

3 files changed

+108
-108
lines changed

Dockerfile

Lines changed: 60 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,62 @@
11
# Usage:
22
#
3-
# /strictdoc$ docker build . -t strictdoc:latest
4-
# /strictdoc$ docker run --name strictdoc --rm -v "$(pwd):/data" -i -t strictdoc:latest
5-
# bash-5.1# strictdoc export .
6-
# bash-5.1# exit
7-
# strictdoc$ firefox docs/output/html/index.html
3+
# /strictdoc$ docker build \
4+
# ./ \
5+
# --build-arg STRICTDOC_SOURCE=pypi \
6+
# --tag strictdoc:latest
7+
# /strictdoc$ docker run \
8+
# --rm \
9+
# --volume="$(pwd):/data/" \
10+
# --user=$(id -u):$(id -g) \
11+
# --network=host \
12+
# --hostname="strictdoc" \
13+
# --name="strictdoc" \
14+
# --init \
15+
# --tty \
16+
# strictdoc:latest \
17+
# export ./
18+
# /strictdoc$ firefox ./output/html/index.html
819

920
FROM ubuntu:24.04
1021

22+
# Workaround: Newly introduced `ubuntu` user in ubuntu:24.04 causes UID/GID
23+
# mapping issues when adding custom user.
24+
RUN touch /var/mail/ubuntu && \
25+
chown ubuntu /var/mail/ubuntu && \
26+
userdel --remove ubuntu
27+
28+
# Main "payload" software
29+
ARG PAYLOAD=strictdoc
30+
31+
# Docker image labels
32+
LABEL maintainer="StrictDoc Project"
33+
LABEL name="${PAYLOAD}"
34+
LABEL description="Software for technical documentation and requirements management."
35+
1136
# Install dependencies
12-
RUN apt-get update && apt-get install -y \
13-
curl \
14-
git \
15-
gosu \
16-
python3 \
17-
python3-pip \
18-
python3-venv \
19-
sudo \
20-
vim \
21-
wget \
22-
&& rm -rf /var/lib/apt/lists/*
37+
RUN apt-get update && apt-get install --assume-yes --no-install-recommends \
38+
curl \
39+
git \
40+
python3 \
41+
python3-pip \
42+
python3-venv \
43+
vim \
44+
wget \
45+
&& \
46+
rm --recursive --force /var/lib/apt/lists/*
2347

2448
# Download and install Google Chrome
25-
RUN wget -q -O google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
26-
&& apt-get update \
27-
&& apt-get install -y ./google-chrome.deb \
28-
&& rm google-chrome.deb
49+
RUN wget --quiet --output-document=google-chrome.deb \
50+
https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && \
51+
apt-get update && \
52+
apt-get install --assume-yes --no-install-recommends ./google-chrome.deb && \
53+
rm --recursive --force /var/lib/apt/lists/* && \
54+
rm --force google-chrome.deb
2955

30-
# Create a virtual environment in the user's home directory.
31-
RUN python3 -m venv /opt/venv
32-
33-
# Ensure the virtual environment is used by modifying the PATH.
34-
ENV PATH="/opt/venv/bin:$PATH"
56+
# Create a virtual environment and ensure it is used by modifying the PATH.
57+
ENV VIRTUAL_ENV=/opt/venv
58+
RUN python3 -m venv ${VIRTUAL_ENV}
59+
ENV PATH="${VIRTUAL_ENV}/bin:$PATH"
3560

3661
# Install StrictDoc. Set default StrictDoc installation from PyPI but allow
3762
# overriding it with an environment variable.
@@ -44,17 +69,16 @@ RUN if [ "$STRICTDOC_SOURCE" = "pypi" ]; then \
4469
else \
4570
pip install --no-cache-dir --upgrade pip && \
4671
pip install --no-cache-dir git+https://github.com/strictdoc-project/strictdoc.git@${STRICTDOC_SOURCE}; \
47-
fi; \
48-
chmod -R 777 /opt/venv;
49-
50-
# Remove the default 'ubuntu' user.
51-
RUN userdel -r ubuntu 2>/dev/null || true
72+
fi;
5273

53-
# Allow updating the UID/GID dynamically at runtime
54-
COPY entrypoint.sh /entrypoint.sh
55-
RUN chmod +x /entrypoint.sh
74+
# Switch to non-root user
75+
RUN groupadd ${PAYLOAD} && \
76+
useradd --no-log-init --gid ${PAYLOAD} ${PAYLOAD}
77+
USER ${PAYLOAD}
5678

57-
# Set the working directory to the user's home directory.
58-
WORKDIR /data
79+
# Set up working directory.
80+
WORKDIR /data/
5981

60-
ENTRYPOINT ["/entrypoint.sh"]
82+
# Execute StrictDoc by default
83+
ENTRYPOINT ["strictdoc"]
84+
CMD ["--help"]

docs/strictdoc_01_user_guide.sdoc

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ STATEMENT: >>>
130130
TITLE: Requirements management
131131
STATEMENT: StrictDoc shall enable requirements management.
132132

133-
Create a file called ``hello_world.sdoc`` somewhere on your file system and copy the above "Hello World" example text to it. **The file must end with a newline character**.
133+
Create a file called ``hello.sdoc`` somewhere on your file system and copy the above "Hello World" example text to it. **The file must end with a newline character**.
134134

135135
Open a command-line terminal program supported on your system.
136136

137-
Once you have ``strictdoc`` installed (see [LINK: SDOC_UG_GETTING_STARTED] below), switch to the directory with the ``hello_world.sdoc`` file. For example, assuming that the file is now in the ``workspace/hello_world`` directory in your user folder:
137+
Once you have ``strictdoc`` installed (see [LINK: SDOC_UG_GETTING_STARTED] below), switch to the directory with the ``hello.sdoc`` file. For example, assuming that the file is now in the ``workspace/hello_world`` directory in your user folder:
138138

139139
.. code-block:: text
140140

@@ -295,25 +295,47 @@ To build the image:
295295

296296
.. code-block:: text
297297

298-
docker build . \
298+
docker build \
299+
./ \
299300
--build-arg STRICTDOC_SOURCE=pypi \
300-
-t strictdoc:latest
301+
--tag strictdoc:latest
301302

302303
The ``STRICTDOC_SOURCE`` argument is optional (default value is ``pypi``) and can be used to specify which Git revision the container shall check out when installing StrictDoc with ``pip install``. Possible values: a branch name, e.g., ``main``, or a commit hash.
303304

304-
To run the container:
305+
To run the container and execute StrictDoc directly:
305306

306307
.. code-block:: text
307308

308309
docker run \
309-
--name strictdoc \
310310
--rm \
311-
-e HOST_UID=$(id -u) \
312-
-e HOST_GID=$(id -g) \
313-
-v "$(pwd):/data" \
314-
-i -t \
311+
--volume="$(pwd):/data/" \
312+
--user=$(id -u):$(id -g) \
313+
--userns=host \
314+
--network=host \
315+
--hostname="strictdoc" \
316+
--name="strictdoc" \
317+
--init \
318+
--tty \
315319
strictdoc:latest \
316-
/bin/bash -c "strictdoc export --formats=html"
320+
export --formats=html ./
321+
322+
To run an interactive container with a shell:
323+
324+
.. code-block:: text
325+
326+
docker run \
327+
--rm \
328+
--volume="$(pwd):/data/" \
329+
--user=$(id -u):$(id -g) \
330+
--network=host \
331+
--hostname="strictdoc" \
332+
--name="strictdoc" \
333+
--init \
334+
--interactive \
335+
--tty \
336+
--entrypoint="" \
337+
strictdoc:latest \
338+
bash
317339

318340
.. list-table:: ``docker run`` options breakdown
319341
:widths: 40 60
@@ -325,21 +347,27 @@ To run the container:
325347
* - ``--rm``
326348
- Remove container when it is exited.
327349

328-
* - ``HOST_UID`` and ``HOST_GID``
329-
- These environment variables are used to tell the container that it should create a ``strictdoc`` user that has these values. This enables the content generated by the container to be visible outside the container under the permissions of the host user.
350+
* - ``--volume="<folder on host>:/data/"``
351+
- Normally the folder on the host should be the folder with the StrictDoc documentation. The ``/data/`` folder must always be specified without change because that's where the Docker container is designed to operate.
352+
353+
* - ``--user=$(id -u):$(id -g)``
354+
- Map the host user's user and group ID to the container user's IDs. This enables the content generated by the container to be visible outside the container under the permissions of the host user.
355+
356+
* - ``--network=host``
357+
- Map the host network into the container.
330358

331-
* - ``-v "<folder on host>:/data"``
332-
- Normally the folder on the host should be the folder with the StrictDoc documentation. The ``/data`` folder must always be specified without change because that's where the Docker container is designed to operate.
359+
* - ``--init``
360+
- Forward signals.
333361

334-
* - ``/bin/bash -c "..."``
335-
- This command shall typically be ``strictdoc export`` but it can also be skipped in which case the ``docker run`` will enter the container with SSH.
362+
* - ``--entrypoint=""``
363+
- Override entrypoint as empty to run a different command, e.g. Bash. (The default entrypoint is ``strictdoc``.)
336364

337-
If entering the container manually, the ``strictdoc`` command can be run as follows:
365+
If running an interactive container with a shell, the ``strictdoc`` command can be executed as follows:
338366

339367
.. code-block:: text
340368

341-
bash-5.1# strictdoc export .
342-
bash-5.1# exit
369+
ubuntu@strictdoc:/data$ strictdoc export .
370+
ubuntu@strictdoc:/data$ exit
343371

344372
The documentation shall be generated to ``./output/html`` which is accessible both on the host and inside the container.
345373
<<<

entrypoint.sh

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)