Skip to content

Commit 92bb0de

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

8 files changed

Lines changed: 163 additions & 109 deletions

File tree

Dockerfile.cpu

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ 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+
1822
SHELL ["/bin/bash", "-c"]
1923

2024
# Some basic tools
@@ -27,8 +31,8 @@ RUN apt-get update && apt-get upgrade -y && \
2731
fc-cache -f -v
2832

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

3337
# CMake
3438
RUN wget -O /tmp/kitware-archive.sh \
@@ -37,19 +41,16 @@ RUN wget -O /tmp/kitware-archive.sh \
3741
apt-get update && apt-get install -y cmake
3842

3943
# 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 && \
44+
RUN wget -O /tmp/llvm.sh https://apt.llvm.org/llvm.sh && \
45+
chmod +x /tmp/llvm.sh && \
46+
/tmp/llvm.sh ${LLVM_VERSION} && \
4647
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 && \
48+
clang-${LLVM_VERSION} lldb-${LLVM_VERSION} \
49+
clang-tools-${LLVM_VERSION} libclang-${LLVM_VERSION}-dev \
50+
clang-format-${LLVM_VERSION} python3-clang-${LLVM_VERSION} \
51+
clangd-${LLVM_VERSION} clang-tidy-${LLVM_VERSION} \
52+
lldb-${LLVM_VERSION} libc++-${LLVM_VERSION}-dev \
53+
libc++abi-${LLVM_VERSION}-dev libomp-${LLVM_VERSION}-dev && \
5354
ln -s /usr/bin/clang-${LLVM_VERSION} /usr/bin/clang && \
5455
ln -s /usr/bin/clang++-${LLVM_VERSION} /usr/bin/clang++ && \
5556
ln -s /usr/bin/clangd-${LLVM_VERSION} /usr/bin/clangd && \
@@ -61,33 +62,42 @@ RUN wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | \
6162
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
6263

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

6772
# Install Miniconda3 and conda env
6873
# [TODO] Conda now uses python=3.13 in default. However, some packages (i.e.,
6974
# vllm) only support python<=3.12. That's why I install python=3.12
7075
# mannually here. Maybe some days later I will remove this command.
7176
RUN wget -O /tmp/miniconda3.sh \
7277
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 && \
78+
mkdir -p ${CONDA_HOME} && \
79+
bash /tmp/miniconda3.sh -b -u -p ${CONDA_HOME} && \
80+
${CONDA_HOME}/bin/conda tos accept && \
81+
\. ${CONDA_HOME}/bin/activate && \
7682
conda upgrade libstdcxx-ng -c conda-forge -y && \
7783
conda install -y python=3.12 && \
7884
pip3 install nvitop --no-cache-dir && \
7985
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 \
86+
pip3 install torch==${TORCH_VERSION} torchvision torchaudio \
87+
--index-url https://download.pytorch.org/whl/cpu \
88+
--no-cache-dir \
8489
; fi
8590

8691
# Some final steps
8792
RUN apt-get update && apt-get upgrade -y && apt-get autoremove -y && \
8893
apt-get clean && rm -rf /var/lib/apt/lists/* && \
8994
conda clean --all -y && pip cache purge && \
90-
git config --system --unset-all user.name || true && \
95+
git config --system --unset-all user.name || true && \
9196
git config --system --unset-all user.email || true && \
92-
git config --global --unset-all user.name || true && \
97+
git config --global --unset-all user.name || true && \
9398
git config --global --unset-all user.email || true
99+
100+
COPY data/entrypoint.sh /usr/local/bin/
101+
RUN chmod +x /usr/local/bin/entrypoint.sh
102+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
103+
CMD ["bash"]

Dockerfile.cuda

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ 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+
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+
# [TODO] The config files should not only be copied only to /root, but also to
68+
# /etc/skel, so that the new user can also use them. But in singularity,
69+
# /etc/skel has no effect, so I will decide what to do later.
70+
COPY data/.inputrc data/.bashrc data/.tmux.conf /root/
71+
COPY data/.inputrc data/.bashrc data/.tmux.conf /etc/skel/
6672

6773
# Install Miniconda3 and conda env
6874
# [TODO] Conda now uses python=3.13 in default. However, some packages (i.e.,
6975
# vllm) only support python<=3.12. That's why I install python=3.12
7076
# mannually here. Maybe some days later I will remove this command.
7177
RUN wget -O /tmp/miniconda3.sh \
7278
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 && \
79+
mkdir -p ${CONDA_HOME} && \
80+
bash /tmp/miniconda3.sh -b -u -p ${CONDA_HOME} && \
81+
${CONDA_HOME}/bin/conda tos accept && \
82+
\. ${CONDA_HOME}/bin/activate && \
7683
conda upgrade libstdcxx-ng -c conda-forge -y && \
7784
conda install -y python=3.12 && \
7885
pip3 install nvitop --no-cache-dir && \
7986
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 \
87+
TORCH_CU_VER=$(echo $CUDA_VERSION | cut -d'.' -f1,2 | tr -d '.') && \
88+
pip3 install torch==${TORCH_VERSION} torchvision torchaudio \
89+
--index-url "https://download.pytorch.org/whl/cu${TORCH_CU_VER}" \
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/
103+
RUN chmod +x /usr/local/bin/entrypoint.sh
104+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
105+
CMD ["bash"]

data/.bashrc

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

105-
# Load all environment settings
106-
source ~/.setup_env.sh
105+
# @brief Add `$1` into environment variable `$2` if it is not already there.
106+
# @example > env_load PATH /usr/local/bin
107+
env_load() {
108+
local env_var=$1
109+
local path=$2
110+
if [[ ":${!env_var}:" != *":$path:"* ]]; then
111+
export $env_var="${!env_var}:$path"
112+
fi
113+
}
114+
115+
# @brief Remove `$1` from environment variable `$2` if it is there.
116+
# @example > env_unload PATH /usr/local/bin
117+
env_unload() {
118+
local env_var=$1
119+
local path=$2
120+
local paths_array=(${!env_var//:/ })
121+
local new_paths=()
122+
for item in "${paths_array[@]}"; do
123+
if [[ "$item" != "$path" ]]; then
124+
new_paths+=("$item")
125+
fi
126+
done
127+
export $env_var=$(IFS=:; echo "${new_paths[*]}")
128+
}

data/.setup_env.sh

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

data/entrypoint.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "[ENTRYPOINT] Starting entrypoint script..."
5+
6+
# @brief Add `$1` into environment variable `$2` if it is not already there.
7+
# @example > env_load PATH /usr/local/bin
8+
env_load() {
9+
local env_var=$1
10+
local path=$2
11+
if [[ ":${!env_var}:" != *":$path:"* ]]; then
12+
export $env_var="${!env_var}:$path"
13+
fi
14+
}
15+
16+
echo "[ENTRYPOINT] Setting up conda..."
17+
. "${CONDA_HOME}/etc/profile.d/conda.sh"
18+
conda activate
19+
20+
if [ -d "$CUDA_HOME" ]; then
21+
echo "[ENTRYPOINT] Setting up CUDA..."
22+
env_load PATH $CUDA_HOME/bin
23+
env_load LD_LIBRARY_PATH $CUDA_HOME/lib64
24+
else
25+
unset CUDA_HOME
26+
fi
27+
28+
echo "[ENTRYPOINT] Setting up VCPKG..."
29+
env_load PATH $VCPKG_HOME
30+
31+
# Execute the command passed to the container
32+
echo "[ENTRYPPOINT] Running command: $@"
33+
exec "$@"

data/.vimrc renamed to data/vimrc

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
" $VIMRUNTIME refers to the versioned system directory where Vim stores its
2+
" system runtime files -- /usr/share/vim/vim<version>.
3+
"
4+
" Vim will load $VIMRUNTIME/defaults.vim if the user does not have a vimrc.
5+
" This happens after /etc/vim/vimrc(.local) are loaded, so it will override
6+
" any settings in these files.
7+
"
8+
" If you don't want that to happen, uncomment the below line to prevent
9+
" defaults.vim from being loaded.
10+
" let g:skip_defaults_vim = 1
11+
"
12+
" If you would rather _use_ default.vim's settings, but have the system or
13+
" user vimrc override its settings, then uncomment the line below.
14+
" source $VIMRUNTIME/defaults.vim
15+
16+
" All Debian-specific settings are defined in $VIMRUNTIME/debian.vim and
17+
" sourced by the call to :runtime you can find below. If you wish to change
18+
" any of those settings, you should do it in this file or
19+
" /etc/vim/vimrc.local, since debian.vim will be overwritten everytime an
20+
" upgrade of the vim packages is performed. It is recommended to make changes
21+
" after sourcing debian.vim so your settings take precedence.
22+
23+
runtime! debian.vim
24+
125
" Uncomment the next line to make Vim more Vi-compatible
226
" NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes
327
" numerous options, so any other options should be set AFTER changing
@@ -58,4 +82,9 @@ augroup END
5882
set langmenu=en_US
5983
let $LANG='en_US'
6084
source $VIMRUNTIME/delmenu.vim
61-
source $VIMRUNTIME/menu.vim
85+
source $VIMRUNTIME/menu.vim
86+
87+
" Source a global configuration file if available
88+
if filereadable("/etc/vim/vimrc.local")
89+
source /etc/vim/vimrc.local
90+
endif

scripts/.image-configs.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
IMAGE_VERSION=2.2.4
2-
TORCH_VERSION=2.7.0
1+
IMAGE_VERSION=2.3.0
2+
TORCH_VERSION=2.7.1
33
CUDA_VERSION=12.8.0
44
UBUNTU_VERSION=24.04
5-
LLVM_VERSION=21
5+
LLVM_VERSION=20
66
IMAGE_TAG="v${IMAGE_VERSION}"

tmp.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exec "$@"

0 commit comments

Comments
 (0)