This repository was archived by the owner on Aug 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile.deprecated
129 lines (107 loc) · 3.31 KB
/
Dockerfile.deprecated
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
# stage 1: build OpenMPI with GCC
ARG BASE_IMAGE="gcc"
ARG BASE_TAG="9.2.0"
FROM ${BASE_IMAGE}:${BASE_TAG} AS builder
LABEL maintainer="Wang An <[email protected]>"
USER root
# install basic buiding tools
RUN set -eu; \
\
apt-get update; \
apt-get install -y \
autoconf \
automake \
make \
wget
# stage 1.1: download OpenMPI source
ARG OMPI_VMAJOR="4.0"
ENV OMPI_VMAJOR=${OMPI_VMAJOR}
ARG OMPI_VMINOR="0"
ENV OMPI_VMINOR=${OMPI_VMINOR}
ENV OMPI_VERSION="${OMPI_VMAJOR}.${OMPI_VMINOR}"
ENV OMPI_TARBALL="openmpi-${OMPI_VERSION}.tar.gz"
WORKDIR /tmp
RUN set -eux; \
\
# checksums are not provided due to the build-time arguments OMPI_VERSION
wget "https://www.open-mpi.org/software/ompi/v${OMPI_VMAJOR}/downloads/${OMPI_TARBALL}"; \
tar -xzf ${OMPI_TARBALL}
# stage 1.2: build and install OpenMPI
ARG OMPI_OPTIONS="--enable-mpi-cxx --enable-shared"
ENV OMPI_OPTIONS=${OMPI_OPTIONS}
ENV OMPI_PREFIX="/opt/openmpi/${OMPI_VERSION}"
WORKDIR /tmp/openmpi-${OMPI_VERSION}
RUN set -eux; \
\
./configure \
--prefix=${OMPI_PREFIX} \
${OMPI_OPTIONS} \
; \
make -j "$(nproc)"; \
make install; \
\
rm -rf openmpi-${OMPI_VERSION} ${OMPI_TARBALL}
# stage 2: build the runtime environment
ARG BASE_IMAGE
ARG BASE_TAG
FROM ${BASE_IMAGE}:${BASE_TAG}
USER root
# install mpi dependencies
RUN set -eu; \
\
apt-get update; \
apt-get install -y \
openssh-server \
sudo
# define environment variables
ARG OMPI_VMAJOR="4.0"
ARG OMPI_VMINOR="0"
ENV OMPI_VERSION="${OMPI_VMAJOR}.${OMPI_VMINOR}"
ENV OMPI_PATH="/opt/openmpi/${OMPI_VERSION}"
# copy artifacts from stage 1
COPY --from=builder ${OMPI_PATH} ${OMPI_PATH}
# set environment variables for users
ENV PATH="${OMPI_PATH}/bin:${PATH}"
ENV CPATH="${OMPI_PATH}/include:${CPATH}"
ENV LIBRARY_PATH="${OMPI_PATH}/lib:${LIBRARY_PATH}"
ENV LD_LIBRARY_PATH="${OMPI_PATH}/lib:${LD_LIBRARY_PATH}"
# define environment variables
ARG GROUP_NAME
ENV GROUP_NAME=${GROUP_NAME:-mpi}
ARG GROUP_ID
ENV GROUP_ID=${GROUP_ID:-1000}
ARG USER_NAME
ENV USER_NAME=${USER_NAME:-one}
ARG USER_ID
ENV USER_ID=${USER_ID:-1000}
ENV USER_HOME="/home/${USER_NAME}"
# create the first user
RUN set -eu; \
\
groupadd -g ${GROUP_ID} ${GROUP_NAME}; \
useradd -m -G ${GROUP_NAME} -u ${USER_ID} ${USER_NAME}; \
\
echo "${USER_NAME} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
# generate ssh keys for root
RUN set -eu; \
\
ssh-keygen -f /root/.ssh/id_rsa -q -N ""; \
mkdir -p ~/.ssh/ && chmod 700 ~/.ssh/
# generate ssh keys for the newly added user
USER ${USER_NAME}
WORKDIR ${USER_HOME}
RUN set -eu; \
\
ssh-keygen -f ${USER_HOME}/.ssh/id_rsa -q -N ""; \
mkdir -p ~/.ssh/ && chmod 700 ~/.ssh/
# Build-time metadata as defined at http://label-schema.org
ARG BUILD_DATE
ARG VCS_REF
ARG VCS_URL="https://github.com/K-Wone/docker-openmpi"
LABEL org.label-schema.build-date=${BUILD_DATE} \
org.label-schema.name="OpenMPI docker image" \
org.label-schema.description="A lightweight image for GCC and OpenMPI" \
org.label-schema.license="MIT" \
org.label-schema.vcs-ref=${VCS_REF} \
org.label-schema.vcs-url=${VCS_URL} \
org.label-schema.schema-version="1.0"