-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_docker.sh
More file actions
executable file
·89 lines (76 loc) · 2.59 KB
/
start_docker.sh
File metadata and controls
executable file
·89 lines (76 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash -e
USE_SUDO=$1
# Color definitions
GREEN='\033[0;32m'
NC='\033[0m' # No Color
if [ "$USE_SUDO" = "su" ]; then
echo -e "${GREEN}[+] Use sudo docker${NC}"
fi
# Function to create a symbolic link if it doesn't already exist
create_symlink_if_not_exist() {
local target=$1
local link=$2
if [ ! -L "$link" ]; then
ln -s "$target" "$link"
fi
}
use_docker() {
if [ "$USE_SUDO" = "su" ]; then
sudo docker "$@"
else
docker "$@"
fi
}
# Creating necessary symbolic links
create_symlink_if_not_exist LLM_training_docker/Dockerfile ./Dockerfile
create_symlink_if_not_exist LLM_training_docker/docker-compose.yml ./docker-compose.yml
# create_symlink_if_not_exist LLM_training_docker/config/.env.example ./.env
# Setting user and group information
USER_ID=${USER_ID:-$(id -u)}
GROUP_ID=${GROUP_ID:-$(id -g)}
USER_NAME=${USER_NAME:-${USER}}
# Displaying current user and group information
echo -e "${GREEN}+-------------------+-------------+"
echo -e "| Attribute | Value |"
echo -e "+-------------------+-------------+"
printf "| %-17s | %-11s |\n" "Current USER_ID" "$USER_ID"
printf "| %-17s | %-11s |\n" "Current GROUP_ID" "$GROUP_ID"
printf "| %-17s | %-11s |\n" "Current USER_NAME" "$USER_NAME"
echo -e "+-------------------+-------------+${NC}"
# Setting service name and converting it to lowercase
SERVICE_NAME="llm_train_env_${USER_NAME,,}"
# If the argument is 'log', display logs and exit
if [ "$USE_SUDO" = "su" ]; then
if [ "$2" = "log" ]; then
use_docker logs $SERVICE_NAME
exit 0
fi
elif [ "$1" = "log" ]; then
use_docker logs $SERVICE_NAME
exit 0
fi
# Checking if the Docker service is running
if [ $(use_docker ps --filter "name=$SERVICE_NAME" --filter "status=running" -q | wc -l) -gt 0 ]; then
use_docker exec -it $SERVICE_NAME /bin/bash
elif [ "$USE_SUDO" = "su" ]; then
echo -e "use_docker compose up --build -d"
cp LLM_training_docker/config/.env.example .env
cat <<EOF >> .env
# <Start of TMP>
USER_ID=${USER_ID}
GROUP_ID=${GROUP_ID}
USER_NAME=${USER_NAME}
SERVICE_NAME=${SERVICE_NAME}
# <End of TMP>
EOF
use_docker compose up --build -d
sleep 1
use_docker logs $SERVICE_NAME
sed -i '/# <Start of TMP>/,/# <End of TMP>/d' .env
else
echo -e "USER_ID=$USER_ID GROUP_ID=$GROUP_ID USER_NAME=$USER_NAME SERVICE_NAME=$SERVICE_NAME use_docker compose up --build -d"
cp LLM_training_docker/config/.env.example .env
USER_ID=$USER_ID GROUP_ID=$GROUP_ID USER_NAME=$USER_NAME SERVICE_NAME=$SERVICE_NAME use_docker compose up --build -d
sleep 1
use_docker logs $SERVICE_NAME
fi