-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·93 lines (87 loc) · 1.98 KB
/
run.sh
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
90
91
92
#!/bin/bash
set -ae
DUSER=docker-user
DGROUP=docker-user
DGID=$(id -g)
DUID=$(id -u)
PLATFORM=$(uname -m)
print_usage() {
printf \
"Usage:
-b build
-f no cache
-p push to remote
-m multiarch
-c clean
-f clean all
-g gpu
-d close instance
\n"
}
while getopts 'hbfpmcdg' flag; do
case "${flag}" in
b) build='true' ;;
f) nocache='true' ;;
p) push='true' ;;
m) multi='true' ;;
c) clean='true' ;;
d) down='true' ;;
g) gpu='true' ;;
h | *) print_usage
exit 1 ;;
esac
done
if [[ "$gpu" == "true" ]]; then
dc='docker compose -f docker-compose-gpu.yml';
else
dc='docker compose';
fi
if [[ "$build" == 'true' ]]; then
ARGS='';
if [[ "$nocache" == 'true' ]]; then
ARGS+='--no-cache ';
fi
if [[ "$gpu" == 'true' ]]; then
ARGS+='--build-arg image=nvidia/cuda:12.6.2-cudnn-devel-ubuntu24.04 ';
else
ARGS+='--build-arg image=ubuntu:24.04 ';
fi
if [[ "$push" == 'true' ]]; then
ARGS+='--push ';
fi
if [[ "$multi" == 'true' ]]; then
docker buildx bake --set *.platform=linux/arm64,linux/amd64 $ARGS;
else
$dc build $ARGS;
fi
elif [[ "$clean" == 'true' ]]; then
if [[ "$nocache" == 'true' ]]; then
yes | docker system prune -a;
yes | docker buildx prune -a;
else
yes | docker system prune;
yes | docker buildx prune;
fi
else
if [[ "$down" == "true" ]]; then
$dc down;
exit;
fi
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
xhost +localhost;
DISPLAY=$DISPLAY;
elif [[ "$OSTYPE" == "darwin"* ]]; then
# https://gist.github.com/cschiewek/246a244ba23da8b9f0e7b11a68bf3285?permalink_comment_id=3477013#gistcomment-3477013
xhost +localhost;
DISPLAY=host.docker.internal:0;
else
echo "not supported";
exit 1
fi
$dc up -d;
if [[ "$gpu" == "true" ]]; then
docker exec -it emacs-latex-gpu bash
else
docker exec -it emacs-latex bash
fi
fi