|
1 | | -FROM ubuntu:noble |
| 1 | +FROM ghcr.io/prefix-dev/pixi:0.72.2-noble AS build |
| 2 | +# Inspired by https://tech.quantco.com/blog/pixi-production/ |
| 3 | + |
| 4 | +# ARGS |
| 5 | +ARG LANGUAGE="en_US" |
| 6 | +ARG ENCODING="UTF-8" |
| 7 | + |
| 8 | +ENV LOCALE_STR="${LANGUAGE}.${ENCODING} ${ENCODING}" \ |
| 9 | + DEBIAN_FRONTEND=noninteractive |
| 10 | + |
| 11 | +# Install and Configure default locale |
| 12 | +# NB GHC has its own language handling via Babel. |
| 13 | +RUN apt update -y \ |
| 14 | + && apt install -y locales \ |
| 15 | + && echo "${LOCALE_STR}" > /etc/locale.gen \ |
| 16 | + && locale-gen \ |
| 17 | + && rm -rf /var/lib/apt/lists/* |
| 18 | + |
| 19 | +# Copy entire GHC repo content to /app |
| 20 | +WORKDIR /app |
| 21 | +COPY . . |
| 22 | + |
| 23 | +# Install deps (in /app/.pixi/). |
| 24 | +RUN pixi install -e prod --locked |
| 25 | + |
| 26 | +# pixi-env.sh: to be sourced, sets all paths and more. |
| 27 | +RUN echo '#!/bin/bash' > /app/pixi-env.sh |
| 28 | +RUN pixi shell-hook -e prod -s bash --as-is >> /app/pixi-env.sh |
| 29 | +RUN echo 'exec "$@"' >> /app/pixi-env.sh |
| 30 | +RUN echo chmod +x /app/pixi-env.sh |
| 31 | + |
| 32 | +# Prepare the GHC app, mainly web-related. |
| 33 | +RUN pixi run -e prod setup |
| 34 | +RUN cp docker/config_site.py instance/ |
| 35 | +RUN if [ -d docker/plugins ]; then cp -ar docker/plugins/* /app/GeoHealthCheck/plugins/; fi |
| 36 | + |
| 37 | +# Slim down, removing unused files generated within build |
| 38 | +RUN rm -rf /app/GeoHealthCheck/docs |
| 39 | +RUN find /app/GeoHealthCheck/static/lib -type d -name docs | xargs rm -rf |
| 40 | +RUN find /app/GeoHealthCheck/static/lib -type d -name src | xargs rm -rf |
| 41 | + |
| 42 | +FROM ubuntu:24.04 AS production |
2 | 43 |
|
3 | 44 | # Credits to yjacolin for providing first versions |
4 | 45 | LABEL original_developer="yjacolin <yves.jacolin@camptocamp.com>" \ |
5 | 46 | maintainer="Just van den Broecke <justb4@gmail.com>" |
6 | 47 |
|
| 48 | +# Copy the compiled locale files from the builder |
| 49 | +COPY --from=build /usr/lib/locale/locale-archive /usr/lib/locale/locale-archive |
| 50 | +COPY --from=build /etc/locale.gen /etc/locale.gen |
| 51 | +COPY --from=build /etc/default/locale /etc/default/locale |
| 52 | + |
7 | 53 | # These are default values, |
8 | 54 | # Override when running container via docker(-compose) |
9 | | - |
10 | | -# ARGS |
11 | | -ARG TZ="Etc/UTC" |
12 | | -ARG LANG="en_US.UTF-8" |
13 | | -ARG ADD_DEB_PACKAGES="" |
14 | | - |
15 | | -# General ENV settings |
16 | | -ENV LC_ALL="en_US.UTF-8" \ |
17 | | - LANG="en_US.UTF-8" \ |
18 | | - LANGUAGE="en_US.UTF-8" \ |
19 | | - \ |
20 | | - \ |
21 | | - DEB_PACKAGES="locales gunicorn python3.12-venv postgresql-client python3-gunicorn python3-gevent python3-lxml python3-pyproj" \ |
22 | | - DEB_BUILD_DEPS="make python3-pip" \ |
| 55 | +ENV LANG='en_US.UTF-8' \ |
| 56 | + LANGUAGE='en_US:en' \ |
| 57 | + LC_ALL='en_US.UTF-8' \ |
| 58 | + TZ='Etc/UTC' \ |
| 59 | + DEB_PACKAGES="ca-certificates postgresql-client" \ |
| 60 | + DEB_BUILD_DEPS="adduser" \ |
23 | 61 | ADMIN_NAME=admin \ |
24 | 62 | ADMIN_PWD=admin \ |
25 | 63 | ADMIN_EMAIL=admin.istrator@mydomain.com \ |
26 | | - SQLALCHEMY_DATABASE_URI='sqlite:////GeoHealthCheck/DB/data.db' \ |
| 64 | + SQLALCHEMY_DATABASE_URI='sqlite:////app/instance/DB/data.db' \ |
27 | 65 | SQLALCHEMY_ENGINE_OPTION_PRE_PING=False \ |
28 | 66 | SECRET_KEY='d544ccc37dc3ad214c09b1b7faaa64c60351d5c8bb48b342' \ |
| 67 | + GHC_HOME=/app \ |
| 68 | + GHC_USER=ghc \ |
| 69 | + GHC_USER_HOME=/home/ghc \ |
29 | 70 | GHC_PROBE_HTTP_TIMEOUT_SECS=30 \ |
30 | 71 | GHC_MINIMAL_RUN_FREQUENCY_MINS=10 \ |
31 | 72 | GHC_RETENTION_DAYS=30 \ |
@@ -54,52 +95,40 @@ ENV LC_ALL="en_US.UTF-8" \ |
54 | 95 | GHC_GEOIP_LATFIELD='lat' \ |
55 | 96 | GHC_GEOIP_LONFIELD='lon' \ |
56 | 97 | GHC_METADATA_CACHE_SECS=900 \ |
57 | | - \ |
58 | | -# WSGI server settings, assumed is gunicorn \ |
59 | | -HOST=0.0.0.0 \ |
60 | | -PORT=80 \ |
61 | | -WSGI_WORKERS=4 \ |
62 | | -WSGI_WORKER_TIMEOUT=6000 \ |
63 | | -WSGI_WORKER_CLASS='gevent' \ |
64 | | -\ |
| 98 | + HOST=0.0.0.0 \ |
| 99 | + PORT=80 \ |
| 100 | + WSGI_WORKERS=4 \ |
| 101 | + WSGI_WORKER_TIMEOUT=6000 \ |
| 102 | + WSGI_WORKER_CLASS='gevent' \ |
| 103 | + GHC_USER_PLUGINS='' |
| 104 | + |
65 | 105 | # GHC Core Plugins modules and/or classes, seldom needed to set: \ |
66 | 106 | # if not specified here or in Container environment \ |
67 | 107 | # all GHC built-in Plugins will be active. \ |
68 | 108 | #ENV GHC_PLUGINS 'GeoHealthCheck.plugins.probe.owsgetcaps,\ |
69 | 109 | # GeoHealthCheck.plugins.probe.wms, ...., ...\ |
70 | 110 | # GeoHealthCheck.plugins.check.checks' \ |
71 | | -\ |
72 | | -# GHC User Plugins, best be overridden via Container environment \ |
73 | | -GHC_USER_PLUGINS='' |
74 | | - |
75 | | -# Install operating system dependencies |
76 | | -RUN \ |
77 | | - apt-get update \ |
78 | | - && apt-get --no-install-recommends install -y ${DEB_PACKAGES} ${DEB_BUILD_DEPS} ${ADD_DEB_PACKAGES} \ |
79 | | - && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 \ |
80 | | - && echo "For ${TZ} date=$(date)" && echo "Locale=$(locale)" |
81 | 111 |
|
82 | | -# Add standard files and Add/override Plugins |
83 | | -# Alternative Entrypoints to run GHC jobs |
84 | | -# Override default Entrypoint with these on Containers |
85 | | -COPY docker/scripts/*.sh docker/config_site.py docker/plugins / |
86 | | - |
87 | | -# Add Source Code |
88 | | -COPY . /GeoHealthCheck |
| 112 | +# GHC User Plugins, best be overridden via Container environment \ |
89 | 113 |
|
90 | | -# Install |
| 114 | +# Install remaining dependencies and create user. |
91 | 115 | RUN \ |
92 | | - chmod a+x /*.sh && ./install.sh \ |
93 | | - # Cleanup TODO: remove unused Locales and TZs \ |
94 | | - && apt-get remove --purge -y ${DEB_BUILD_DEPS} \ |
95 | | - && apt-get clean \ |
| 116 | + apt update \ |
| 117 | + && apt --no-install-recommends install -y ${DEB_PACKAGES} ${DEB_BUILD_DEPS} \ |
| 118 | + && echo "For ${TZ} date=$(date)" && echo "Locale=$(locale)" \ |
| 119 | + && adduser --disabled-password --shell /bin/bash --gecos "User" ${GHC_USER} \ |
| 120 | + && apt remove --purge -y ${DEB_BUILD_DEPS} \ |
| 121 | + && apt clean \ |
96 | 122 | && apt autoremove -y \ |
97 | 123 | && rm -rf /var/lib/apt/lists/* |
98 | 124 |
|
| 125 | +# Copy entire bundle: GHC plus all dependencies, including non-Python binaries in /app. |
| 126 | +WORKDIR /app |
| 127 | +COPY --from=build --chown=${GHC_USER}:${GHC_USER} /app /app |
99 | 128 |
|
100 | | -# For SQLite |
101 | | -VOLUME ["/GeoHealthCheck/DB/"] |
| 129 | +# Run Containers as user. |
| 130 | +USER ${GHC_USER} |
102 | 131 |
|
103 | 132 | EXPOSE ${PORT} |
104 | 133 |
|
105 | | -ENTRYPOINT /run-web.sh |
| 134 | +ENTRYPOINT [ "/app/docker/scripts/run-web.sh" ] |
0 commit comments