Mercurial > p > roundup > code
comparison scripts/Dockerfile @ 6522:e6ae8188f61a
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.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Fri, 05 Nov 2021 23:44:14 -0400 |
| parents | 26babdf85067 |
| children | 49d26e77d173 |
comparison
equal
deleted
inserted
replaced
| 6521:42ff671d7f41 | 6522:e6ae8188f61a |
|---|---|
| 1 # build in root dir using: | 1 # 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 . | |
| 3 # | 4 # |
| 4 # run using: | 5 # 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 | |
| 6 | 9 |
| 7 FROM python:3-alpine | |
| 8 | 10 |
| 9 ENV appdir=/usr/src/app | 11 # Global vars for all build stages |
| 12 | |
| 13 # application directory | |
| 14 ARG appdir=/usr/src/app | |
| 15 | |
| 16 # support roundup install from 'local' directory or from 'pypi' | |
| 17 ARG source=local | |
| 18 | |
| 19 FROM python:3-alpine as build | |
| 20 | |
| 21 # Inherit global values https://github.com/moby/moby/issues/37345 | |
| 22 ARG appdir | |
| 23 | |
| 10 WORKDIR $appdir | 24 WORKDIR $appdir |
| 11 | 25 |
| 12 # allow roundup install from local directory or from pypi | 26 # Add packages needed to compile mysql, pgsql and other python modules. |
| 13 ARG source=local | 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 | |
| 14 | 38 |
| 15 LABEL "org.roundup-tracker.vendor"="Roundup Issue Tracker Team" \ | 39 # add requirements for pip here, e.g. Whoosh, gpg, zstd or other |
| 16 "org.roundup-tracker.description"="Roundup Issue Tracker using sqlite" \ | 40 # modules not installed in the base library. |
| 17 "version"="2.1.0 $source" | 41 # ignore warnings from pip to use virtualenv |
| 18 | |
| 19 # add requirements for pip here, e.g. pytz or other modules | |
| 20 # ignore warnings from pip to use virtualenv | |
| 21 COPY scripts/requirements.txt . | 42 COPY scripts/requirements.txt . |
| 22 RUN pip install --no-cache-dir -r requirements.txt | 43 RUN pip install --no-cache-dir -r requirements.txt |
| 23 | 44 |
| 24 # copy the elements of the release directory to the docker image | 45 # copy the elements of the release directory to the docker image |
| 25 COPY setup.py install/ | 46 COPY setup.py install/ |
| 30 COPY share install/share/ | 51 COPY share install/share/ |
| 31 | 52 |
| 32 # verify source has one of two valid values then | 53 # verify source has one of two valid values then |
| 33 # install in python3 standard directories from local copy | 54 # install in python3 standard directories from local copy |
| 34 # or install in python3 standard directories from pypi using pip | 55 # or install in python3 standard directories from pypi using pip |
| 35 | 56 # import from global/command line |
| 36 RUN if [ "$source" == "local" ] || [ "$source" == "pypi" ]; then :; \ | 57 ARG source |
| 58 RUN set -xv && if [ "$source" = "local" ] || [ "$source" = "pypi" ]; then :; \ | |
| 37 else echo "invalid value for source: $source"; \ | 59 else echo "invalid value for source: $source"; \ |
| 38 echo "must be local or pypi"; exit 1; fi; \ | 60 echo "must be local or pypi"; exit 1; fi; \ |
| 39 if [ "$source" == "local" ]; then cd install && ./setup.py install; fi; \ | 61 if [ "$source" = "local" ]; then cd install && ./setup.py install; fi; \ |
| 40 if [ "$source" == "pypi" ]; then pip install roundup; fi | 62 if [ "$source" = "pypi" ]; then pip install roundup; fi |
| 41 | 63 |
| 42 # delete source files | 64 # build a new smaller docker image for execution. Build image above |
| 43 RUN rm -rf install | 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/ | |
| 44 | 89 |
| 45 # map port 8080 to your local port | 90 # map port 8080 to your local port |
| 46 EXPOSE 8080/tcp | 91 EXPOSE 8080/tcp |
| 47 | 92 |
| 48 # mount a trackerdir on tracker location | 93 # mount a trackerdir on tracker location |
| 49 RUN mkdir tracker | 94 RUN mkdir tracker |
| 50 VOLUME $appdir/tracker | 95 VOLUME $appdir/tracker |
| 51 | 96 |
| 52 # do not run roundup as root | 97 # do not run roundup as root |
| 53 RUN adduser -D roundup | 98 RUN adduser -D -h /usr/src/app roundup |
| 99 USER roundup | |
| 54 | 100 |
| 55 # run the server | 101 # run the server, disable output buffering so we can see logs. |
| 56 USER roundup | 102 ENV PYTHONUNBUFFERED=1 |
| 57 ENTRYPOINT [ "roundup-server", "-L", "-n", "0.0.0.0" ] | 103 ENTRYPOINT [ "roundup-server", "-n", "0.0.0.0" ] |
| 58 | 104 |
| 59 # allow the invoker to override cmd with multiple trackers | 105 # allow the invoker to override cmd with multiple trackers |
| 60 # in each subdirectory under $appdir/tracker. E.G. | 106 # in each subdirectory under $appdir/tracker. E.G. |
| 61 # docker run .... \ | 107 # docker run .... \ |
| 62 # issues=tracker/issues foo=tracker/foo | 108 # issues=tracker/issues foo=tracker/foo |
