-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·127 lines (96 loc) · 2.67 KB
/
run.sh
File metadata and controls
executable file
·127 lines (96 loc) · 2.67 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
# If file based logging is desired, use
# LOG_TO_FILE=/path/to/file run.sh
IMAGE_NAME=${IMAGE_NAME:=izaber/izaber_wamp}
CONTAINER_NAME=${CONTAINER_NAME:=izaber_wamp}
help () {
cat << HELP
Usage: run.sh [COMMAND] [ARGUMENTS]...
Performs various for nexus servers including building images, launching and debugging support
COMMANDS:
If no command is provided, the script will build, configure, and launch an instance of
the nexus container.
help
This help text
build
Forces a build of the container
stop
docker stop $CONTAINER_NAME
here
This will launch the nexus in the current environment without using docker
Useful when you're in the container itself or are developing locally
shell
This runs docker exec -ti $CONTAINER_NAME bash to allow shelling into a container
login
This runs docker exec -ti $CONTAINER_NAME bash to allow "logging in" to a container
Alias for shell
root
This runs docker exec -ti -u root $CONTAINER_NAME bash to allow "logging in" to a
container as root
If the command does not match any of the listed commands, the system will instantiate the
container then pass the entire set of arguments to be invoked in the new container.
HELP
}
build_docker_image () {
echo "Creating the ${IMAGE_NAME} docker image"
docker build --progress plain -t $IMAGE_NAME .
}
upsert_docker_image () {
if [[ "$(docker images -q ${IMAGE_NAME} 2> /dev/null)" == "" ]]; then
build_docker_image
fi
}
default_invoke_command () {
INVOKE_COMMAND="/src/docker/run-test.sh"
}
launch_container () {
text=$(sed 's/[[:space:]]\+/ /g' <<< ${INVOKE_COMMAND})
echo "Invoking: ${text}"
docker run --name $CONTAINER_NAME \
-ti \
-v `pwd`:/src \
--rm \
$IMAGE_NAME $INVOKE_COMMAND && \
echo "Started ${CONTAINER_NAME}."
}
shell () {
if [[ "$(docker inspect ${CONTAINER_NAME} 2> /dev/null)" == "[]" ]]; then
upsert_docker_image
INVOKE_COMMAND="/bin/bash"
launch_container
else
docker exec -ti $CONTAINER_NAME "/bin/bash"
fi
}
if [ $# -eq 0 ]; then
upsert_docker_image
default_invoke_command
launch_container
else
case $1 in
-h) help
;;
--help) help
;;
help) help
;;
build) build_docker_image
;;
stop) docker stop $CONTAINER_NAME
;;
here) default_invoke_command
cd /src/nexus/data
$INVOKE_COMMAND
;;
login) shell
;;
shell) shell
;;
root) docker exec -ti -u root $CONTAINER_NAME /bin/bash
;;
*) upsert_docker_image
INVOKE_COMMAND="$@"
launch_container
;;
esac
fi