This repository has been archived by the owner on May 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
test-environment.sh
executable file
·63 lines (54 loc) · 1.55 KB
/
test-environment.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
#!/bin/sh
WORKDIR=`pwd | rev | cut -d "/" -f1 | rev`
RED='\033[0;31m'
YELLOW='\033[0;33m'
GREEN='\033[0;32m'
BLUE='\033[0;94m'
RESET='\033[0;00m'
create_test_environment() {
printf "${GREEN}Creating${RESET} new Spark test environment (container: ${BLUE}${WORKDIR}${RESET})...\n"
docker run \
--name $WORKDIR \
-p 8080:8080 \
-p 9999:9999 \
-d \
-e GRADLE_OPTS="-Dorg.gradle.native=false" \
-v /`pwd`/src/test/resources/log4j.properties:/usr/local/spark/conf/log4j.properties \
-v /`pwd`:`pwd` \
-it \
--workdir="/`pwd`" \
uncharted/sparklet:2.0.0 bash
}
run_test_environment() {
printf "${GREEN}Resuming${RESET} existing Spark test environment (container: ${BLUE}${WORKDIR}${RESET})...\n"
docker start $WORKDIR
}
stop_test_environment() {
printf "${YELLOW}Stopping${RESET} Spark test environment (container: ${BLUE}${WORKDIR}${RESET})...\n"
docker stop $WORKDIR
}
kill_test_environment() {
printf "${RED}Destroying${RESET} Spark test environment (container: ${BLUE}${WORKDIR}${RESET})...\n"
docker rm -fv $WORKDIR
}
attach_test_environment() {
printf "${GREEN}Attaching${RESET} to Spark test environment (container: ${BLUE}${WORKDIR}${RESET})...\n"
docker attach $WORKDIR
}
verify_test_environment() {
PRESENT=$(docker ps -a -q -f name=$WORKDIR)
if [ -n "$PRESENT" ]; then
run_test_environment
else
create_test_environment
fi
}
if [ "$1" = "stop" ]; then
stop_test_environment
elif [ "$1" = "rm" ]; then
kill_test_environment
elif [ "$1" = "attach" ]; then
attach_test_environment
else
verify_test_environment
fi