-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathmanage.sh
executable file
·83 lines (71 loc) · 1.97 KB
/
manage.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
#!/usr/bin/env bash
set -e
REV=`git log -n 1 --pretty=format:%h -- docker/`
IMGNAME="suricatta-devenv"
function kill-container {
echo "Cleaning development container $IMGNAME:$REV..."
if $(docker ps | grep -q $IMGNAME); then
docker ps | grep $IMGNAME | awk '{print $1}' | xargs --no-run-if-empty docker kill
fi
if $(docker ps -a | grep -q $IMGNAME); then
docker ps -a | grep $IMGNAME | awk '{print $1}' | xargs --no-run-if-empty docker rm
fi
}
function remove-image {
echo "Clean old development image $IMGNAME..."
docker images | grep $IMGNAME | awk '{print $3}' | xargs --no-run-if-empty docker rmi
}
function build-devenv {
kill-container
echo "Building development image $IMGNAME:$REV..."
docker build --rm=true -t $IMGNAME:$REV -t $IMGNAME:latest --build-arg EXTERNAL_UID=$(id -u) docker/
}
function reset {
kill-container
if ! $(docker images | grep $IMGNAME | grep -q $REV); then
build-devenv
fi
}
function docker-run {
docker run --rm -ti \
-v `pwd`:/home/devuser/suricatta \
-v $HOME/.m2:/home/devuser/.m2 \
-w /home/devuser/suricatta \
$IMGNAME:latest $@
}
function run-devenv {
reset || exit -1;
mkdir -p $HOME/.m2
docker-run /bin/zsh
}
function run-tests {
reset || exit -1;
docker-run clojure -Adev:test
}
function help {
echo "suricatta devenv manager v$REV"
echo "USAGE: $0 OPTION"
echo "Options:"
echo "- clean Kill container and remove image"
echo "- build-devenv Build docker container for development"
echo "- run-devenv Run (and build if necessary) development container"
echo "- run-tests Execute unit tests for both backend and frontend"
}
case $1 in
clean)
kill-container
remove-image
;;
build-devenv)
build-devenv
;;
run-devenv)
run-devenv
;;
run-tests)
run-tests
;;
*)
help
;;
esac