Skip to content

Commit 46d5cd0

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

File tree

7 files changed

+180
-111
lines changed

7 files changed

+180
-111
lines changed

Dockerfile.cpu

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ ARG CUDA_VERSION
22
ARG UBUNTU_VERSION
33

44
FROM ubuntu:24.04
5+
CMD ["bash"]
56

67
ARG DEBIAN_FRONTEND=noninteractive
78
ENV LANGUAGE=en_US.UTF-8
@@ -11,10 +12,15 @@ ARG INSTALL_TORCH
1112
ARG LLVM_VERSION
1213
ARG IMAGE_VERSION
1314
ARG TORCH_VERSION
15+
ENV ENV_SETUP_FILE=/etc/local/env_setup.sh
1416

1517
LABEL maintainer="JamesNULLiu jamesnulliu@gmail.com"
1618
LABEL version=${IMAGE_VERSION}
1719

20+
ENV VCPKG_ROOT=/opt/vcpkg
21+
ENV VCPKG_HOME=/opt/vcpkg
22+
ENV CONDA_HOME=/opt/miniconda3
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,38 @@ 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/cpu \
83-
--no-cache-dir \
89+
pip3 install torch==${TORCH_VERSION} torchvision torchaudio \
90+
--index-url https://download.pytorch.org/whl/cpu \
91+
--no-cache-dir \
8492
; fi
8593

8694
# Some final steps
8795
RUN apt-get update && apt-get upgrade -y && apt-get autoremove -y && \
8896
apt-get clean && rm -rf /var/lib/apt/lists/* && \
8997
conda clean --all -y && pip cache purge && \
90-
git config --system --unset-all user.name || true && \
98+
git config --system --unset-all user.name || true && \
9199
git config --system --unset-all user.email || true && \
92-
git config --global --unset-all user.name || true && \
93-
git config --global --unset-all user.email || true
100+
git config --global --unset-all user.name || true && \
101+
git config --global --unset-all user.email || true

Dockerfile.cuda

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ ARG CUDA_VERSION
22
ARG UBUNTU_VERSION
33

44
FROM nvidia/cuda:${CUDA_VERSION}-cudnn-devel-ubuntu${UBUNTU_VERSION}
5+
CMD ["bash"]
56

67
ARG DEBIAN_FRONTEND=noninteractive
78
ENV LANGUAGE=en_US.UTF-8
@@ -15,6 +16,12 @@ ARG TORCH_VERSION
1516
LABEL maintainer="JamesNULLiu jamesnulliu@gmail.com"
1617
LABEL version=${IMAGE_VERSION}
1718

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

2027
# Some basic tools
@@ -27,8 +34,8 @@ RUN apt-get update && apt-get upgrade -y && \
2734
fc-cache -f -v
2835

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

3340
# CMake
3441
RUN wget -O /tmp/kitware-archive.sh \
@@ -37,19 +44,16 @@ RUN wget -O /tmp/kitware-archive.sh \
3744
apt-get update && apt-get install -y cmake
3845

3946
# 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 && \
47+
RUN wget -O /tmp/llvm.sh https://apt.llvm.org/llvm.sh && \
48+
chmod +x /tmp/llvm.sh && \
49+
/tmp/llvm.sh ${LLVM_VERSION} && \
4650
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 && \
51+
clang-${LLVM_VERSION} lldb-${LLVM_VERSION} \
52+
clang-tools-${LLVM_VERSION} libclang-${LLVM_VERSION}-dev \
53+
clang-format-${LLVM_VERSION} python3-clang-${LLVM_VERSION} \
54+
clangd-${LLVM_VERSION} clang-tidy-${LLVM_VERSION} \
55+
lldb-${LLVM_VERSION} libc++-${LLVM_VERSION}-dev \
56+
libc++abi-${LLVM_VERSION}-dev libomp-${LLVM_VERSION}-dev && \
5357
ln -s /usr/bin/clang-${LLVM_VERSION} /usr/bin/clang && \
5458
ln -s /usr/bin/clang++-${LLVM_VERSION} /usr/bin/clang++ && \
5559
ln -s /usr/bin/clangd-${LLVM_VERSION} /usr/bin/clangd && \
@@ -61,33 +65,39 @@ RUN wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | \
6165
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
6266

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

6776
# Install Miniconda3 and conda env
6877
# [TODO] Conda now uses python=3.13 in default. However, some packages (i.e.,
6978
# vllm) only support python<=3.12. That's why I install python=3.12
7079
# mannually here. Maybe some days later I will remove this command.
7180
RUN wget -O /tmp/miniconda3.sh \
7281
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 && \
82+
mkdir -p ${CONDA_HOME} && \
83+
bash /tmp/miniconda3.sh -b -u -p ${CONDA_HOME} && \
84+
${CONDA_HOME}/bin/conda tos accept && \
85+
\. ${CONDA_HOME}/bin/activate && \
7686
conda upgrade libstdcxx-ng -c conda-forge -y && \
7787
conda install -y python=3.12 && \
7888
pip3 install nvitop --no-cache-dir && \
7989
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 \
90+
TORCH_CU_VER=$(echo $CUDA_VERSION | cut -d'.' -f1,2 | tr -d '.') && \
91+
pip3 install torch==${TORCH_VERSION} torchvision torchaudio \
92+
--index-url "https://download.pytorch.org/whl/cu${TORCH_CU_VER}" \
93+
--no-cache-dir \
8494
; fi
8595

8696
# Some final steps
8797
RUN apt-get update && apt-get upgrade -y && apt-get autoremove -y && \
8898
apt-get clean && rm -rf /var/lib/apt/lists/* && \
8999
conda clean --all -y && pip cache purge && \
90-
git config --system --unset-all user.name || true && \
100+
git config --system --unset-all user.name || true && \
91101
git config --system --unset-all user.email || true && \
92-
git config --global --unset-all user.name || true && \
93-
git config --global --unset-all user.email || true
102+
git config --global --unset-all user.name || true && \
103+
git config --global --unset-all user.email || true

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/env_setup.sh

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

0 commit comments

Comments
 (0)