Skip to content

Commit bfe679a

Browse files
committed
[UPDATE][v2.3.0] Support Apptainer (Non-Interactive Mode)!
1 parent 17344e1 commit bfe679a

10 files changed

Lines changed: 199 additions & 113 deletions

File tree

.github/workflows/cd-docker-build-push.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
dockerfile: ["Dockerfile.cuda", "Dockerfile.cpu"]
15-
install_torch: [true, false]
14+
dockerfile: [
15+
# "Dockerfile.cuda",
16+
"Dockerfile.cpu"
17+
]
18+
install_torch: [
19+
# true,
20+
false
21+
]
1622

1723
steps:
1824
- name: Free Disk Space (Ubuntu)

Dockerfile.cpu

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ARG CUDA_VERSION
22
ARG UBUNTU_VERSION
33

4-
FROM ubuntu:24.04
4+
FROM ubuntu:${UBUNTU_VERSION}
55

66
ARG DEBIAN_FRONTEND=noninteractive
77
ENV LANGUAGE=en_US.UTF-8
@@ -15,6 +15,11 @@ ARG TORCH_VERSION
1515
LABEL maintainer="JamesNULLiu jamesnulliu@gmail.com"
1616
LABEL version=${IMAGE_VERSION}
1717

18+
ENV VCPKG_ROOT=/opt/vcpkg
19+
ENV VCPKG_HOME=/opt/vcpkg
20+
ENV CONDA_HOME=/opt/miniconda3
21+
ENV ENV_SETUP_FILE=/etc/local/env_setup.sh
22+
1823
SHELL ["/bin/bash", "-c"]
1924

2025
# Some basic tools
@@ -27,8 +32,8 @@ RUN apt-get update && apt-get upgrade -y && \
2732
fc-cache -f -v
2833

2934
# Vcpkg
30-
RUN cd /usr/local && git clone https://github.com/microsoft/vcpkg.git && \
31-
cd vcpkg && ./bootstrap-vcpkg.sh
35+
RUN git clone https://github.com/microsoft/vcpkg.git ${VCPKG_HOME} && \
36+
cd ${VCPKG_HOME} && ./bootstrap-vcpkg.sh
3237

3338
# CMake
3439
RUN wget -O /tmp/kitware-archive.sh \
@@ -37,19 +42,16 @@ RUN wget -O /tmp/kitware-archive.sh \
3742
apt-get update && apt-get install -y cmake
3843

3944
# LLVM
40-
RUN wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | \
41-
tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc && \
42-
echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble main" | \
43-
tee /etc/apt/sources.list.d/llvm.list && \
44-
echo "deb-src http://apt.llvm.org/noble/ llvm-toolchain-noble main" | \
45-
tee -a /etc/apt/sources.list.d/llvm.list && \
45+
RUN wget -O /tmp/llvm.sh https://apt.llvm.org/llvm.sh && \
46+
chmod +x /tmp/llvm.sh && \
47+
/tmp/llvm.sh ${LLVM_VERSION} && \
4648
apt-get update && apt-get install -y \
47-
clang-${LLVM_VERSION} lldb-${LLVM_VERSION} \
48-
clang-tools-${LLVM_VERSION} libclang-${LLVM_VERSION}-dev \
49-
clang-format-${LLVM_VERSION} python3-clang-${LLVM_VERSION} \
50-
clangd-${LLVM_VERSION} clang-tidy-${LLVM_VERSION} \
51-
lldb-${LLVM_VERSION} libc++-${LLVM_VERSION}-dev \
52-
libc++abi-${LLVM_VERSION}-dev libomp-${LLVM_VERSION}-dev && \
49+
clang-${LLVM_VERSION} lldb-${LLVM_VERSION} \
50+
clang-tools-${LLVM_VERSION} libclang-${LLVM_VERSION}-dev \
51+
clang-format-${LLVM_VERSION} python3-clang-${LLVM_VERSION} \
52+
clangd-${LLVM_VERSION} clang-tidy-${LLVM_VERSION} \
53+
lldb-${LLVM_VERSION} libc++-${LLVM_VERSION}-dev \
54+
libc++abi-${LLVM_VERSION}-dev libomp-${LLVM_VERSION}-dev && \
5355
ln -s /usr/bin/clang-${LLVM_VERSION} /usr/bin/clang && \
5456
ln -s /usr/bin/clang++-${LLVM_VERSION} /usr/bin/clang++ && \
5557
ln -s /usr/bin/clangd-${LLVM_VERSION} /usr/bin/clangd && \
@@ -61,33 +63,43 @@ RUN wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | \
6163
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
6264

6365
# Config files
64-
COPY data/.vimrc data/.inputrc data/.bashrc data/.setup_env.sh data/.tmux.conf \
65-
/root/
66+
COPY data/vimrc /etc/vim/vimrc
67+
COPY data/env_setup.sh ${ENV_SETUP_FILE}
68+
# [TODO] The config files should not only be copied only to /root, but also to
69+
# /etc/skel, so that the new user can also use them. But in singularity,
70+
# /etc/skel has no effect, so I will decide what to do later.
71+
COPY data/.inputrc data/.bashrc data/.tmux.conf /root/
72+
COPY data/.inputrc data/.bashrc data/.tmux.conf /etc/skel/
6673

6774
# Install Miniconda3 and conda env
6875
# [TODO] Conda now uses python=3.13 in default. However, some packages (i.e.,
6976
# vllm) only support python<=3.12. That's why I install python=3.12
7077
# mannually here. Maybe some days later I will remove this command.
7178
RUN wget -O /tmp/miniconda3.sh \
7279
https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
73-
mkdir -p /root/miniconda3 && \
74-
bash /tmp/miniconda3.sh -b -u -p /root/miniconda3 && \
75-
\. /root/miniconda3/bin/activate && \
80+
mkdir -p ${CONDA_HOME} && \
81+
bash /tmp/miniconda3.sh -b -u -p ${CONDA_HOME} && \
82+
${CONDA_HOME}/bin/conda tos accept && \
83+
\. ${CONDA_HOME}/bin/activate && \
7684
conda upgrade libstdcxx-ng -c conda-forge -y && \
7785
conda install -y python=3.12 && \
7886
pip3 install nvitop --no-cache-dir && \
7987
if [[ "${INSTALL_TORCH}" == "true" ]]; then \
80-
TORCH_CU_VER=$(echo $CUDA_VERSION | cut -d'.' -f1,2 | tr -d '.') && \
81-
pip3 install torch==${TORCH_VERSION} torchvision torchaudio \
82-
--index-url https://download.pytorch.org/whl/cpu \
83-
--no-cache-dir \
88+
pip3 install torch==${TORCH_VERSION} torchvision torchaudio \
89+
--index-url https://download.pytorch.org/whl/cpu \
90+
--no-cache-dir \
8491
; fi
8592

8693
# Some final steps
8794
RUN apt-get update && apt-get upgrade -y && apt-get autoremove -y && \
8895
apt-get clean && rm -rf /var/lib/apt/lists/* && \
8996
conda clean --all -y && pip cache purge && \
90-
git config --system --unset-all user.name || true && \
97+
git config --system --unset-all user.name || true && \
9198
git config --system --unset-all user.email || true && \
92-
git config --global --unset-all user.name || true && \
99+
git config --global --unset-all user.name || true && \
93100
git config --global --unset-all user.email || true
101+
102+
COPY data/entrypoint.sh /usr/local/bin/entrypoint.sh
103+
RUN chmod +x /usr/local/bin/entrypoint.sh
104+
ENTRYPOINT [ "entrypoint.sh" ]
105+
CMD [ "bash" ]

Dockerfile.cuda

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ ARG TORCH_VERSION
1515
LABEL maintainer="JamesNULLiu jamesnulliu@gmail.com"
1616
LABEL version=${IMAGE_VERSION}
1717

18+
ENV CUDA_HOME=/usr/local/cuda
19+
ENV VCPKG_ROOT=/opt/vcpkg
20+
ENV VCPKG_HOME=/opt/vcpkg
21+
ENV CONDA_HOME=/opt/miniconda3
22+
ENV ENV_SETUP_FILE=/etc/local/env_setup.sh
23+
1824
SHELL ["/bin/bash", "-c"]
1925

2026
# Some basic tools
@@ -27,8 +33,8 @@ RUN apt-get update && apt-get upgrade -y && \
2733
fc-cache -f -v
2834

2935
# Vcpkg
30-
RUN cd /usr/local && git clone https://github.com/microsoft/vcpkg.git && \
31-
cd vcpkg && ./bootstrap-vcpkg.sh
36+
RUN git clone https://github.com/microsoft/vcpkg.git ${VCPKG_HOME} && \
37+
cd ${VCPKG_HOME} && ./bootstrap-vcpkg.sh
3238

3339
# CMake
3440
RUN wget -O /tmp/kitware-archive.sh \
@@ -37,19 +43,16 @@ RUN wget -O /tmp/kitware-archive.sh \
3743
apt-get update && apt-get install -y cmake
3844

3945
# LLVM
40-
RUN wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | \
41-
tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc && \
42-
echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble main" | \
43-
tee /etc/apt/sources.list.d/llvm.list && \
44-
echo "deb-src http://apt.llvm.org/noble/ llvm-toolchain-noble main" | \
45-
tee -a /etc/apt/sources.list.d/llvm.list && \
46+
RUN wget -O /tmp/llvm.sh https://apt.llvm.org/llvm.sh && \
47+
chmod +x /tmp/llvm.sh && \
48+
/tmp/llvm.sh ${LLVM_VERSION} && \
4649
apt-get update && apt-get install -y \
47-
clang-${LLVM_VERSION} lldb-${LLVM_VERSION} \
48-
clang-tools-${LLVM_VERSION} libclang-${LLVM_VERSION}-dev \
49-
clang-format-${LLVM_VERSION} python3-clang-${LLVM_VERSION} \
50-
clangd-${LLVM_VERSION} clang-tidy-${LLVM_VERSION} \
51-
lldb-${LLVM_VERSION} libc++-${LLVM_VERSION}-dev \
52-
libc++abi-${LLVM_VERSION}-dev libomp-${LLVM_VERSION}-dev && \
50+
clang-${LLVM_VERSION} lldb-${LLVM_VERSION} \
51+
clang-tools-${LLVM_VERSION} libclang-${LLVM_VERSION}-dev \
52+
clang-format-${LLVM_VERSION} python3-clang-${LLVM_VERSION} \
53+
clangd-${LLVM_VERSION} clang-tidy-${LLVM_VERSION} \
54+
lldb-${LLVM_VERSION} libc++-${LLVM_VERSION}-dev \
55+
libc++abi-${LLVM_VERSION}-dev libomp-${LLVM_VERSION}-dev && \
5356
ln -s /usr/bin/clang-${LLVM_VERSION} /usr/bin/clang && \
5457
ln -s /usr/bin/clang++-${LLVM_VERSION} /usr/bin/clang++ && \
5558
ln -s /usr/bin/clangd-${LLVM_VERSION} /usr/bin/clangd && \
@@ -61,33 +64,44 @@ RUN wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | \
6164
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
6265

6366
# Config files
64-
COPY data/.vimrc data/.inputrc data/.bashrc data/.setup_env.sh data/.tmux.conf \
65-
/root/
67+
COPY data/vimrc /etc/vim/vimrc
68+
COPY data/env_setup.sh ${ENV_SETUP_FILE}
69+
# [TODO] The config files should not only be copied only to /root, but also to
70+
# /etc/skel, so that the new user can also use them. But in singularity,
71+
# /etc/skel has no effect, so I will decide what to do later.
72+
COPY data/.inputrc data/.bashrc data/.tmux.conf /root/
73+
COPY data/.inputrc data/.bashrc data/.tmux.conf /etc/skel/
6674

6775
# Install Miniconda3 and conda env
6876
# [TODO] Conda now uses python=3.13 in default. However, some packages (i.e.,
6977
# vllm) only support python<=3.12. That's why I install python=3.12
7078
# mannually here. Maybe some days later I will remove this command.
7179
RUN wget -O /tmp/miniconda3.sh \
7280
https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
73-
mkdir -p /root/miniconda3 && \
74-
bash /tmp/miniconda3.sh -b -u -p /root/miniconda3 && \
75-
\. /root/miniconda3/bin/activate && \
81+
mkdir -p ${CONDA_HOME} && \
82+
bash /tmp/miniconda3.sh -b -u -p ${CONDA_HOME} && \
83+
${CONDA_HOME}/bin/conda tos accept && \
84+
\. ${CONDA_HOME}/bin/activate && \
7685
conda upgrade libstdcxx-ng -c conda-forge -y && \
7786
conda install -y python=3.12 && \
7887
pip3 install nvitop --no-cache-dir && \
7988
if [[ "${INSTALL_TORCH}" == "true" ]]; then \
80-
TORCH_CU_VER=$(echo $CUDA_VERSION | cut -d'.' -f1,2 | tr -d '.') && \
81-
pip3 install torch==${TORCH_VERSION} torchvision torchaudio \
82-
--index-url "https://download.pytorch.org/whl/cu${TORCH_CU_VER}" \
83-
--no-cache-dir \
89+
TORCH_CU_VER=$(echo $CUDA_VERSION | cut -d'.' -f1,2 | tr -d '.') && \
90+
pip3 install torch==${TORCH_VERSION} torchvision torchaudio \
91+
--index-url "https://download.pytorch.org/whl/cu${TORCH_CU_VER}" \
92+
--no-cache-dir \
8493
; fi
8594

8695
# Some final steps
8796
RUN apt-get update && apt-get upgrade -y && apt-get autoremove -y && \
8897
apt-get clean && rm -rf /var/lib/apt/lists/* && \
8998
conda clean --all -y && pip cache purge && \
90-
git config --system --unset-all user.name || true && \
99+
git config --system --unset-all user.name || true && \
91100
git config --system --unset-all user.email || true && \
92-
git config --global --unset-all user.name || true && \
101+
git config --global --unset-all user.name || true && \
93102
git config --global --unset-all user.email || true
103+
104+
COPY data/entrypoint.sh /usr/local/bin/entrypoint.sh
105+
RUN chmod +x /usr/local/bin/entrypoint.sh
106+
ENTRYPOINT [ "entrypoint.sh" ]
107+
CMD [ "bash" ]

data/.bashrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,4 @@ fi
102102
# . /etc/bash_completion
103103
#fi
104104

105-
# Load all environment settings
106-
source ~/.setup_env.sh
105+
source $ENV_SETUP_FILE

data/.setup_env.sh

Lines changed: 0 additions & 53 deletions
This file was deleted.

data/entrypoint.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
if [[ $# -eq 0 ]]; then
4+
exec "/bin/bash"
5+
else
6+
exec "$@"
7+
fi

data/env_setup.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# @brief Add `$1` into environment variable `$2` if it is not already there.
2+
# @example > env_load PATH /usr/local/bin
3+
env_load() {
4+
local var_name=$1
5+
local new_path=$2
6+
if [[ ":${!var_name}:" != *":$new_path:"* ]]; then
7+
export "$var_name"="${!var_name:+"${!var_name}:"}$new_path"
8+
fi
9+
}
10+
11+
# @brief Remove `$1` from environment variable `$2` if it is there.
12+
# @example > env_unload PATH /usr/local/bin
13+
env_unload() {
14+
local var_name=$1
15+
local target_path=$2
16+
local paths_array=(${!var_name//:/ })
17+
local new_paths=()
18+
for item in "${paths_array[@]}"; do
19+
if [[ "$item" != "$target_path" ]]; then
20+
new_paths+=("$item")
21+
fi
22+
done
23+
export $var_name=$(IFS=:; echo "${new_paths[*]}")
24+
}
25+
26+
if [ -d "${CONDA_HOME:-}" ]; then
27+
if [[ $- == *i* ]]; then
28+
# Initialize conda in interactive mode
29+
__conda_setup="$('${CONDA_HOME}/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
30+
if [ $? -eq 0 ]; then
31+
eval "$__conda_setup"
32+
else
33+
if [ -f "${CONDA_HOME}/etc/profile.d/conda.sh" ]; then
34+
. "${CONDA_HOME}/etc/profile.d/conda.sh"
35+
else
36+
env_load PATH "${CONDA_HOME}/bin"
37+
fi
38+
fi
39+
unset __conda_setup
40+
echo "[SETUP] Conda initialized in interactive mode from $CONDA_HOME"
41+
else
42+
# Initialize conda in non-interactive mode
43+
# Note that you will have to use `conda run` to use conda environments
44+
. "${CONDA_HOME}/etc/profile.d/conda.sh"
45+
echo "[SETUP] Conda initialized in non-interactive mode from $CONDA_HOME."
46+
fi
47+
else
48+
unset CONDA_HOME
49+
fi
50+
51+
if [ -d "${CUDA_HOME:-}" ]; then
52+
alias LOAD_CUDA="env_load PATH $CUDA_HOME/bin && \
53+
env_load LD_LIBRARY_PATH $CUDA_HOME/lib64"
54+
alias UNLOAD_CUDA="env_unload PATH $CUDA_HOME/bin && \
55+
env_unload LD_LIBRARY_PATH $CUDA_HOME/lib64"
56+
env_load PATH "$CUDA_HOME/bin"
57+
env_load LD_LIBRARY_PATH "$CUDA_HOME/lib64"
58+
echo "[SETUP] CUDA initialized from $CUDA_HOME"
59+
else
60+
unset CUDA_HOME
61+
fi
62+
63+
if [ -d "${VCPKG_HOME:-}" ]; then
64+
alias LOAD_VCPKG="env_load PATH $VCPKG_HOME"
65+
alias UNLOAD_VCPKG="env_unload PATH $VCPKG_HOME"
66+
alias VCPKG_UPDATE="pushd $VCPKG_HOME && git pull && popd"
67+
# Load vcpkg by default
68+
env_load PATH "$VCPKG_HOME"
69+
echo "[SETUP] VCPKG initialized from $VCPKG_HOME"
70+
else
71+
unset VCPKG_HOME
72+
fi

0 commit comments

Comments
 (0)