Skip to content

Commit 510e95e

Browse files
committed
issue2551163 Docker/containerization support
New multi-stage build including drivers for mysql and postgresql along with brotli and zstd HTTP compression methods. Documentation in installation.txt.
1 parent 8f0fb3e commit 510e95e

File tree

4 files changed

+142
-31
lines changed

4 files changed

+142
-31
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ Features:
5656
faster response/loading. Also eliminates stalls when the front end web
5757
server uses http 1.1 but the roundup-server uses 1.0. New option
5858
"-V HTTP/1.0" can turn it off. (John Rouillard)
59+
- issue2551163 - add scripts/Dockerfile to provide basic support for
60+
containerization. See installation.txt for details. (John Rouillard)
5961

6062
2021-07-13 2.1.0
6163

doc/installation.txt

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,70 @@ base directory, if you do not want to use administrator rights. If you
216216
choose to do this, you may have to change Python's search path (sys.path)
217217
yourself.
218218

219+
Creating a Docker Container
220+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
221+
222+
If you don't want to install it natively, you can create a Docker
223+
container. This uses the Dockerfile in the scripts directory. The
224+
roundup code in the distribuion and any changes will be used. The
225+
build command is::
226+
227+
docker build -t roundup-app --rm -f scripts/Dockerfile .
228+
229+
It supports the following backends: anydbm, sqlite, mysql and
230+
postgresql. Mysql and postgresql support hasn't been tested, but the
231+
Python modules are built and available. See scripts/requirement.txt
232+
for the additional modules that are installed.
233+
234+
If you want to build a docker from the latest release on PyPI, you can
235+
use::
236+
237+
docker build -t roundup-app --build-arg="source=pypi" \
238+
--rm -f scripts/Dockerfile .
239+
240+
Once the docker is created, run it with::
241+
242+
docker run --rm -p 9017:8080 \
243+
-v /.../issue.tracker:/usr/src/app/tracker \
244+
roundup-app:latest
245+
246+
This will make the tracker available at:
247+
``http://yourhost:9017/issues/``.
248+
249+
The ``-p`` option maps an external port (9017) to proxy the roundup
250+
server running at port 8080 to the outside. The ``-v`` option maps a
251+
directory from the host into the docker container. It should be a
252+
tracker home directory. Note that uid 1000 is used by roundup. So the
253+
uid of the directory must be 1000.
254+
255+
If you want to run multiple trackers, create a subdirectory for each
256+
tracker home under the volume mount point. Then invoke ``docker run``
257+
passing the roundup-server tracker specifications like::
258+
259+
docker run --rm -p 9017:8080 \
260+
-v /.../issue.tracker:/usr/src/app/tracker \
261+
roundup-app:latest tracker1=tracker1_home tracker2=tracker2_home
262+
263+
264+
This will set up two trackers that can be reached at
265+
``http://yourhost:9017/tracker1/`` and ``http://yourhost:9017/tracker2/``.
266+
267+
If you need to install and initialize the trackers, you can get a
268+
shell without starting the roundup-server using::
269+
270+
docker run -it \
271+
-v /.../issue.tracker:/usr/src/app/tracker \
272+
--entrypoint sh roundup-app:latest
273+
274+
Now you can configure your tracker using ``roundup-admin -i tracker``
275+
using the directions below.
276+
277+
If you need to access your container while the server is running you
278+
can use::
279+
280+
docker exec -it c0d5 sh
281+
282+
where ``c0d5`` is the id prefix for the running container.
219283

220284
Configuring your first tracker
221285
------------------------------

scripts/Dockerfile

Lines changed: 67 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,44 @@
11
# build in root dir using:
2-
# docker build -t roundup-app --rm -f Dockerfile ..
2+
#
3+
# docker build -t roundup-app --rm -f scripts/Dockerfile .
34
#
45
# run using:
5-
# docker run --rm -v /home/rouilj/develop/roundup.sysadmin/issue.tracker:/usr/src/app/tracker -p 9017:8080 roundup-app:latest
6+
#
7+
# docker run --rm -v /.../issue.tracker:/usr/src/app/tracker \
8+
# -p 9017:8080 roundup-app:latest
69

7-
FROM python:3-alpine
810

9-
ENV appdir=/usr/src/app
10-
WORKDIR $appdir
11+
# Global vars for all build stages
1112

12-
# allow roundup install from local directory or from pypi
13+
# application directory
14+
ARG appdir=/usr/src/app
15+
16+
# support roundup install from 'local' directory or from 'pypi'
1317
ARG source=local
1418

15-
LABEL "org.roundup-tracker.vendor"="Roundup Issue Tracker Team" \
16-
"org.roundup-tracker.description"="Roundup Issue Tracker using sqlite" \
17-
"version"="2.1.0 $source"
19+
FROM python:3-alpine as build
20+
21+
# Inherit global values https://github.com/moby/moby/issues/37345
22+
ARG appdir
23+
24+
WORKDIR $appdir
25+
26+
# Add packages needed to compile mysql, pgsql and other python modules.
27+
# Can't use apk to add them as that installs a 3.9 python version.
28+
# g++ installs cc1plus needed by pip install
29+
RUN apk add \
30+
g++ \
31+
gcc \
32+
gpgme-dev \
33+
linux-headers \
34+
musl-dev \
35+
mysql-dev \
36+
postgresql-dev \
37+
swig
1838

19-
# add requirements for pip here, e.g. pytz or other modules
20-
# ignore warnings from pip to use virtualenv
39+
# add requirements for pip here, e.g. Whoosh, gpg, zstd or other
40+
# modules not installed in the base library.
41+
# ignore warnings from pip to use virtualenv
2142
COPY scripts/requirements.txt .
2243
RUN pip install --no-cache-dir -r requirements.txt
2344

@@ -32,15 +53,39 @@ COPY share install/share/
3253
# verify source has one of two valid values then
3354
# install in python3 standard directories from local copy
3455
# or install in python3 standard directories from pypi using pip
35-
36-
RUN if [ "$source" == "local" ] || [ "$source" == "pypi" ]; then :; \
56+
# import from global/command line
57+
ARG source
58+
RUN set -xv && if [ "$source" = "local" ] || [ "$source" = "pypi" ]; then :; \
3759
else echo "invalid value for source: $source"; \
3860
echo "must be local or pypi"; exit 1; fi; \
39-
if [ "$source" == "local" ]; then cd install && ./setup.py install; fi; \
40-
if [ "$source" == "pypi" ]; then pip install roundup; fi
61+
if [ "$source" = "local" ]; then cd install && ./setup.py install; fi; \
62+
if [ "$source" = "pypi" ]; then pip install roundup; fi
4163

42-
# delete source files
43-
RUN rm -rf install
64+
# build a new smaller docker image for execution. Build image above
65+
# is 1G in size.
66+
FROM python:3-alpine
67+
68+
# import from global
69+
ARG appdir
70+
71+
WORKDIR $appdir
72+
73+
# add libraries needed to run gpg/mysql/pgsql/brotli
74+
RUN apk add \
75+
gpgme \
76+
mariadb-connector-c \
77+
libpq \
78+
libstdc++
79+
80+
ARG source
81+
LABEL "org.roundup-tracker.vendor"="Roundup Issue Tracker Team" \
82+
"org.roundup-tracker.description"="Roundup Issue Tracker using sqlite" \
83+
"version"="2.1.0 $source"
84+
85+
# pull over built assets
86+
COPY --from=build /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages/
87+
COPY --from=build /usr/local/bin/roundup* /usr/local/bin/
88+
COPY --from=build /usr/local/share /usr/local/share/
4489

4590
# map port 8080 to your local port
4691
EXPOSE 8080/tcp
@@ -50,11 +95,12 @@ RUN mkdir tracker
5095
VOLUME $appdir/tracker
5196

5297
# do not run roundup as root
53-
RUN adduser -D roundup
54-
55-
# run the server
98+
RUN adduser -D -h /usr/src/app roundup
5699
USER roundup
57-
ENTRYPOINT [ "roundup-server", "-L", "-n", "0.0.0.0" ]
100+
101+
# run the server, disable output buffering so we can see logs.
102+
ENV PYTHONUNBUFFERED=1
103+
ENTRYPOINT [ "roundup-server", "-n", "0.0.0.0" ]
58104

59105
# allow the invoker to override cmd with multiple trackers
60106
# in each subdirectory under $appdir/tracker. E.G.

scripts/requirements.txt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
pytz
33
# indexer
44
Whoosh
5-
# databases - need devel and other files installed to be built.
6-
#psycopg2==2.7.4
7-
#mysqlclient==1.3.10
8-
# encryption - need additional packages
9-
#gpg==1.10.0
5+
# extra database support
6+
psycopg2
7+
mysqlclient
8+
# encryption
9+
gpg
1010
# java web tokens
11-
PyJWT==1.7.1
12-
# extra compression support - build needs gcc
13-
#Brotli==1.0.4
14-
#zstd==1.5.0.2
15-
11+
PyJWT
12+
# extra HTTP compression methods
13+
Brotli
14+
zstd

0 commit comments

Comments
 (0)