Skip to content

Commit 93604cd

Browse files
committed
Replace hardcoded python version with ARG variable
The Dockerfile had a hardcoded Python version in install paths and COPY command in the second stage build. Replace that with a hardcoded ARG pythonversion. Add RUN command to verify pythonversion against the actual version installed in the docker image. If they do not match generate an appropriate --build-arg for the docker build command that will match the docker image version. Document the use of the variable and why it's needed in installation.txt. Also fix typos referencing --build-args and bad values for the arguments.
1 parent 9c76d0e commit 93604cd

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

doc/installation.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,20 @@ PyPI, by running::
290290
The docker declares a single volume mounted at
291291
``/usr/src/app/tracker`` inside the container. You will mount your
292292
tracker home directory at this location. The ``/usr/src/app`` path can
293-
be changed by using ``--build-args=/new/path``.
293+
be changed by using ``--build-arg="appdir=/new/path"``.
294294

295295
You can also add additional modules to the docker container by using
296-
`--build-args="pip_mod=requests setproctitle"`.
296+
`--build-arg="pip_mod=requests setproctitle"`.
297+
298+
Because of deficiencies in the docker program (see:
299+
https://github.com/moby/moby/issues/29110#issuecomment-1100676306),
300+
there is no way to determine the version of Python inside the
301+
container and make that available as part of the build process. If
302+
your build fails because the ``pythonversion does not match``, add the
303+
suggested ``--build-arg`` to the ``docker build`` command line.
297304

298305
By default the container runs Roundup using UID 1000. By setting
299-
`--build-args="roundup_uid=2000"` you can change the UID.
306+
`--build-arg="roundup_uid=2000"` you can change the UID.
300307

301308
Configuring Roundup in the Container
302309
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

scripts/Docker/Dockerfile

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ ARG appdir=/usr/src/app
1818
# latest release from 'pypi'
1919
ARG source=local
2020

21+
# Python version as a.b Used for installation directory and
22+
# COPY from install dir in second stage.
23+
ARG pythonversion=3.11
24+
2125
FROM python:3-alpine as build
2226

2327
# Inherit global values https://github.com/moby/moby/issues/37345
@@ -44,6 +48,15 @@ RUN apk add \
4448
swig \
4549
xapian-core-dev
4650

51+
ARG pythonversion
52+
# verify that pythonversion matches the one in the image.
53+
RUN image_python_version=$(python -c 'import sys; print("%s.%s"%sys.version_info[0:2])'); \
54+
if [ "${pythonversion}" != "${image_python_version}" ]; then \
55+
printf "\n\n*****\npythonversion does not match.\n" ; \
56+
printf "Add:\n --build-arg=\"pythonversion=${image_python_version}\"\nto docker build\n******\n\n"; \
57+
exit 1; \
58+
fi
59+
4760
# build xapian bindings:
4861
# file with sphinx build dependencies to remove after build
4962
# they are over 70MB of space.
@@ -95,7 +108,7 @@ RUN set -xv && if [ "$source" = "local" ] || \
95108
if [ "$source" = "local_pip" ]; then cd install && pip install \
96109
--use-feature=in-tree-build . ; fi; \
97110
if [ "$source" = "pypi" ]; then pip install roundup; \
98-
cp -ril /usr/local/lib/python3.11/site-packages/usr/local/share/* \
111+
cp -ril /usr/local/lib/python${pythonversion}/site-packages/usr/local/share/* \
99112
/usr/local/share; fi
100113

101114
# Allow user to add more modules during build
@@ -135,9 +148,9 @@ LABEL "org.roundup-tracker.vendor"="Roundup Issue Tracker Team" \
135148
"version"="2.2.0 $source" \
136149
"org.opencontainers.image.authors"="[email protected]"
137150

138-
151+
ARG pythonversion
139152
# pull over built assets
140-
COPY --from=build /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages/
153+
COPY --from=build /usr/local/lib/python${pythonversion}/site-packages /usr/local/lib/python${pythonversion}/site-packages/
141154
COPY --from=build /usr/local/bin/roundup* /usr/local/bin/
142155
COPY --from=build /usr/local/share /usr/local/share/
143156
COPY scripts/Docker/roundup_start .

0 commit comments

Comments
 (0)