-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_vscode_server
executable file
·103 lines (93 loc) · 2.82 KB
/
run_vscode_server
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
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env bash
USAGE="Usage: run_rstudio_server -i <image> -u <user list> -p <admin password>\n
\n
This command generates docker containers based on a rstudio server container for each user\n
\n
-i image name. If not present yet it will be downloaded from docker hub. Should be based on a linuxserver/code-server image. Default: linuxserver/code-server\n
-u user list. Tab delimited list of users with three columns: port, user name, password\n
-p admin password. Password used for the admin container.\n
-m maximum memory for the user container. Default: 16g.\n
-c maximum number of cpu for the user container. Default: 4."
while getopts ":i:u:p:m:c:" opt
do
case $opt in
i)
IMAGE=$OPTARG
;;
u)
USERLIST=$OPTARG
;;
p)
MASTERPW=$OPTARG
;;
m)
MEMORY=$OPTARG
;;
c)
CPU=$OPTARG
;;
\?)
echo -e "Invalid option: -$OPTARG \n" >&2
echo -e $USAGE >&2
exit 1
;;
:)
echo -e "Option -$OPTARG requires an argument. \n"
echo -e $USAGE >&2
exit 1
;;
esac
done
# return usage if no options are passed
if [ $OPTIND -eq 1 ]
then
echo -e "No options were passed. \n" >&2
echo -e $USAGE >&2
exit 1
fi
# required options
if [ "$USERLIST" == "" ]; then echo "option -u is missing, but required">&2 && exit 1; fi
if [ "$MASTERPW" == "" ]; then echo "option -p is missing, but required">&2 && exit 1; fi
# default values
if [ "$IMAGE" == "" ]; then IMAGE=linuxserver/code-server; fi
if [ "$MEMORY" == "" ]; then MEMORY=16g; fi
if [ "$CPU" == "" ]; then CPU=4; fi
# create general volume that will be populated with read-only data
docker volume create data
# create general volume for group work
docker volume create group
docker run \
-d \
-p 7000:8443 \
--name vscode_admin \
-e PASSWORD=$MASTERPW \
-e SUDO_PASSWORD=$MASTERPW \
-e PUID=1000 \
-e PGID=1000 \
--mount source=data,target=/data \
--mount source=group,target=/group_work \
$IMAGE
# remove carriage returns and spaces and pipe to while loop
cat $USERLIST | tr -d '\015\040' | while read port user password
do
# create user volume. If the container crashes the volume keeps existing.
docker volume create $user
# generate container for each user
# mount user volume, data volume (general, read only) and group work volume (general, read and write)
# the permissions of general volumes (data and group work) need to be changed with the master container (this can probably be coded as well)
docker run \
-d \
--cpus=$CPU \
--memory=$MEMORY \
--restart=on-failure:10 \
-p $port:8443 \
--name vscode_"$user" \
-e PASSWORD=$password \
-e PUID=1000 \
-e PGID=1000 \
-e DEFAULT_WORKSPACE=/config/project \
--mount source=$user,target=/config/project \
--mount source=data,target=/data,readonly \
--mount source=group,target=/group_work \
$IMAGE
done