Skip to content

Commit

Permalink
Big update of Dockersfiles
Browse files Browse the repository at this point in the history
- More automation of versioning in `docker-build.sh`
- Moving to Ubuntu 24.04 as base OS
- Update to petsc 3.22.2
- using `podman` instead of `docker`
  • Loading branch information
julesghub committed Dec 5, 2024
1 parent 1a95217 commit 803e2a0
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 58 deletions.
4 changes: 2 additions & 2 deletions docs/development/docker/base/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM ubuntu:22.04 as base_runtime
FROM ubuntu:24.04 as base_runtime
LABEL maintainer="https://github.com/underworldcode/"
ENV LANG=C.UTF-8
ENV PYVER=3.10
ENV PYVER=3.12
# Setup some things in anticipation of virtualenvs
ENV VIRTUAL_ENV=/opt/venv
# The following ensures that the venv takes precedence if available
Expand Down
42 changes: 31 additions & 11 deletions docs/development/docker/docker-builder.sh
Original file line number Diff line number Diff line change
@@ -1,35 +1,55 @@
#!/usr/bin/bash
#!/usr/bin/env bash

set -e


# Example Usage:
# - Run from underworld2 repository head
# - mpi and lavavu dockers are automatically generated via github actions
# - petsc and underworld2 must be created by runn the following script.

UBUNTU_VERSION=24.04
PYTHON_VERSION=3.12
OMPI_VERSION=4.1.4
PETSC_VERSION=3.22.2

ARCH=$(uname -m)
echo "Will build docker image locally for architecture type: $ARCH"
echo "************************************************************\n"

# Get the ubuntu image
docker pull ubuntu:22.04
podman pull ubuntu:$UBUNTU_VERSION

## The mpi and lavavu images should be automatically made via github actions
docker build . -f ./docs/development/docker/mpi/Dockerfile.openmpi -t underworldcode/openmpi:4.1.4-$ARCH
docker build . -f ./docs/development/docker/lavavu/Dockerfile -t underworldcode/lavavu:$ARCH
podman build . \
-f ./docs/development/docker/mpi/Dockerfile.openmpi \
--build-arg UBUNTU_VERSION=$UBUNTU_VERSION \
--build-arg OMPI_VERSION=$OMPI_VERSION \
-t underworldcode/openmpi:$OMPI_VERSION-$ARCH

podman build \
-f ./docs/development/docker/lavavu/Dockerfile \
--build-arg UBUNTU_VERSION=$UBUNTU_VERSION \
--build-arg PYTHON_VERSION=$PYTHON_VERSION \
-t underworldcode/lavavu:$ARCH \
.

docker build . \
podman build \
-f ./docs/development/docker/petsc/Dockerfile \
--build-arg MPI_IMAGE="underworldcode/openmpi:4.1.4-$ARCH" \
-t underworldcode/petsc:3.19.4-$ARCH
--build-arg UBUNTU_VERSION=$UBUNTU_VERSION \
--build-arg PYTHON_VERSION=$PYTHON_VERSION \
--build-arg PETSC_VERSION=$PETSC_VERSION \
-t underworldcode/petsc:$PETSC_VERSION-$ARCH \
.

## don't use pull here as we want the petsc image above
docker build . \
--build-arg PETSC_IMAGE="underworldcode/petsc:3.19.4-$ARCH" \
### don't use pull here as we want the petsc image above
podman build . \
--build-arg UBUNTU_VERSION=$UBUNTU_VERSION \
--build-arg PYTHON_VERSION=$PYTHON_VERSION \
--build-arg PETSC_IMAGE="underworldcode/petsc:$PETSC_VERSION-$ARCH" \
--build-arg LAVAVU_IMAGE="underworldcode/lavavu:$ARCH" \
-f ./docs/development/docker/underworld2/Dockerfile \
-t underworldcode/underworld2:2.15.1b-$ARCH
-t underworldcode/underworld2:2.16.0b-$ARCH


#docker push underworldcode/petsc:3.19.4-$ARCH
Expand Down
52 changes: 34 additions & 18 deletions docs/development/docker/lavavu/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
FROM ubuntu:22.04 as base_runtime
ARG UBUNTU_VERSION="24.04"
ARG PYTHON_VERSION="3.12"

FROM ubuntu:${UBUNTU_VERSION} as base_runtime
LABEL maintainer="https://github.com/underworldcode/"

# need to repeat ARGS after every FROM
ARG UBUNTU_VERSION
ARG PYTHON_VERSION

ENV LANG=C.UTF-8
ENV PYVER=3.10
ENV PYVER=${PYTHON_VERSION}

# Setup some things in anticipation of virtualenvs
ENV VIRTUAL_ENV=/opt/venv
# The following ensures that the venv takes precedence if available
Expand All @@ -28,28 +37,32 @@ RUN apt-get update -qq \
python3-venv \
python3-pip \
python3-numpy \
libpng16-16 \
libpng16-16t64 \
libjpeg8 \
libtiff5 \
libglu1-mesa \
libtiff-dev \
libglu1-mesa-dev \
libosmesa6 \
libavcodec58 \
libavformat58 \
libavutil56 \
libswscale5 \
zlib1g \
libavcodec-dev \
libavformat-dev \
libavutil-dev \
libswscale-dev \
zlib1g-dev \
libopenblas0 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*


FROM base_runtime AS build_base
# FROM base_runtime AS build_base

ARG UBUNTU_VERSION
ARG PYTHON_VERSION

# install build requirements
RUN apt-get update -qq
RUN DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
build-essential \
python3-setuptools \
libpython${PYVER}-dev \
libpython${PYTHON_VERSION}-dev \
libpng-dev \
libjpeg-dev \
libtiff-dev \
Expand All @@ -65,8 +78,13 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
libopenblas-dev \
libz-dev \
gcc \
python3-dev
python3-full


# lavavu
# create a virtualenv to put new python modules
USER $NB_USER
RUN /usr/bin/python3 -m venv --system-site-packages ${VIRTUAL_ENV}
RUN pip3 install -U setuptools \
&& pip3 install --no-cache-dir \
packaging \
Expand All @@ -75,11 +93,9 @@ RUN pip3 install -U setuptools \
pillow \
ipython

# lavavu
# create a virtualenv to put new python modules
USER $NB_USER
RUN /usr/bin/python3 -m venv --system-site-packages ${VIRTUAL_ENV}
RUN LV_OSMESA=1 pip3 install --no-cache-dir --no-binary=lavavu lavavu
#RUN LV_OSMESA=1 pip3 install --no-cache-dir lavavu #--no-binary=lavavu lavavu

RUN pip3 install --no-cache-dir lavavu-osmesa

FROM base_runtime AS minimal
COPY --from=build_base $VIRTUAL_ENV $VIRTUAL_ENV
Expand Down
3 changes: 2 additions & 1 deletion docs/development/docker/mpi/Dockerfile.mpich
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
#####################################################################

ARG MPICH_VERSION="3.4.3"
ARG UBUNTU_VERSION="24.04"

FROM ubuntu:22.04 as runtime
FROM ubuntu:${UBUNTU_VERSION} as runtime
LABEL maintainer="https://github.com/underworldcode/"

################
Expand Down
3 changes: 2 additions & 1 deletion docs/development/docker/mpi/Dockerfile.openmpi
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@

# https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
ARG OMPI_VERSION=4.1.4
ARG UBUNTU_VERSION=24.04

FROM ubuntu:22.04 as runtime
FROM ubuntu:${UBUNTU_VERSION} as runtime
LABEL maintainer="https://github.com/underworldcode/"

################
Expand Down
27 changes: 18 additions & 9 deletions docs/development/docker/petsc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,26 @@
#####################################################################

ARG MPI_IMAGE="underworldcode/openmpi:4.1.4"
ARG UBUNTU_VERSION="24.02"
ARG PYTHON_VERSION="3.12"

FROM ${MPI_IMAGE} as mpi-image

FROM ubuntu:22.04 as runtime
FROM ubuntu:${UBUNTU_VERSION} as runtime
LABEL maintainer="https://github.com/underworldcode/"

# need to repeat ARGS after every FROM
ARG UBUNTU_VERSION
ARG PYTHON_VERSION

#### Dockerfile ENV vars - for all image stages
ENV LANG=C.UTF-8
# mpi lib will be install at /usr/local/lib
ENV LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

# python env vars.
# prepappending on PATH means all pip install will goto the PYOPT
ENV PYVER=3.10
ENV PYVER=${PYTHON_VERSION}
ENV PYOPT=/opt/venv
ENV PATH=$PYOPT/bin:$PATH
ENV PYTHONPATH=$PYTHONPATH:$PYOPT/lib/python${PYVER}/site-packages
Expand All @@ -43,8 +49,8 @@ RUN apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
bash-completion \
ssh \
libopenblas-base \
python3-venv \
libopenblas0 \
python3-full \
python3-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
Expand All @@ -57,6 +63,9 @@ RUN python3 -m venv $PYOPT \

FROM runtime as build

ARG UBUNTU_VERSION
ARG PYTHON_VERSION

RUN apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
ca-certificates \
Expand All @@ -80,15 +89,15 @@ RUN apt-get update -qq \
&& rm -rf /var/lib/apt/lists/*

RUN pip3 install --no-cache-dir \
cython==0.29.36 \
numpy \
mpi4py
cython \
mpi4py \
'numpy<2'

# get petsc
ARG PETSC_VERSION="3.19.4"
ARG PETSC_VERSION="3.22.2"
RUN mkdir -p /tmp/src
WORKDIR /tmp/src
RUN wget http://ftp.mcs.anl.gov/pub/petsc/release-snapshots/petsc-lite-${PETSC_VERSION}.tar.gz --no-check-certificate \
RUN wget https://web.cels.anl.gov/projects/petsc/download/release-snapshots/petsc-lite-${PETSC_VERSION}.tar.gz --no-check-certificate \
&& tar -zxf petsc-lite-${PETSC_VERSION}.tar.gz
WORKDIR /tmp/src/petsc-${PETSC_VERSION}

Expand Down
47 changes: 31 additions & 16 deletions docs/development/docker/underworld2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,35 @@
# minimal sections of the build layer.
#####################################################################

# PETSC_VERSION passed in via --build-args
# The following are passed in via --build-args
# Used for github actions on the underworld repo
# Must go before the 1st FROM see
# https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
ARG PETSC_IMAGE="underworldcode/petsc:3.19.4"
ARG PETSC_IMAGE="underworldcode/petsc:3.22.2"
ARG LAVAVU_IMAGE="none"
ARG UBUNTU_VERSION="24.02"
ARG PYTHON_VERSION="3.12"

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

FROM ubuntu:22.04 as runtime
FROM ${LAVAVU_IMAGE} as lavavu-image

FROM ubuntu:${UBUNTU_VERSION} as runtime
LABEL maintainer="https://github.com/underworldcode/"

# need to repeat ARGS after every FROM
ARG UBUNTU_VERSION
ARG PYTHON_VERSION

#### Dockerfile ENV vars - for all image stages
ENV LANG=C.UTF-8
# mpi lib will be install at /usr/local/lib
ENV LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

# python env vars.
# prepappending on PATH means all pip install will goto the PYOPT
ENV PYVER=3.10
ENV PYVER=${PYTHON_VERSION}
ENV PYOPT=/opt/venv
ENV PATH=$PYOPT/bin:$PATH
ENV PYTHONPATH=$PYTHONPATH:$PYOPT/lib/python${PYVER}/site-packages
Expand All @@ -52,21 +62,21 @@ RUN apt-get update -qq \
ssh \
python3-venv \
python3-dev \
libopenblas-base \
python3-venv \
libopenblas0 \
python3-full \
libxml2 \
vim \
git \
gdb \
libpng16-16 \
libpng16-16t64 \
libjpeg8 \
libtiff5 \
libtiff-dev \
libglu1-mesa \
libosmesa6 \
libavcodec58 \
libavformat58 \
libavutil56 \
libswscale5 \
libavcodec60 \
libavformat60 \
libavutil58 \
libswscale7 \
zlib1g \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
Expand All @@ -78,6 +88,9 @@ RUN python3 -m venv $PYOPT \

FROM runtime as build

ARG UBUNTU_VERSION
ARG PYTHON_VERSION

# install build packages
RUN apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
Expand Down Expand Up @@ -106,8 +119,8 @@ RUN pip3 install setuptools --force-reinstall --no-cache \
tabulate

# Lets grab lavavu & requirements
COPY --from=underworldcode/lavavu /opt /opt
COPY --from=underworldcode/lavavu /usr/local /usr/local
COPY --from=lavavu-image /opt /opt
COPY --from=lavavu-image /usr/local /usr/local
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends $(awk '{print $1'} /opt/installed.txt) \
&& apt-get clean \
Expand All @@ -129,8 +142,7 @@ WORKDIR /tmp/underworld2
RUN pip3 install -vvv .
RUN pip3 install setuptools --force-reinstall --no-cache-dir \
&& pip3 install --no-cache-dir \
git+https://github.com/drufat/triangle.git \
git+https://github.com/badlands-model/badlands.git@6ec949472ddd4c012d8694ce5f994b37ef143029#subdirectory=badlands \
"badlands @ git+https://github.com/julesghub/badlands.git@julesghub/meson-build#subdirectory=badlands" \
jupyter_contrib_nbextensions

RUN pip3 freeze >/opt/requirements.txt
Expand All @@ -141,6 +153,9 @@ RUN apt-mark showmanual >/opt/installed.txt
# Build the final image, a combination of the runtime and build stages
FROM runtime as final

ARG UBUNTU_VERSION
ARG PYTHON_VERSION

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

Expand Down

0 comments on commit 803e2a0

Please sign in to comment.