forked from underworldcode/underworld2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile.openmpi
93 lines (79 loc) · 2.6 KB
/
Dockerfile.openmpi
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
#####################################################################
# Multi stage Dockerfile structure:
# 1. runtime
# 2. build
# 3. final == runtime + min. build
#
# It begins with layers for runtime execution.
# The runtime environment (packages, permissions, ENV vars.)
# are consistent accross all layer of this Dockerfile.
# The build layer takes the runtime layer and builds the software
# stack in /usr/local.
# The final image is a composite of the runtime layer and
# minimal sections of the build layer.
#####################################################################
# https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
ARG OMPI_VERSION=4.1.4
ARG PYTHON_VERSION="3.12"
ARG BASE_IMAGE="python:$PYTHON_VERSION-slim-bookworm"
FROM ${BASE_IMAGE} as runtime
LABEL maintainer="https://github.com/underworldcode/"
################
## 1. Runtime ##
################
# Dockerfile ENV vars - for all image stages
ENV LANG=C.UTF-8
# openmpi lib will be install at /usr/local/lib
ENV LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
# add user jovyan
ENV NB_USER jovyan
ENV NB_HOME /home/$NB_USER
RUN useradd -m -s /bin/bash -N $NB_USER
# install runtime packages
RUN apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
ssh \
bash \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
################
## 2. Build ##
################
FROM runtime as build
# Build options for for openmpi
ARG OMPI_VERSION
ARG OMPI_MAJOR_VERSION="v4.1"
ARG OMPI_CONFIGURE_OPTIONS="--prefix=/usr/local"
ARG OMPI_MAKE_OPTIONS="-j4"
# apt get install dependency packages
RUN apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
wget \
gcc \
gfortran \
g++ \
make \
file \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# build mpi and remove tarball at the end
RUN mkdir -p /tmp/src
WORKDIR /tmp/src
RUN wget https://download.open-mpi.org/release/open-mpi/${OMPI_MAJOR_VERSION}/openmpi-${OMPI_VERSION}.tar.gz --no-check-certificate \
&& tar -zxf openmpi-${OMPI_VERSION}.tar.gz
WORKDIR /tmp/src/openmpi-${OMPI_VERSION}
RUN ./configure ${OMPI_CONFIGURE_OPTIONS} \
&& make ${OMPI_MAKE_OPTIONS} \
&& make install \
&& rm -rf /tmp/src/
# record build packages used
RUN apt-mark showmanual > /opt/installed.txt
################
## 2. Final ##
################
FROM runtime as final
COPY --from=build /usr/local /usr/local
COPY --from=build /opt/installed.txt /opt/installed.txt
# switch to user and workspace
WORKDIR $NB_HOME
USER $NB_USER