Skip to content

Commit 6ae19a0

Browse files
committed
add dockerfile and workflow to build a jupyter
1 parent 3d48196 commit 6ae19a0

File tree

4 files changed

+279
-0
lines changed

4 files changed

+279
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: ghcr
2+
#on:
3+
# push:
4+
# branches: [ "main" ]
5+
# pull_request:
6+
# branches: [ "main" ]
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
packages: write
12+
contents: read
13+
steps:
14+
- name: 'clone the repo'
15+
uses: actions/checkout@v4
16+
- name: 'login to ghcr'
17+
uses: docker/login-action@v3
18+
with:
19+
registry: ghcr.io
20+
username: ${{github.actor}}
21+
password: ${{secrets.GITHUB_TOKEN}}
22+
- name: Set up Docker Buildx
23+
uses: docker/setup-buildx-action@v3
24+
25+
- name: Build and push Docker image
26+
uses: docker/build-push-action@v5
27+
with:
28+
context: ./containers
29+
file: ./containters/Dockerfile.jupyter
30+
push: true
31+
tags: |
32+
ghcr.io/stfc/janus-core/jupyter:${{ github.sha }}
33+
ghcr.io/stfc/janus-core/jupyter:latest

containers/Dockerfile.jupyter

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
# Copyright (c) Jupyter Development Team.
2+
# Distributed under the terms of the Modified BSD License.
3+
# this is adapted from above.
4+
5+
ARG ROOT_CONTAINER=ubuntu:25.04
6+
7+
FROM $ROOT_CONTAINER
8+
9+
LABEL maintainer="Alin Elena <[email protected]>"
10+
ARG NB_USER="jovyan"
11+
ARG NB_UID="1001"
12+
ARG NB_GID="100"
13+
14+
USER root
15+
16+
# Install all OS dependencies for notebook server that starts but lacks all
17+
# features (e.g., download as all possible file formats)
18+
ENV DEBIAN_FRONTEND=noninteractive
19+
RUN apt update --yes && \
20+
# - apt-get upgrade is run to patch known vulnerabilities in apt-get packages as
21+
# the ubuntu base image is rebuilt too seldom sometimes (less than once a month)
22+
apt upgrade --yes && \
23+
apt install --yes --no-install-recommends \
24+
ca-certificates \
25+
fonts-liberation \
26+
locales \
27+
# - pandoc is used to convert notebooks to html files
28+
# it's not present in arm64 ubuntu image, so we install it here
29+
pandoc \
30+
# - run-one - a wrapper script that runs no more
31+
# than one unique instance of some command with a unique set of arguments,
32+
# we use `run-one-constantly` to support `RESTARTABLE` option
33+
run-one \
34+
sudo \
35+
# - tini is installed as a helpful container entrypoint that reaps zombie
36+
# processes and such of the actual executable we want to start, see
37+
# https://github.com/krallin/tini#why-tini for details.
38+
tini \
39+
wget bzip2 && \
40+
apt clean && rm -rf /var/lib/apt/lists/* && \
41+
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \
42+
locale-gen
43+
44+
# Configure environment
45+
ENV CONDA_DIR=/opt/conda \
46+
SHELL=/bin/bash \
47+
NB_USER="${NB_USER}" \
48+
NB_UID=${NB_UID} \
49+
NB_GID=${NB_GID} \
50+
LC_ALL=en_US.UTF-8 \
51+
LANG=en_US.UTF-8 \
52+
LANGUAGE=en_US.UTF-8
53+
ENV PATH="${CONDA_DIR}/bin:${PATH}" \
54+
HOME="/home/${NB_USER}"
55+
56+
# Copy a script that we will use to correct permissions after running certain commands
57+
COPY fix-permissions /usr/local/bin/fix-permissions
58+
RUN chmod a+rx /usr/local/bin/fix-permissions
59+
60+
# Enable prompt color in the skeleton .bashrc before creating the default NB_USER
61+
# hadolint ignore=SC2016
62+
RUN sed -i 's/^#force_color_prompt=yes/force_color_prompt=yes/' /etc/skel/.bashrc && \
63+
# Add call to conda init script see https://stackoverflow.com/a/58081608/4413446
64+
echo 'eval "$(command conda shell.bash hook 2> /dev/null)"' >> /etc/skel/.bashrc
65+
66+
# Create NB_USER with name jovyan user with UID=1000 and in the 'users' group
67+
# and make sure these dirs are writable by the `users` group.
68+
RUN echo "auth requisite pam_deny.so" >> /etc/pam.d/su && \
69+
sed -i.bak -e 's/^%admin/#%admin/' /etc/sudoers && \
70+
sed -i.bak -e 's/^%sudo/#%sudo/' /etc/sudoers && \
71+
useradd -l -m -s /bin/bash -N -u "${NB_UID}" "${NB_USER}" && \
72+
mkdir -p "${CONDA_DIR}" && \
73+
chown "${NB_USER}:${NB_GID}" "${CONDA_DIR}" && \
74+
chmod g+w /etc/passwd && \
75+
fix-permissions "${HOME}" && \
76+
fix-permissions "${CONDA_DIR}"
77+
78+
USER ${NB_UID}
79+
ARG PYTHON_VERSION=3.12
80+
81+
# Setup work directory for backward-compatibility
82+
RUN mkdir "/home/${NB_USER}/work" && \
83+
fix-permissions "/home/${NB_USER}"
84+
85+
# Install conda as jovyan and check the sha256 sum provided on the download site
86+
WORKDIR /tmp
87+
88+
RUN set -x && \
89+
arch=$(uname -m) && \
90+
if [ "${arch}" = "x86_64" ]; then arch="64"; fi && \
91+
wget --progress=dot:giga -O - "https://micro.mamba.pm/api/micromamba/linux-${arch}/latest" | tar -xvj bin/micromamba && \
92+
PYTHON_SPECIFIER="python=${PYTHON_VERSION}" && \
93+
if [ "${PYTHON_VERSION}" = "default" ]; then PYTHON_SPECIFIER="python"; fi && \
94+
./bin/micromamba install \
95+
--root-prefix="${CONDA_DIR}" \
96+
--prefix="${CONDA_DIR}" \
97+
--yes \
98+
'jupyter_core' \
99+
'conda' \
100+
'mamba' \
101+
"${PYTHON_SPECIFIER}" && \
102+
rm -rf /tmp/bin/ && \
103+
mamba list --full-name 'python' | awk 'END{sub("[^.]*$", "*", $2); print $1 " " $2}' >> "${CONDA_DIR}/conda-meta/pinned" && \
104+
mamba clean --all -f -y && \
105+
fix-permissions "${CONDA_DIR}" && \
106+
fix-permissions "/home/${NB_USER}"
107+
108+
RUN rm -rf "/home/${NB_USER}/.cache/"
109+
110+
# Switch back to jovyan to avoid accidental container runs as root
111+
USER ${NB_UID}
112+
113+
#============
114+
#minimal image now
115+
116+
USER root
117+
118+
RUN apt update --yes && \
119+
apt install --yes --no-install-recommends \
120+
cm-super \
121+
dvipng && \
122+
apt clean && rm -rf /var/lib/apt/lists/*
123+
124+
USER ${NB_UID}
125+
126+
# Install Python 3 packages
127+
RUN mamba install --yes \
128+
'altair' \
129+
'beautifulsoup4' \
130+
'bokeh' \
131+
'bottleneck' \
132+
'cloudpickle' \
133+
'conda-forge::blas=*=openblas' \
134+
'conda-forge::gfortran' \
135+
'conda-forge::hdf5' \
136+
'cython' \
137+
'dask' \
138+
'dill' \
139+
'h5py' \
140+
'ipympl'\
141+
'ipywidgets' \
142+
'matplotlib-base' \
143+
'numba' \
144+
'numexpr' \
145+
'pandas' \
146+
'openpyxl' \
147+
'patsy' \
148+
'protobuf' \
149+
'pytables' \
150+
'scikit-image' \
151+
'scikit-learn' \
152+
'scipy' \
153+
'seaborn' \
154+
'sqlalchemy' \
155+
'statsmodels' \
156+
'sympy' \
157+
'widgetsnbextension'\
158+
'xlrd' \
159+
'meson' \
160+
'spglib' && \
161+
mamba clean --all -f -y && \
162+
fix-permissions "${CONDA_DIR}" && \
163+
fix-permissions "/home/${NB_USER}"
164+
165+
# Import matplotlib the first time to build the font cache.
166+
ENV XDG_CACHE_HOME="/home/${NB_USER}/.cache/"
167+
168+
RUN MPLBACKEND=Agg python -c "import matplotlib.pyplot" && \
169+
fix-permissions "/home/${NB_USER}"
170+
171+
USER root
172+
173+
RUN apt -y update && apt -y upgrade\
174+
&& apt install -y git pkg-config cmake && \
175+
apt clean && rm -rf /var/lib/apt/lists/*
176+
177+
RUN chown -R $NB_UID:$NB_GID $HOME
178+
179+
COPY --chown=$NB_UID:$NB_GID environment.yml /tmp
180+
USER $NB_USER
181+
RUN . /opt/conda/bin/activate && \
182+
mamba env update --quiet --file /tmp/environment.yml && \
183+
mamba clean --all -f -y && \
184+
rm -rf "/home/${NB_USER}/.cache"
185+
186+
187+
WORKDIR "${HOME}"

containers/environment.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
channels:
2+
- conda-forge
3+
- nodefaults
4+
dependencies:
5+
- pip
6+
- pip:
7+
- git+https://github.com/imagdau/aseMolec@main
8+
- skmatter
9+
- pymatgen
10+
- tqdm
11+
- pack-mm
12+
- 'janus-core[all]@git+https://github.com/stfc/janus-core.git@main'
13+
- git+https://github.com/ChengUCB/les.git
14+
# - git+https://github.com/ACEsuit/mace.git@develop
15+
- torch-dftd
16+
# - git+https://github.com/CheukHinHoJerry/torch-dftd.git
17+
- cuequivariance==0.5.1
18+
- cuequivariance-torch==0.5.1
19+
- cuequivariance-ops-torch-cu12==0.5.1
20+
- torchvision
21+
- weas-widget
22+
- seaborn
23+
- data-tutorials
24+
- opentsne

containers/fix-permissions

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
# set permissions on a directory
3+
# after any installation, if a directory needs to be (human) user-writable,
4+
# run this script on it.
5+
# It will make everything in the directory owned by the group ${NB_GID}
6+
# and writable by that group.
7+
# Deployments that want to set a specific user id can preserve permissions
8+
# by adding the `--group-add users` line to `docker run`.
9+
10+
# uses find to avoid touching files that already have the right permissions,
11+
# which would cause massive image explosion
12+
13+
# right permissions are:
14+
# group=${NB_GID}
15+
# AND permissions include group rwX (directory-execute)
16+
# AND directories have setuid,setgid bits set
17+
18+
set -e
19+
20+
for d in "$@"; do
21+
find "${d}" \
22+
! \( \
23+
-group "${NB_GID}" \
24+
-a -perm -g+rwX \
25+
\) \
26+
-exec chgrp "${NB_GID}" {} \; \
27+
-exec chmod g+rwX {} \;
28+
# setuid, setgid *on directories only*
29+
find "${d}" \
30+
\( \
31+
-type d \
32+
-a ! -perm -6000 \
33+
\) \
34+
-exec chmod +6000 {} \;
35+
done

0 commit comments

Comments
 (0)