Skip to content

Commit d295da7

Browse files
authored
Merge pull request #26 from Becksteinlab/develop
NAMD workflow
2 parents 499de2b + 0abde6f commit d295da7

16 files changed

+627
-8
lines changed

.github/workflows/ci.yaml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ on:
55
pull_request:
66
branches: ['main']
77

8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: ${{ github.repository }}
811

912
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
1013
jobs:
@@ -13,7 +16,7 @@ jobs:
1316
strategy:
1417
matrix:
1518
arch: [amd64]
16-
build: ["Common-CPU", "Common-GPU"]
19+
build: ["common-cpu", "common-gpu"]
1720

1821
permissions:
1922
contents: read
@@ -34,13 +37,15 @@ jobs:
3437
- name: Option
3538
id: option
3639
run: |
37-
if [ "${{ matrix.build }}" == "Common-CPU" ]; then
40+
if [ "${{ matrix.build }}" == "common-cpu" ]; then
3841
echo GMX_OPTS= >> $GITHUB_ENV
3942
echo LMP_OPTS= >> $GITHUB_ENV
43+
echo NAMD_OPTS= >> $GITHUB_ENV
4044
echo DOCKERFILE="CPU.Dockerfile" >> $GITHUB_ENV
4145
else
4246
echo GMX_OPTS="-DGMX_GPU=CUDA" >> $GITHUB_ENV
4347
echo LMP_OPTS="-DPKG_GPU=on -DGPU_API=cuda" >> $GITHUB_ENV
48+
echo NAMD_OPTS="--with-cuda" >> $GITHUB_ENV
4449
echo DOCKERFILE="GPU.Dockerfile" >> $GITHUB_ENV
4550
fi
4651
@@ -56,4 +61,19 @@ jobs:
5661
CUDA_VER=12.4.1
5762
DISTRO_ARCH=${{ matrix.arch }}
5863
DISTRO_VER=22.04
59-
DISTRO_NAME=ubuntu
64+
DISTRO_NAME=ubuntu
65+
66+
- name: Build and push private NAMD Docker image
67+
uses: docker/build-push-action@v5
68+
with:
69+
context: ./docker/namd
70+
file: ./docker/namd/${{ env.DOCKERFILE }}
71+
push: false
72+
build-args: |
73+
NAMD_OPTS="${{ env.NAMD_OPTS }}"
74+
CUDA_VER=12.4.1
75+
DISTRO_ARCH=${{ matrix.arch }}
76+
DISTRO_VER=22.04
77+
DISTRO_NAME=ubuntu
78+
secrets: |
79+
NAMD_ACCESS_TOKEN=${{ secrets.NAMD_ACCESS_TOKEN }}

.github/workflows/deploy_docker.yaml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
strategy:
1919
matrix:
2020
arch: [amd64]
21-
build: ["Common-CPU", "Common-GPU"]
21+
build: ["common-cpu", "common-gpu"]
2222

2323
permissions:
2424
contents: read
@@ -47,13 +47,15 @@ jobs:
4747
- name: Option
4848
id: option
4949
run: |
50-
if [ "${{ matrix.build }}" == "Common-CPU" ]; then
50+
if [ "${{ matrix.build }}" == "common-cpu" ]; then
5151
echo GMX_OPTS= >> $GITHUB_ENV
5252
echo LMP_OPTS= >> $GITHUB_ENV
53+
echo NAMD_OPTS= >> $GITHUB_ENV
5354
echo DOCKERFILE="CPU.Dockerfile" >> $GITHUB_ENV
5455
else
5556
echo GMX_OPTS="-DGMX_GPU=CUDA" >> $GITHUB_ENV
5657
echo LMP_OPTS="-DPKG_GPU=on -DGPU_API=cuda" >> $GITHUB_ENV
58+
echo NAMD_OPTS="--with-cuda" >> $GITHUB_ENV
5759
echo DOCKERFILE="GPU.Dockerfile" >> $GITHUB_ENV
5860
fi
5961
@@ -77,4 +79,21 @@ jobs:
7779
CUDA_VER=12.4.1
7880
DISTRO_ARCH=${{ matrix.arch }}
7981
DISTRO_VER=22.04
80-
DISTRO_NAME=ubuntu
82+
DISTRO_NAME=ubuntu
83+
84+
- name: Build and push private NAMD Docker image
85+
uses: docker/build-push-action@v5
86+
with:
87+
context: ./docker/namd
88+
file: ./docker/namd/${{ env.DOCKERFILE }}
89+
push: true
90+
tags: ghcr.io/becksteinlab/streaming-namd-docker:main-${{ matrix.build }}
91+
labels: ${{ steps.meta.outputs.labels }}
92+
build-args: |
93+
NAMD_OPTS="${{ env.NAMD_OPTS }}"
94+
CUDA_VER=12.4.1
95+
DISTRO_ARCH=${{ matrix.arch }}
96+
DISTRO_VER=22.04
97+
DISTRO_NAME=ubuntu
98+
secrets: |
99+
NAMD_ACCESS_TOKEN=${{ secrets.NAMD_ACCESS_TOKEN }}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ docker run -it --runtime=nvidia --gpus=all streaming_md_docker_local
5050
We publish prebuilt images using CI at `ghcr.io`. Pull the latest image using:
5151

5252
```bash
53-
docker pull ghcr.io/becksteinlab/streaming-md-docker:main-Common-GPU
53+
docker pull ghcr.io/becksteinlab/streaming-md-docker:main-common-gpu
5454
```
5555

5656
```bash
57-
docker run -it --runtime=nvidia --gpus=all ghcr.io/becksteinlab/streaming-md-docker:main-Common-GPU
57+
docker run -it --runtime=nvidia --gpus=all ghcr.io/becksteinlab/streaming-md-docker:main-common-gpu
5858
```
5959

docker/namd/CPU.Dockerfile

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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+
RUN apt-get update && \
52+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
53+
bzip2 \
54+
sudo \
55+
tar \
56+
curl \
57+
&& \
58+
apt-get clean && \
59+
rm -rf /var/lib/apt/lists/*
60+
61+
# Run common commands
62+
COPY run_commands /opt/docker/bin/run_commands
63+
RUN chmod +x /opt/docker/bin/run_commands
64+
RUN /opt/docker/bin/run_commands
65+
66+
# Download and cache CUDA related packages.
67+
RUN . /opt/conda/etc/profile.d/conda.sh && \
68+
conda activate && \
69+
conda create -n test --yes --quiet --download-only && \
70+
conda clean -tiy && \
71+
chgrp -R lucky /opt/conda && \
72+
chmod -R g=u /opt/conda
73+
74+
# Add a file for users to source to activate the `conda`
75+
# environment `base`. Also add a file that wraps that for
76+
# use with the `ENTRYPOINT`.
77+
COPY entrypoint_source /opt/docker/bin/entrypoint_source
78+
RUN chmod +x /opt/docker/bin/entrypoint_source
79+
COPY entrypoint /opt/docker/bin/entrypoint
80+
RUN chmod +x /opt/docker/bin/entrypoint
81+
82+
FROM conda AS build
83+
84+
ARG NAMD_OPTS=""
85+
86+
COPY . .
87+
RUN . /opt/conda/etc/profile.d/conda.sh && conda env create --file env.yaml
88+
RUN chmod +x install_namd.sh
89+
RUN --mount=type=secret,id=NAMD_ACCESS_TOKEN \
90+
. /opt/conda/etc/profile.d/conda.sh && conda activate env && ./install_namd.sh "$NAMD_OPTS"
91+
92+
# Delete the heavy environment but keep conda binaries
93+
RUN . /opt/conda/etc/profile.d/conda.sh && conda remove -n env --all -y
94+
RUN . /opt/conda/etc/profile.d/conda.sh && conda clean -a -y
95+
96+
ARG CUDA_VER
97+
ARG DISTRO_ARCH
98+
ARG DISTRO_VER
99+
ARG DISTRO_NAME
100+
# CUDA toolkit is massive, so use a smaller image for the runtime
101+
FROM --platform=linux/${DISTRO_ARCH} ${DISTRO_NAME}:${DISTRO_VER}
102+
103+
ENV LANG en_US.UTF-8
104+
ENV LANGUAGE en_US.UTF-8
105+
106+
COPY . .
107+
108+
RUN apt-get update && \
109+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
110+
curl \
111+
ca-certificates
112+
113+
RUN update-ca-certificates
114+
115+
COPY --from=build /opt/docker/bin/run_commands /opt/docker/bin/run_commands
116+
RUN /opt/docker/bin/run_commands
117+
118+
COPY --from=build /opt/docker/bin/entrypoint /opt/docker/bin/entrypoint
119+
COPY --from=build /opt/docker/bin/entrypoint_source /opt/docker/bin/entrypoint_source
120+
121+
# Create the new lightweight env
122+
RUN . /opt/conda/etc/profile.d/conda.sh && conda env create --file runtime_env.yaml
123+
124+
COPY --from=build /opt/namd-build /opt/namd-build
125+
RUN ln -s /opt/namd-build/namd3 /bin/namd3
126+
127+
# Ensure that all containers start with tini and the user selected process.
128+
# Activate the `conda` environment `base`.
129+
# Provide a default command (`bash`), which will start if the user doesn't specify one.
130+
ENTRYPOINT [ "/opt/conda/bin/tini", "--", "/opt/docker/bin/entrypoint" ]
131+
CMD [ "/bin/bash" ]

docker/namd/GPU.Dockerfile

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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" ]

docker/namd/TMP.Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM alpine:latest
2+
RUN apk add --no-cache bash
3+
CMD ["bash"]

0 commit comments

Comments
 (0)