-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkspace.sh
executable file
·58 lines (48 loc) · 1.06 KB
/
workspace.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
#!/bin/bash
set -u -e
cd $(dirname $0)
IMAGE_NAME=base
CONTAINER_NAME=workspace
USER_NAME=user
build-image() {
[[ $(docker images | grep $IMAGE_NAME) ]] || \
docker build \
-t $IMAGE_NAME \
--build-arg="USERNAME=$USER_NAME" .
}
run-container() {
docker run -it --rm \
--name $CONTAINER_NAME \
--hostname $CONTAINER_NAME \
-v $(pwd)/projects:/workspace \
$IMAGE_NAME
}
remove-container() {
docker rm -f $CONTAINER_NAME
}
remove-image() {
docker rmi -f $IMAGE_NAME
}
usage() {
source scripts/color.sh
echo -e "
$(title Usage:)
$(command $0 '<COMMAND>')
$(title Commands:)
$(command help) \t Print this help message
$(command start), $(command run) Build the image if not exist and run the container. Note that the container will be deleted after exit it.
$(command remove), $(command rm) \t Remove the image
"
}
case ${1:-''} in
start | run)
build-image
run-container
;;
remove | rm)
remove-image
;;
*)
usage
;;
esac