Skip to content

Commit e544ec5

Browse files
author
seel.xu
committed
[Offline]: add docker images
1 parent 9361baf commit e544ec5

File tree

4 files changed

+375
-0
lines changed

4 files changed

+375
-0
lines changed

.gitignore

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
*.obj
9+
10+
# Precompiled Headers
11+
*.gch
12+
*.pch
13+
14+
# Compiled Dynamic libraries
15+
*.so
16+
*.dylib
17+
*.dll
18+
19+
# Fortran module files
20+
*.mod
21+
*.smod
22+
23+
# Compiled Static libraries
24+
*.lai
25+
*.la
26+
*.a
27+
*.lib
28+
29+
# Executables
30+
*.exe
31+
*.out
32+
*.app
33+
34+
# vscode
35+
.vscode
36+
37+
# Clangd
38+
/.cache
39+
/external
40+
41+
# Bazel
42+
bazel-*
43+
MODULE.bazel.lock
44+
45+
### Automatically added by Hedron's Bazel Compile Commands Extractor: https://github.com/hedronvision/bazel-compile-commands-extractor
46+
# Ignore generated output. Although valuable (after all, the primary purpose of `bazel-compile-commands-extractor` is to produce `compile_commands.json`!), it should not be checked in.
47+
/compile_commands.json
48+
49+
# Tmp
50+
tmp/*

docker.sh

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
DOCKER_IMG="silvesterhsu/astroparse:dev"
6+
CONTAINER_NAME="AstroParse"
7+
BASE_DIRECTORY=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
8+
9+
# Logging functions
10+
log_info() {
11+
printf "[\e[34m\e[1mINFO\e[0m] $*\n" >&2
12+
}
13+
14+
log_error() {
15+
printf "[\033[0;31mERROR\e[0m] $*\n" >&2
16+
}
17+
18+
log_warning() {
19+
printf "[\033[0;33mWARNING\e[0m] $*\n" >&2
20+
}
21+
22+
log_success() {
23+
printf "[\e[32m\e[1m OK \e[0m] $*\n" >&2
24+
}
25+
26+
# Display usage
27+
show_usage() {
28+
local script_name=$(basename "${BASH_SOURCE[0]}")
29+
cat << EOF
30+
Usage:
31+
${script_name} [run|init|help]
32+
run Run container (default).
33+
init Init container.
34+
help Display this help message.
35+
EOF
36+
}
37+
38+
# Check Docker environment
39+
check_docker() {
40+
log_info "[1/4] Checking Docker environment ..."
41+
if ! docker --version &>/dev/null; then
42+
log_error "Docker is not installed. Please install Docker first."
43+
exit 1
44+
fi
45+
}
46+
47+
# Check Docker image
48+
check_docker_image() {
49+
log_info "[2/4] Checking if Docker image \"${DOCKER_IMG}\" exists ..."
50+
if ! docker image inspect "${DOCKER_IMG}" &>/dev/null; then
51+
log_info "Docker image \"${DOCKER_IMG}\" not found. Pulling image ..."
52+
docker pull "${DOCKER_IMG}" || {
53+
log_error "Failed to pull Docker image \"${DOCKER_IMG}\"."
54+
exit 1
55+
}
56+
else
57+
log_success "Docker image \"${DOCKER_IMG}\" already exists."
58+
fi
59+
}
60+
61+
# Check Docker container
62+
check_docker_container() {
63+
log_info "[3/4] Checking container \"${CONTAINER_NAME}\" ..."
64+
if docker ps -a --format "{{.Names}}" | grep -q "${CONTAINER_NAME}"; then
65+
log_info "Container \"${CONTAINER_NAME}\" exists. Stopping and removing it ..."
66+
docker stop "${CONTAINER_NAME}" &>/dev/null
67+
docker rm "${CONTAINER_NAME}" &>/dev/null
68+
fi
69+
}
70+
71+
# Run Docker container
72+
run_docker_container() {
73+
log_info "[4/4] Running container \"${CONTAINER_NAME}\" ..."
74+
docker run --runtime=nvidia \
75+
-it -d \
76+
--shm-size=4G \
77+
--restart always \
78+
--name "$CONTAINER_NAME" \
79+
-v "$BASE_DIRECTORY:/${CONTAINER_NAME}" \
80+
-v "$HOME:/home/$USER" \
81+
-w "/${CONTAINER_NAME}" \
82+
-v /etc/localtime:/etc/localtime:ro \
83+
-v /etc/resolv.conf:/etc/resolv.conf:ro \
84+
--net host \
85+
--add-host "$CONTAINER_NAME:127.0.0.1" \
86+
--hostname "$CONTAINER_NAME" \
87+
"$DOCKER_IMG" \
88+
/bin/bash
89+
}
90+
91+
# Start Docker container
92+
start_docker_container() {
93+
log_info "Checking container \"${CONTAINER_NAME}\" ..."
94+
if docker ps -a --format "{{.Names}}" | grep -q "${CONTAINER_NAME}"; then
95+
log_info "Container \"${CONTAINER_NAME}\" exists, starting it ..."
96+
docker start "${CONTAINER_NAME}" &>/dev/null
97+
docker exec -it "${CONTAINER_NAME}" /bin/bash
98+
else
99+
log_error "Container \"${CONTAINER_NAME}\" does not exist. Please run \"${0} init\" first."
100+
exit 1
101+
fi
102+
}
103+
104+
# Main function
105+
main() {
106+
local cmd="run"
107+
if [ $# -ge 1 ]; then
108+
cmd=$1
109+
shift
110+
fi
111+
112+
case "${cmd}" in
113+
run)
114+
start_docker_container
115+
;;
116+
init)
117+
check_docker
118+
check_docker_image
119+
check_docker_container
120+
run_docker_container
121+
;;
122+
help|usage)
123+
show_usage
124+
;;
125+
*)
126+
show_usage
127+
;;
128+
esac
129+
}
130+
131+
# Execute the main function
132+
main "$@"

docker/Dockerfile

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
ARG VARIANT=dev
2+
FROM ubuntu:22.04 as base
3+
4+
ENV DEBIAN_FRONTEND noninteractive
5+
6+
RUN apt update && \
7+
apt install autoconf automake libtool curl wget make cmake g++ unzip git -y && \
8+
rm -rf /var/lib/apt/lists/*
9+
10+
# Install Bazel
11+
RUN apt update && apt install apt-transport-https curl gnupg -y && \
12+
curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor >bazel-archive-keyring.gpg && \
13+
mv bazel-archive-keyring.gpg /usr/share/keyrings && \
14+
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/bazel-archive-keyring.gpg] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list && \
15+
apt update && \
16+
wget https://github.com/bazelbuild/bazel/releases/download/7.3.1/bazel-7.3.1-installer-linux-x86_64.sh -O /tmp/bazel-installer.sh && \
17+
chmod +x /tmp/bazel-installer.sh && \
18+
/tmp/bazel-installer.sh
19+
20+
# install Clang
21+
ENV CLANG 20
22+
ENV CLANG_URL https://apt.llvm.org/llvm.sh
23+
RUN apt update && apt install -y lsb-release wget software-properties-common gnupg && \
24+
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \
25+
echo "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-${CLANG} main" | tee /etc/apt/sources.list.d/llvm-toolchain.list && \
26+
echo "deb-src http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-${CLANG} main" | tee -a /etc/apt/sources.list.d/llvm-toolchain.list && \
27+
apt update && \
28+
apt install lsb-release wget software-properties-common gnupg -y && \
29+
apt install --no-install-recommends -y \
30+
clang-${CLANG} \
31+
clang-tidy-${CLANG} \
32+
clang-format-${CLANG} \
33+
llvm-${CLANG}-dev \
34+
clangd-${CLANG} \
35+
libclang-${CLANG}-dev \
36+
libclang-cpp${CLANG} && \
37+
rm -rf /var/lib/apt/lists/*
38+
39+
RUN apt update && \
40+
apt install lsb-release wget software-properties-common gnupg -y && \
41+
wget ${CLANG_URL} && \
42+
chmod +x llvm.sh && \
43+
./llvm.sh ${CLANG} && \
44+
ln -s /usr/bin/clang-20 /usr/bin/clang && \
45+
ln -s /usr/bin/clang++-20 /usr/bin/clang++ && \
46+
ln -s /usr/bin/clang-tidy-20 /usr/bin/clang-tidy && \
47+
ln -s /usr/bin/clang-format-20 /usr/bin/clang-format && \
48+
ln -s /usr/bin/clangd-20 /usr/bin/clangd && \
49+
rm -rf llvm.sh && \
50+
rm -rf /var/lib/apt/lists/*
51+
52+
FROM base as dev-stage
53+
COPY --from=base /usr/local/include /usr/local/include
54+
COPY --from=base /usr/local/lib /usr/local/lib
55+
COPY --from=base /usr/local/bin /usr/local/bin
56+
57+
# install Clangd
58+
ENV CLANGD 16.0.2
59+
ENV CLANGD_URL https://github.com/clangd/clangd/releases/download/${CLANGD}/clangd-linux-${CLANGD}.zip
60+
WORKDIR /tmp
61+
RUN wget ${CLANGD_URL} && \
62+
unzip clangd-linux-${CLANGD}.zip && \
63+
mv clangd_${CLANGD}/lib/clang /usr/local/lib/ && \
64+
mv clangd_${CLANGD}/bin/clangd /usr/local/bin/ && \
65+
rm -rf clangd_${CLANGD} && \
66+
rm -rf clangd-linux-${CLANGD}.zip
67+
68+
# install GDB
69+
ENV GDB 12.1
70+
ENV GDB_URL https://ftp.gnu.org/gnu/gdb/gdb-${GDB}.tar.gz
71+
WORKDIR /tmp
72+
RUN apt update && \
73+
apt install -y --no-install-recommends libgmp-dev && \
74+
rm -rf /var/lib/apt/lists/* && \
75+
wget ${GDB_URL} && \
76+
tar -zxvf gdb-${GDB}.tar.gz && \
77+
cd gdb-${GDB} && \
78+
./configure && \
79+
export CPP='g++ -E' && \
80+
export CXX='g++' && \
81+
export CC='gcc' && \
82+
export LD='g++' && \
83+
make -j$(nproc) && \
84+
make install && \
85+
cd /tmp && \
86+
rm -rf /tmp/gdb-${GDB}*
87+
88+
# install zsh & fix ssh env
89+
WORKDIR /tmp
90+
RUN apt update && apt install zsh openssh-client openssh-server -y && \
91+
echo "export \$(cat /proc/1/environ |tr '\\0' '\\n' | xargs)" >> /etc/profile && \
92+
echo "export \$(cat /proc/1/environ |tr '\\0' '\\n' | xargs)" >> /etc/zsh/zprofile && \
93+
rm -rf ~/.oh-my-zsh || true && \
94+
curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -o install.sh && \
95+
chmod +x install.sh && \
96+
./install.sh --skip-chsh --unattended && \
97+
rm install.sh && \
98+
git clone http://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions && \
99+
git clone http://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting && \
100+
sed -e '/ZSH_THEME=/s/"robbyrussell"/"ys"/' \
101+
-e '/plugins=(git/s/)/ zsh-autosuggestions zsh-syntax-highlighting)/' -i ~/.zshrc && \
102+
chsh -s /bin/zsh root && \
103+
rm -rf /var/lib/apt/lists/*
104+
105+
# install vim & plugins
106+
RUN apt update && \
107+
apt install -y --no-install-recommends \
108+
git vim && \
109+
rm -rf /var/lib/apt/lists/* && \
110+
git config --global core.editor vim && \
111+
git config --global http.sslverify false && \
112+
git config --global https.sslverify false && \
113+
git clone https://github.com/sickill/vim-monokai.git /tmp/vim-monokai && \
114+
mkdir -p ~/.vim/colors && \
115+
mv /tmp/vim-monokai/colors/* ~/.vim/colors && \
116+
git config --global --unset http.sslverify && \
117+
git config --global --unset https.sslverify && \
118+
touch ~/.vimrc && \
119+
vim -u ~/.vimrc +PlugInstall +qall
120+
121+
FROM base as final-build
122+
USER root
123+
WORKDIR /workspace
124+
ENV PATH $PATH:/usr/local/cuda/bin:/usr/src/tensorrt/bin
125+
ENV LD_LIBRARY_PATH $LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/targets/x86_64-linux/lib:/usr/lib/llvm-20/lib
126+
ENV LIBRARY_PATH $LIBRARY_PATH::/usr/local/lib:/usr/local/cuda/lib64:/usr/local/cuda/targets/x86_64-linux/lib:/usr/lib/llvm-20/lib
127+
ENV C_INCLUDE_PATH $C_INCLUDE_PATH:/usr/local/cuda/include:/usr/include/x86_64-linux-gnu:/usr/lib/llvm-20/include:/usr/include/llvm-20
128+
ENV CPLUS_INCLUDE_PATH $CPLUS_INCLUDE_PATH:/usr/local/cuda/include://usr/include/x86_64-linux-gnu::/usr/lib/llvm-20/include:/usr/include/llvm-20
129+
130+
FROM dev-stage as final-dev
131+
USER root
132+
WORKDIR /workspace
133+
ENV PATH $PATH:/usr/local/cuda/bin:/usr/src/tensorrt/bin
134+
ENV LD_LIBRARY_PATH $LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/targets/x86_64-linux/lib:/usr/lib/llvm-20/lib
135+
ENV LIBRARY_PATH $LIBRARY_PATH::/usr/local/lib:/usr/local/cuda/lib64:/usr/local/cuda/targets/x86_64-linux/lib:/usr/lib/llvm-20/lib
136+
ENV C_INCLUDE_PATH $C_INCLUDE_PATH:/usr/local/cuda/include:/usr/include/x86_64-linux-gnu:/usr/lib/llvm-20/include:/usr/include/llvm-20
137+
ENV CPLUS_INCLUDE_PATH $CPLUS_INCLUDE_PATH:/usr/local/cuda/include://usr/include/x86_64-linux-gnu::/usr/lib/llvm-20/include:/usr/include/llvm-20
138+
139+
FROM final-${VARIANT} as final

scripts/build_image.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
info() {
6+
echo -e "\033[0;34m[INFO]\033[0m $1"
7+
}
8+
9+
error() {
10+
echo -e "\033[0;31m[ERROR]\033[0m $1"
11+
}
12+
13+
warning() {
14+
echo -e "\033[0;33m[WARNING]\033[0m $1"
15+
}
16+
17+
ok() {
18+
echo -e "\033[0;32m[OK]\033[0m $1"
19+
}
20+
21+
# Display usage
22+
show_usage() {
23+
echo "Usage: $0 [dev|build]"
24+
echo " dev - Build the dev image"
25+
echo " build - Build the build image"
26+
}
27+
28+
main() {
29+
if [ "$#" -ne 1 ]; then
30+
show_usage
31+
exit 1
32+
fi
33+
34+
case $1 in
35+
dev)
36+
info "Building dev image..."
37+
docker build --progress=plain -t astroparse:dev --build-arg VARIANT=dev docker/.
38+
ok "Dev image built successfully."
39+
;;
40+
build)
41+
info "Building build image..."
42+
docker build --progress=plain -t astroparse:build --build-arg VARIANT=build docker/.
43+
ok "Build image built successfully."
44+
;;
45+
*)
46+
error "Invalid argument: $1"
47+
show_usage
48+
exit 1
49+
;;
50+
esac
51+
}
52+
53+
# Execute the main function
54+
main "$@"

0 commit comments

Comments
 (0)