Skip to content

Commit 8048d4c

Browse files
committed
Update dockerfiles
- Rebase to a python image based on Debian bookworm - Update runtime requirements (mainly for lavavu) - Modify bash script to allow switching between mpi implementation & change of base image
1 parent bde07f8 commit 8048d4c

File tree

6 files changed

+121
-64
lines changed

6 files changed

+121
-64
lines changed

docs/development/docker/docker-builder.sh

+64-20
Original file line numberDiff line numberDiff line change
@@ -7,54 +7,81 @@ set -e
77
# - mpi and lavavu dockers are automatically generated via github actions
88
# - petsc and underworld2 must be created by runn the following script.
99

10-
UBUNTU_VERSION=24.04
11-
PYTHON_VERSION=3.12
10+
PYTHON_VERSION=3.11
1211
OMPI_VERSION=4.1.4
12+
MPICH_VERSION=3.4.3
1313
PETSC_VERSION=3.22.2
1414

15+
MPI_IMPLEMENTATION=opmi
16+
17+
BASE_IMAGE="python:$PYTHON_VERSION-slim-bookworm"
18+
19+
#### x86 images can be built on mac arm architecture using rosetta
1520
ARCH=$(uname -m)
16-
echo "Will build docker image locally for architecture type: $ARCH"
21+
echo "Will build docker image locally for architecture type: $ARCH, with mpi implementation: $MPI_IMPLEMENTATION"
1722
echo "************************************************************\n"
1823

19-
# Get the ubuntu image
20-
podman pull ubuntu:$UBUNTU_VERSION
24+
25+
# Get the base image
26+
podman pull $BASE_IMAGE
2127

2228
## The mpi and lavavu images should be automatically made via github actions
23-
podman build . \
24-
--rm --squash-all \
25-
-f ./docs/development/docker/mpi/Dockerfile.openmpi \
26-
--build-arg UBUNTU_VERSION=$UBUNTU_VERSION \
27-
--build-arg OMPI_VERSION=$OMPI_VERSION \
28-
-t underworldcode/openmpi:$OMPI_VERSION-$ARCH
29+
30+
if [ "$MPI_IMPLEMENTATION" = "MPICH" ]
31+
then
32+
## Default is openmpi, but can be switched to mpich
33+
podman build . \
34+
--rm --squash-all \
35+
-f ./docs/development/docker/mpi/Dockerfile.mpich \
36+
--build-arg BASE_IMAGE=$BASE_IMAGE \
37+
--build-arg PYTHON_VERSION=$PYTHON_VERSION \
38+
--build-arg MPICH_VERSION=$MPICH_VERSION \
39+
-t underworldcode/mpich:$MPICH_VERSION-$ARCH
40+
41+
MPI_IMAGE=underworldcode/mpich:$MPICH_VERSION-$ARCH
42+
mpi_lowercase="mpich"
43+
else
44+
podman build . \
45+
--rm --squash-all \
46+
-f ./docs/development/docker/mpi/Dockerfile.openmpi \
47+
--build-arg BASE_IMAGE=$BASE_IMAGE \
48+
--build-arg PYTHON_VERSION=$PYTHON_VERSION \
49+
--build-arg OMPI_VERSION=$OMPI_VERSION \
50+
-t underworldcode/openmpi:$OMPI_VERSION-$ARCH
51+
52+
MPI_IMAGE=underworldcode/openmpi:$OMPI_VERSION-$ARCH
53+
mpi_lowercase="ompi"
54+
fi
2955

3056
podman build . \
3157
--rm --squash-all \
3258
-f ./docs/development/docker/lavavu/Dockerfile \
33-
--build-arg UBUNTU_VERSION=$UBUNTU_VERSION \
59+
--build-arg BASE_IMAGE=$BASE_IMAGE \
3460
--build-arg PYTHON_VERSION=$PYTHON_VERSION \
3561
-t underworldcode/lavavu:$ARCH
3662

3763
podman build . \
3864
--rm --squash-all \
3965
-f ./docs/development/docker/petsc/Dockerfile \
40-
--build-arg MPI_IMAGE="underworldcode/openmpi:$OMPI_VERSION-$ARCH" \
41-
--build-arg UBUNTU_VERSION=$UBUNTU_VERSION \
66+
--build-arg BASE_IMAGE=$BASE_IMAGE \
67+
--build-arg MPI_IMAGE=$MPI_IMAGE \
4268
--build-arg PYTHON_VERSION=$PYTHON_VERSION \
4369
--build-arg PETSC_VERSION=$PETSC_VERSION \
44-
-t underworldcode/petsc:$PETSC_VERSION-$ARCH
70+
-t underworldcode/petsc-$mpi_lowercase:$PETSC_VERSION-$ARCH
4571

4672
### don't use pull here as we want the petsc image above
4773
podman build . \
4874
--rm --squash-all \
49-
--build-arg UBUNTU_VERSION=$UBUNTU_VERSION \
75+
--build-arg BASE_IMAGE=$BASE_IMAGE \
5076
--build-arg PYTHON_VERSION=$PYTHON_VERSION \
51-
--build-arg PETSC_IMAGE="underworldcode/petsc:$PETSC_VERSION-$ARCH" \
77+
--build-arg PETSC_IMAGE="underworldcode/petsc-$mpi_lowercase:$PETSC_VERSION-$ARCH" \
5278
--build-arg LAVAVU_IMAGE="underworldcode/lavavu:$ARCH" \
5379
-f ./docs/development/docker/underworld2/Dockerfile \
54-
-t underworldcode/underworld2:2.16.0b-$ARCH
80+
-t underworldcode/underworld2-$mpi_lowercase:2.16.0b-$ARCH
81+
5582

56-
#docker push underworldcode/petsc:3.19.4-$ARCH
57-
#docker push underworldcode/underworld2:2.15.0b-$ARCH
83+
#docker push underworldcode/petsc-$mpi_lowercase:$PETSC_VERSION-$ARCH
84+
#docker push underworldcode/underworld2-$mpi_lowercase:2.16.0b-$ARCH
5885

5986
#### if updates for both arm64 and x86_64 build manifest, ie
6087
# docker manifest create underworldcode/petsc:3.18.1 \
@@ -64,3 +91,20 @@ podman build . \
6491
# docker manifest push underworldcode/petsc:3.18.1
6592
#
6693
# in future this should be automated
94+
95+
96+
97+
## How to use image on HPC with singularity/apptainer
98+
99+
### save the docker image
100+
# podman save -o underworld2-$mpi_lowercase-2.16.0b-$ARCH.tar underworldcode/underworld2-$mpi_lowercase:2.16.0b-$ARCH
101+
### upload to hpc
102+
# scp underworld2-$mpi_lowercase-2.16.0b-$ARCH.tar user@setonix.pawsey.org.au:/path/to/store/container
103+
### extract using singularity/apptainer on HPC
104+
# module load singularity...
105+
# singularity build underworld2-mpich-2.16.0b-x86_64.sif docker-archive://underworld2-mpich-2.16.0b-x86_64.tar
106+
107+
108+
### Some good resources for using containers on HPC:
109+
# (1) checking mpi is using system install not container
110+
# https://pawseysc.github.io/containers-astro-python-workshop/3.hpc/index.html

docs/development/docker/lavavu/Dockerfile

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
ARG UBUNTU_VERSION="24.04"
21
ARG PYTHON_VERSION="3.12"
2+
ARG BASE_IMAGE="python:$PYTHON_VERSION-slim-bookworm"
33

4-
FROM ubuntu:${UBUNTU_VERSION} as base_runtime
4+
FROM ${BASE_IMAGE} as base_runtime
55
LABEL maintainer="https://github.com/underworldcode/"
66

77
# need to repeat ARGS after every FROM
8-
ARG UBUNTU_VERSION
98
ARG PYTHON_VERSION
109

1110
ENV LANG=C.UTF-8
@@ -33,11 +32,13 @@ RUN mkdir ${VIRTUAL_ENV} \
3332
# install runtime requirements
3433
RUN apt-get update -qq \
3534
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
36-
python3-minimal \
37-
python3-venv \
38-
python3-pip \
39-
libpng16-16t64 \
40-
libjpeg8 \
35+
# python3-minimal \
36+
# python3-venv \
37+
# python3-pip \
38+
# libpng16-16t64 \
39+
libpng16-16 \
40+
#libjpeg8 \
41+
libjpeg-dev \
4142
libtiff-dev \
4243
libglu1-mesa-dev \
4344
libosmesa6 \
@@ -53,15 +54,14 @@ RUN apt-get update -qq \
5354

5455
FROM base_runtime AS build_base
5556

56-
ARG UBUNTU_VERSION
5757
ARG PYTHON_VERSION
5858

5959
# install build requirements
6060
RUN apt-get update -qq
6161
RUN DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
6262
build-essential \
63-
python3-setuptools \
64-
libpython${PYTHON_VERSION}-dev \
63+
# python3-setuptools \
64+
# libpython${PYTHON_VERSION}-dev \
6565
libpng-dev \
6666
libjpeg-dev \
6767
libtiff-dev \
@@ -76,14 +76,14 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
7676
cmake \
7777
libopenblas-dev \
7878
libz-dev \
79-
gcc \
80-
python3-full
79+
gcc
80+
# python3-full
8181

8282

8383
# lavavu
8484
# create a virtualenv to put new python modules
8585
USER $NB_USER
86-
RUN /usr/bin/python3 -m venv --system-site-packages ${VIRTUAL_ENV}
86+
RUN python3 -m venv --system-site-packages ${VIRTUAL_ENV}
8787
RUN pip3 install -U setuptools \
8888
&& pip3 install --no-cache-dir \
8989
"numpy<2" \
@@ -101,7 +101,7 @@ COPY --from=build_base /usr/local /usr/local
101101
# ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/x86_64-linux-gnu/
102102
# Record Python packages, but only record system packages!
103103
# Not venv packages, which will be copied directly in.
104-
RUN PYTHONPATH= /usr/bin/pip3 freeze >/opt/requirements.txt
104+
RUN PYTHONPATH= pip3 freeze >/opt/requirements.txt
105105
# Record manually install apt packages.
106106
RUN apt-mark showmanual >/opt/installed.txt
107107

docs/development/docker/mpi/Dockerfile.mpich

+9-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
#####################################################################
1515

1616
ARG MPICH_VERSION="3.4.3"
17-
ARG UBUNTU_VERSION="24.04"
17+
ARG PYTHON_VERSION="3.12"
18+
ARG BASE_IMAGE="python:${PYTHON_VERSION}-slim-bookworm"
1819

19-
FROM ubuntu:${UBUNTU_VERSION} as runtime
20+
FROM ${BASE_IMAGE} as runtime
2021
LABEL maintainer="https://github.com/underworldcode/"
2122

2223
################
@@ -46,7 +47,12 @@ FROM runtime as build
4647

4748
ARG MPICH_VERSION
4849
# Build options for Dockerfile
49-
ARG MPICH_CONFIGURE_OPTIONS="--enable-fast=all,O3 --prefix=/usr/local --with-device=ch4:ofi FFLAGS=-fallow-argument-mismatch FCFLAGS=-fallow-argument-mismatch"
50+
# ARG MPICH_CONFIGURE_OPTIONS="--enable-fast=all,O3 --prefix=/usr/local --with-device=ch4:ofi FFLAGS=-fallow-argument-mismatch FCFLAGS=-fallow-argument-mismatch"
51+
52+
### pawsey config from pawsey base image
53+
### from https://quay.io/repository/pawsey/mpich-base/manifest/sha256:ca1cf20a4f1a8793ec794b7f927a03289f4ad449b51bc821ac98c5a269ea5e8a
54+
ARG MPICH_CONFIGURE_OPTIONS="--enable-fast=all,O3 --enable-fortran --enable-romio --prefix=/usr/local --with-device=ch4:ofi CC=gcc CXX=g++ FC=gfortran FFLAGS=-fallow-argument-mismatch"
55+
5056
ARG MPICH_MAKE_OPTIONS="-j4"
5157

5258
RUN apt-get update -qq \

docs/development/docker/mpi/Dockerfile.openmpi

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515

1616
# https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
1717
ARG OMPI_VERSION=4.1.4
18-
ARG UBUNTU_VERSION=24.04
18+
ARG PYTHON_VERSION="3.12"
19+
ARG BASE_IMAGE="python:$PYTHON_VERSION-slim-bookworm"
1920

20-
FROM ubuntu:${UBUNTU_VERSION} as runtime
21+
FROM ${BASE_IMAGE} as runtime
2122
LABEL maintainer="https://github.com/underworldcode/"
2223

2324
################

docs/development/docker/petsc/Dockerfile

+8-9
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@
1414
#####################################################################
1515

1616
ARG MPI_IMAGE="underworldcode/openmpi:4.1.4"
17-
ARG UBUNTU_VERSION="24.02"
1817
ARG PYTHON_VERSION="3.12"
18+
ARG BASE_IMAGE="python:$PYTHON_VERSION-slim-bookworm"
1919

2020
FROM ${MPI_IMAGE} as mpi-image
2121

22-
FROM ubuntu:${UBUNTU_VERSION} as runtime
22+
FROM ${BASE_IMAGE} as runtime
2323
LABEL maintainer="https://github.com/underworldcode/"
2424

2525
# need to repeat ARGS after every FROM
26-
ARG UBUNTU_VERSION
2726
ARG PYTHON_VERSION
2827

2928
#### Dockerfile ENV vars - for all image stages
@@ -50,8 +49,8 @@ RUN apt-get update -qq \
5049
bash-completion \
5150
ssh \
5251
libopenblas0 \
53-
python3-full \
54-
python3-dev \
52+
# python3-full \
53+
# python3-dev \
5554
&& apt-get clean \
5655
&& rm -rf /var/lib/apt/lists/*
5756

@@ -63,7 +62,6 @@ RUN python3 -m venv $PYOPT \
6362

6463
FROM runtime as build
6564

66-
ARG UBUNTU_VERSION
6765
ARG PYTHON_VERSION
6866

6967
RUN apt-get update -qq \
@@ -127,9 +125,10 @@ RUN PETSC_DIR=`pwd` ./configure --with-debugging=0 --prefix=/usr/local \
127125
&& make PETSC_DIR=`pwd` PETSC_ARCH=arch-linux-c-opt install \
128126
&& rm -rf /usr/local/share/petsc
129127

130-
# install h5py with MPI enabled
131-
RUN CC=mpicc HDF5_MPI="ON" HDF5_DIR=${PETSC_DIR} pip3 install --no-cache-dir --no-build-isolation --no-binary=h5py h5py \
132-
&& pip install --no-cache-dir jupyterlab
128+
### move h5py install to UW script
129+
# # install h5py with MPI enabled
130+
# RUN CC=mpicc HDF5_MPI="ON" HDF5_DIR=${PETSC_DIR} pip3 install --no-cache-dir --no-build-isolation --no-binary=h5py h5py \
131+
# && pip install --no-cache-dir jupyterlab
133132

134133
# record builder stage packages used
135134
RUN pip3 freeze > /opt/requirements.txt \

docs/development/docker/underworld2/Dockerfile

+22-15
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,18 @@
1919
# https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
2020
ARG PETSC_IMAGE="underworldcode/petsc:3.22.2"
2121
ARG LAVAVU_IMAGE="none"
22-
ARG UBUNTU_VERSION="24.02"
2322
ARG PYTHON_VERSION="3.12"
23+
ARG BASE_IMAGE="python:$PYTHON_VERSION-slim-bookworm"
2424

2525
# 'petsc-image' will be used later on in build stage COPY command
2626
FROM ${PETSC_IMAGE} as petsc-image
2727

2828
FROM ${LAVAVU_IMAGE} as lavavu-image
2929

30-
FROM ubuntu:${UBUNTU_VERSION} as runtime
30+
FROM ${BASE_IMAGE} as runtime
3131
LABEL maintainer="https://github.com/underworldcode/"
3232

3333
# need to repeat ARGS after every FROM
34-
ARG UBUNTU_VERSION
3534
ARG PYTHON_VERSION
3635

3736
#### Dockerfile ENV vars - for all image stages
@@ -60,23 +59,29 @@ RUN apt-get update -qq \
6059
ca-certificates \
6160
bash-completion \
6261
ssh \
63-
python3-venv \
64-
python3-dev \
62+
# python3-venv \
63+
# python3-dev \
6564
libopenblas0 \
66-
python3-full \
65+
# python3-full \
6766
libxml2 \
6867
vim \
6968
git \
7069
gdb \
71-
libpng16-16t64 \
72-
libjpeg8 \
70+
# libpng16-16t64 \
71+
libpng16-16 \
72+
# libjpeg8 \
73+
libjpeg-dev \
7374
libtiff-dev \
7475
libglu1-mesa \
7576
libosmesa6 \
76-
libavcodec60 \
77-
libavformat60 \
78-
libavutil58 \
79-
libswscale7 \
77+
# libavcodec60 \
78+
libavcodec-dev \
79+
# libavformat60 \
80+
libavformat-dev \
81+
# libavutil58 \
82+
libavutil-dev \
83+
# libswscale7 \
84+
libswscale-dev \
8085
zlib1g \
8186
&& apt-get clean \
8287
&& rm -rf /var/lib/apt/lists/*
@@ -88,7 +93,6 @@ RUN python3 -m venv $PYOPT \
8893

8994
FROM runtime as build
9095

91-
ARG UBUNTU_VERSION
9296
ARG PYTHON_VERSION
9397

9498
# install build packages
@@ -98,7 +102,7 @@ RUN apt-get update -qq \
98102
cmake \
99103
make \
100104
gfortran \
101-
python3-dev \
105+
# python3-dev \
102106
pkg-config \
103107
libxml2-dev \
104108
ninja-build \
@@ -138,6 +142,10 @@ RUN apt-get update \
138142
&& rm -rf /var/lib/apt/lists/*
139143
RUN pip3 install -r /opt/requirements.txt
140144

145+
# install h5py with MPI enabled
146+
RUN CC=mpicc HDF5_MPI="ON" HDF5_DIR=${PETSC_DIR} pip3 install --no-cache-dir --no-build-isolation --no-binary=h5py h5py \
147+
&& pip install --no-cache-dir jupyterlab
148+
141149
WORKDIR /tmp
142150
COPY --chown=$NB_USER:users . /tmp/underworld2
143151
WORKDIR /tmp/underworld2
@@ -156,7 +164,6 @@ RUN apt-mark showmanual >/opt/installed.txt
156164
# Build the final image, a combination of the runtime and build stages
157165
FROM runtime as final
158166

159-
ARG UBUNTU_VERSION
160167
ARG PYTHON_VERSION
161168

162169
COPY --from=build --chown=$NB_USER:users /opt /opt

0 commit comments

Comments
 (0)