-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
241 lines (178 loc) · 6.38 KB
/
Dockerfile
File metadata and controls
241 lines (178 loc) · 6.38 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# syntax=docker/dockerfile:1
# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/engine/reference/builder/
ARG PYTHON_VERSION=3.12
ARG UV_VERSION=0.7
ARG JUPYTER_VERSION=2025-04-14
FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv_image
FROM python:${PYTHON_VERSION}-slim AS base
# Keeps Python from buffering stdout and stderr to avoid situations where
# the application crashes without emitting any logs due to buffering.
ENV PYTHONUNBUFFERED=1
ENV VIRTUAL_ENV=/opt/venv \
PATH="/opt/venv/bin:$PATH" \
UV_LINK_MODE=copy \
UV_FROZEN=1 \
UV_PROJECT_ENVIRONMENT=/opt/venv
# Create a non-privileged user.
# See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user
ARG UID=1000
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
nomad
# Final stage to create the runnable image with minimal size
FROM base AS base_final
WORKDIR /app
RUN apt-get update \
&& apt-get install --yes --quiet --no-install-recommends \
libgomp1 \
libmagic1 \
curl \
zip \
unzip \
nodejs \
npm \
&& npm install -g configurable-http-proxy@^4.2.0 \
# clean cache and logs
&& rm -rf /var/lib/apt/lists/* /var/log/* /var/tmp/* ~/.npm
# Activate the virtualenv in the container
# See here for more information:
# https://pythonspeed.com/articles/multi-stage-docker-python/
ENV PATH="/opt/venv/bin:$PATH"
FROM base AS builder
# Prevents Python from writing pyc files.
ENV PYTHONDONTWRITEBYTECODE=1
ENV RUNTIME=docker
WORKDIR /app
RUN apt-get update \
&& apt-get install --yes --quiet --no-install-recommends \
libgomp1 \
libmagic1 \
file \
gcc \
build-essential \
curl \
zip \
unzip \
git \
&& rm -rf /var/lib/apt/lists/*
# Install UV
COPY --from=uv_image /uv /bin/uv
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=source=.git,target=.git,type=bind \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --extra plugins
COPY scripts ./scripts
FROM builder AS docs
WORKDIR /app
ARG NOMAD_DOCS_REPO="https://github.com/FAIRmat-NFDI/nomad-docs.git"
RUN set -ex && \
echo "Cloning from: $NOMAD_DOCS_REPO" && \
git clone "$NOMAD_DOCS_REPO" docs
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv run --with nomad-docs --directory docs mkdocs build \
&& mkdir -p built_docs \
&& cp -r docs/site/* built_docs
FROM builder AS gpu_action_builder
WORKDIR /app
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --extra plugins --extra gpu-action
FROM builder AS cpu_action_builder
WORKDIR /app
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --extra plugins --extra cpu-action
FROM base_final AS final
ARG PYTHON_VERSION=3.12
COPY --chown=nomad:${UID} --from=builder /opt/venv /opt/venv
COPY --chown=nomad:${UID} scripts/run.sh .
COPY --chown=nomad:${UID} scripts/run-worker.sh .
# nomad.yaml will be mounted in docker-compose.yaml
# COPY configs/nomad.yaml nomad.yaml
COPY pyproject.toml uv.lock /opt/
COPY --chown=nomad:${UID} --from=docs /app/built_docs /opt/venv/lib/python${PYTHON_VERSION}/site-packages/nomad/app/static/docs
RUN mkdir -p /app/.volumes/fs \
&& chown -R nomad:${UID} /app \
&& chown -R nomad:${UID} /opt/venv \
&& mkdir nomad \
&& cp /opt/venv/lib/python${PYTHON_VERSION}/site-packages/nomad/jupyterhub_config.py nomad/
USER nomad
# The application ports
EXPOSE 8000
EXPOSE 9000
VOLUME /app/.volumes/fs
FROM final AS cpu_action_final
COPY --chown=nomad:${UID} --from=cpu_action_builder /opt/venv /opt/venv
FROM final AS gpu_action_final
COPY --chown=nomad:${UID} --from=gpu_action_builder /opt/venv /opt/venv
FROM quay.io/jupyter/base-notebook:${JUPYTER_VERSION} AS jupyter_builder
ENV UV_PROJECT_ENVIRONMENT=/opt/conda \
UV_FROZEN=1
# Fix: https://github.com/hadolint/hadolint/wiki/DL4006
# Fix: https://github.com/koalaman/shellcheck/wiki/SC3014
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
USER root
RUN apt-get update \
&& apt-get install --yes --quiet --no-install-recommends \
libgomp1 \
libmagic1 \
file \
gcc \
build-essential \
curl \
zip \
unzip \
git \
# clean cache and logs
&& rm -rf /var/lib/apt/lists/* /var/log/* /var/tmp/* ~/.npm
# Switch back to jovyan to avoid accidental container runs as root
USER ${NB_UID}
WORKDIR "${HOME}"
COPY --from=uv_image /uv /bin/uv
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
# Use inexact to avoid removing pre-installed packages in the environment
# Use no-install-project to skip installing the current project (`nomad-distribution`)
uv sync --extra plugins --extra jupyter --no-install-project --inexact
FROM quay.io/jupyter/base-notebook:${JUPYTER_VERSION} AS jupyter
# Fix: https://github.com/hadolint/hadolint/wiki/DL4006
# Fix: https://github.com/koalaman/shellcheck/wiki/SC3014
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
USER root
RUN apt-get update \
&& apt-get install --yes --quiet --no-install-recommends \
libgomp1 \
libmagic1 \
file \
curl \
zip \
unzip \
git \
# `nbconvert` dependencies
# https://nbconvert.readthedocs.io/en/latest/install.html#installing-tex
texlive-xetex \
texlive-fonts-recommended \
texlive-plain-generic \
# clean cache and logs
&& rm -rf /var/lib/apt/lists/* /var/log/* /var/tmp/* ~/.npm
# Switch back to jovyan to avoid accidental container runs as root
USER ${NB_UID}
WORKDIR "${HOME}"
COPY --from=uv_image /uv /bin/uv
COPY --from=jupyter_builder /opt/conda /opt/conda
# Get rid ot the following message when you open a terminal in jupyterlab:
# groups: cannot find name for group ID 11320
RUN touch ${HOME}/.hushlogin