1+ # Set environment variables during runtime.
2+ ARG CUDA_VER
3+ ARG DISTRO_ARCH
4+ ARG DISTRO_VER
5+ ARG DISTRO_NAME
6+ FROM --platform=linux/${DISTRO_ARCH} nvidia/cuda:${CUDA_VER}-devel-${DISTRO_NAME}${DISTRO_VER} as conda
7+
8+ # Set `ARG`s during runtime.
9+ ARG CUDA_VER
10+ ARG DISTRO_ARCH
11+ ARG DISTRO_VER
12+ ARG DISTRO_NAME
13+ ENV CUDA_VER=${CUDA_VER} \
14+ DISTRO_ARCH=${DISTRO_ARCH} \
15+ DISTRO_NAME=${DISTRO_NAME} \
16+ DISTRO_VER=${DISTRO_VER}
17+
18+ # Set an encoding to make things work smoothly.
19+ ENV LANG en_US.UTF-8
20+ ENV LANGUAGE en_US.UTF-8
21+
22+ # Set path to CUDA install (this is a symlink to /usr/local/cuda-${CUDA_VER})
23+ ENV CUDA_HOME /usr/local/cuda
24+
25+ # bust the docker cache so that we always rerun the installs below
26+ ADD https://loripsum.net/api /opt/docker/etc/gibberish
27+
28+ # Add qemu in here so that we can use this image on regular linux hosts with qemu user installed
29+ # ADD qemu-aarch64-static /usr/bin/qemu-aarch64-static
30+ # ADD qemu-ppc64le-static /usr/bin/qemu-ppc64le-static
31+
32+ # we want to persist a path in ldconfig (to avoid having to always set LD_LIBRARY_PATH), but *after* the existing entries;
33+ # since entries in ld.so.conf.d have precedence before the preconfigured directories, we first add the latter to the former
34+ # the upstream images all have libcuda.so under $CUDA_HOME/compat;
35+ # add this to the ldconfig so it will be found correctly.
36+ # don't forget to update settings by running ldconfig
37+ RUN ldconfig -v 2>/dev/null | grep -v ^$'\t ' | cut -f1 -d":" >> /etc/ld.so.conf.d/cuda-$CUDA_VER.conf && \
38+ echo "$CUDA_HOME/compat" >> /etc/ld.so.conf.d/cuda-$CUDA_VER.conf && \
39+ ldconfig
40+
41+ # Add the archived repo URL and fix RPM imports
42+ # ADD rpm-repos /tmp/rpm-repos
43+ # ADD fix_rpm /opt/docker/bin/fix_rpm
44+ # RUN chmod +x /opt/docker/bin/fix_rpm
45+ # RUN /opt/docker/bin/fix_rpm
46+
47+ # Remove preinclude system compilers
48+ RUN apt-get remove -y --purge gcc g++
49+
50+ # Install basic requirements.
51+ # NOTE: this fixes the cuda version.
52+ RUN apt-get update && \
53+ converted=$(echo "$CUDA_VER" | awk -F. '{print $1 "-" $2}' ) && \
54+ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
55+ bzip2 \
56+ sudo \
57+ tar \
58+ curl \
59+ cuda-compiler-${converted} \
60+ && \
61+ apt-get clean && \
62+ rm -rf /var/lib/apt/lists/*
63+
64+ # Run common commands
65+ COPY run_commands /opt/docker/bin/run_commands
66+ RUN chmod +x /opt/docker/bin/run_commands
67+ RUN /opt/docker/bin/run_commands
68+
69+ # Download and cache CUDA related packages.
70+ RUN . /opt/conda/etc/profile.d/conda.sh && \
71+ conda activate && \
72+ conda create -n test --yes --quiet --download-only && \
73+ conda clean -tiy && \
74+ chgrp -R lucky /opt/conda && \
75+ chmod -R g=u /opt/conda
76+
77+ # Add a file for users to source to activate the `conda`
78+ # environment `base`. Also add a file that wraps that for
79+ # use with the `ENTRYPOINT`.
80+ COPY entrypoint_source /opt/docker/bin/entrypoint_source
81+ RUN chmod +x /opt/docker/bin/entrypoint_source
82+ COPY entrypoint /opt/docker/bin/entrypoint
83+ RUN chmod +x /opt/docker/bin/entrypoint
84+
85+ FROM conda AS build
86+
87+ ARG NAMD_OPTS=""
88+
89+ COPY . .
90+ RUN . /opt/conda/etc/profile.d/conda.sh && conda env create --file env.yaml
91+ RUN chmod +x install_namd.sh
92+ RUN --mount=type=secret,id=NAMD_ACCESS_TOKEN \
93+ . /opt/conda/etc/profile.d/conda.sh && conda activate env && ./install_namd.sh "$NAMD_OPTS"
94+
95+ # Delete the heavy environment but keep conda binaries
96+ RUN . /opt/conda/etc/profile.d/conda.sh && conda remove -n env --all -y
97+ RUN . /opt/conda/etc/profile.d/conda.sh && conda clean -a -y
98+
99+ ARG CUDA_VER
100+ ARG DISTRO_ARCH
101+ ARG DISTRO_VER
102+ ARG DISTRO_NAME
103+ # CUDA toolkit is massive, so use a smaller image for the runtime
104+ FROM --platform=linux/${DISTRO_ARCH} nvidia/cuda:${CUDA_VER}-runtime-${DISTRO_NAME}${DISTRO_VER}
105+
106+ ENV LANG en_US.UTF-8
107+ ENV LANGUAGE en_US.UTF-8
108+
109+ COPY . .
110+
111+ RUN apt-get update && \
112+ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
113+ curl \
114+ ca-certificates
115+
116+ RUN update-ca-certificates
117+
118+ COPY --from=build /opt/docker/bin/run_commands /opt/docker/bin/run_commands
119+ RUN /opt/docker/bin/run_commands
120+
121+ COPY --from=build /opt/docker/bin/entrypoint /opt/docker/bin/entrypoint
122+ COPY --from=build /opt/docker/bin/entrypoint_source /opt/docker/bin/entrypoint_source
123+
124+ # Create the new lightweight env
125+ RUN . /opt/conda/etc/profile.d/conda.sh && conda env create --file runtime_env.yaml
126+
127+ COPY --from=build /opt/namd-build /opt/namd-build
128+ RUN ln -s /opt/namd-build/namd3 /bin/namd3
129+
130+ # Ensure that all containers start with tini and the user selected process.
131+ # Activate the `conda` environment `base`.
132+ # Provide a default command (`bash`), which will start if the user doesn't specify one.
133+ ENTRYPOINT [ "/opt/conda/bin/tini" , "--" , "/opt/docker/bin/entrypoint" ]
134+ CMD [ "/bin/bash" ]
0 commit comments