Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
132 lines (117 loc) · 6.88 KB
/
Copy pathDockerfile
File metadata and controls
132 lines (117 loc) · 6.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# syntax=docker/dockerfile:1.7
#
# PlantCraft image: built online once, then shipped offline in the release bundle
# (`make bundle`, docs/install-offline.md). Four stages:
# 1. frontend: builds the web interface with Node (never shipped). It runs on the build
# machine's own architecture: its output is the same for every target.
# 2. notebooks: builds JupyterLite for Notebooks (Python in the browser, never shipped but
# its static files). Like the frontend, the same for every target.
# 3. wheels: downloads every Python dependency as a wheel, checked against the hashes in
# deploy/requirements.lock (binary wheels only: no compiler anywhere).
# 4. runtime: Python slim, installs from that wheelhouse with --no-index (no network), runs
# as an unprivileged user and holds no build tools, not even pip.
#
# Base images are pinned by version and digest. Override them (for example with a registry
# mirror holding the same digests) with --build-arg NODE_IMAGE=... / PYTHON_IMAGE=...
# Behind a TLS-inspecting corporate proxy, pass its CA as a build secret (never stored in a
# layer): docker build --secret id=build_ca,src=/path/to/corporate-ca.pem ... (make: BUILD_CA=)
ARG NODE_IMAGE=node:22.23.3-slim@sha256:c3de60bf2f9dd0ac6370e6117950ff62d6e339527e7472301c9c78a017978392
ARG PYTHON_IMAGE=python:3.13.16-slim-trixie@sha256:70729b46c69b4f1e97c4822c1af3df53a1476cf5ddc6c087c0c10bc3a5678c2f
FROM --platform=$BUILDPLATFORM ${NODE_IMAGE} AS frontend
WORKDIR /build/frontend
COPY frontend/package.json frontend/package-lock.json ./
# The suite frame (@plantcraft/ui), vendored like the SDK wheel (docs/app-standard.md, section 10).
COPY frontend/vendor ./vendor
RUN --mount=type=secret,id=build_ca,required=false \
if [ -s /run/secrets/build_ca ]; then export NODE_EXTRA_CA_CERTS=/run/secrets/build_ca; fi; \
npm ci --no-audit --no-fund
COPY frontend/ ./
RUN npm run build
# Notebooks: JupyterLite with a pruned Pyodide (notebooks/build.py, pinned by SHA-256 in
# notebooks/pins.json). Only its output, static files, reaches the runtime image.
FROM --platform=$BUILDPLATFORM ${PYTHON_IMAGE} AS notebooks
WORKDIR /build
COPY notebooks/requirements.txt ./notebooks/requirements.txt
RUN --mount=type=secret,id=build_ca,required=false \
if [ -s /run/secrets/build_ca ]; then export PIP_CERT=/run/secrets/build_ca SSL_CERT_FILE=/run/secrets/build_ca; fi; \
pip install --no-cache-dir --root-user-action=ignore -r notebooks/requirements.txt
COPY notebooks ./notebooks
RUN --mount=type=secret,id=build_ca,required=false \
if [ -s /run/secrets/build_ca ]; then export PIP_CERT=/run/secrets/build_ca SSL_CERT_FILE=/run/secrets/build_ca; fi; \
python notebooks/build.py --output /build/notebooks/dist --cache /tmp/notebooks-cache
FROM ${PYTHON_IMAGE} AS wheels
WORKDIR /build
COPY deploy/requirements.lock ./
RUN --mount=type=secret,id=build_ca,required=false \
if [ -s /run/secrets/build_ca ]; then export PIP_CERT=/run/secrets/build_ca; fi; \
pip wheel --no-cache-dir --require-hashes --only-binary=:all: \
--wheel-dir /wheelhouse -r requirements.lock
COPY sdk/python ./sdk/python
COPY pyproject.toml README.md LICENSE NOTICE ./
COPY plantcraft ./plantcraft
# First-party wheels: the SDK (installed as is) and the project, whose wheel carries only its
# metadata (version, entry points) into the image.
RUN --mount=type=secret,id=build_ca,required=false \
if [ -s /run/secrets/build_ca ]; then export PIP_CERT=/run/secrets/build_ca; fi; \
pip wheel --no-cache-dir --no-deps --wheel-dir /wheelhouse ./sdk/python . \
&& rm -rf ./sdk/python/build ./build
FROM ${PYTHON_IMAGE} AS runtime
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
HOME=/tmp \
PLANTCRAFT_SCENARIO=/app/deploy/site/site.json \
PLANTCRAFT_DEMO_USERS=false \
FORWARDED_ALLOW_IPS=127.0.0.1
WORKDIR /app
COPY pyproject.toml README.md LICENSE NOTICE /app/
COPY plantcraft /app/plantcraft
# The package's name until 0.5.0: `python -m processcraft.<module>` still runs (plantcraft/legacy.py).
COPY plantcraft/legacy.py /app/processcraft/__init__.py
COPY --from=frontend /build/frontend/dist /app/frontend/dist
COPY --from=notebooks /build/notebooks/dist /app/notebooks/dist
COPY docs /app/docs
COPY scenarios /app/scenarios
COPY demo/data /app/demo/data
COPY deploy/site /app/deploy/site
COPY deploy/demo /app/deploy/demo
# Dependencies from the hash-checked wheelhouse, without network. The project wheel is
# installed for its metadata only: the code runs from /app because the application finds
# its interface and help pages next to the source tree (frontend/dist, docs).
RUN --mount=type=bind,from=wheels,source=/wheelhouse,target=/wheelhouse \
--mount=type=bind,source=deploy/requirements.lock,target=/tmp/requirements.lock \
python -m pip install --no-cache-dir --root-user-action=ignore --no-index --find-links /wheelhouse \
--require-hashes -r /tmp/requirements.lock \
&& python -m pip install --no-cache-dir --root-user-action=ignore --no-index --no-deps \
/wheelhouse/plantcraft_sdk-*.whl /wheelhouse/plantcraft-*.whl \
&& python -m pip check \
&& site="$(python -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])')" \
&& rm -rf "${site}/plantcraft" \
&& echo /app > "${site}/plantcraft-app.pth" \
&& python -m compileall -q /app/plantcraft /app/processcraft \
&& python -m pip uninstall -y --root-user-action=ignore pip \
&& rm -rf /root/.cache \
&& groupadd --gid 10001 processcraft \
&& useradd --no-create-home --uid 10001 --gid 10001 --home-dir /tmp --shell /usr/sbin/nologin processcraft \
&& mkdir -p /data \
&& chown 10001:10001 /data \
&& chmod 0750 /data
USER 10001:10001
EXPOSE 8060
HEALTHCHECK --interval=20s --timeout=5s --start-period=40s --retries=5 \
CMD ["python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8060/healthz', timeout=4)"]
# PLANTCRAFT_WORKERS server processes (auto: 2 to 4 with Historian as the data layer, else 1).
CMD ["python", "-m", "plantcraft.api.serve"]
# Last, so a new commit or build time changes only the labels: the layers stay cached and
# identical, and suite-deploy (ci/macmini) leaves a container whose content did not change.
ARG VERSION=0.0.0
ARG REVISION=unknown
ARG CREATED=unknown
LABEL org.opencontainers.image.title="processcraft" \
org.opencontainers.image.description="PlantCraft: open platform for process engineers (central application)" \
org.opencontainers.image.version="${VERSION}" \
org.opencontainers.image.revision="${REVISION}" \
org.opencontainers.image.created="${CREATED}" \
org.opencontainers.image.licenses="Apache-2.0" \
org.opencontainers.image.source="https://github.com/PlantCraft/PlantCraft" \
org.opencontainers.image.documentation="https://github.com/PlantCraft/PlantCraft/blob/main/docs/install-offline.md" \
org.opencontainers.image.base.name="python:3.13.16-slim-trixie"