forked from gameontext/gameon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
go-run.sh
executable file
·151 lines (139 loc) · 3.09 KB
/
go-run.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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
# Support environments with docker-machine
# For base linux users, 127.0.0.1 is fine, but w/ docker-machine we need to
# use the host ip instead. So we'll generate an over-ridden env file that
# will get passed/copied properly into the target servers
#
# Use this script when you're developing rooms, or a subset of
# Game On services
#
# This will help start/stop Game On services
#
#set the action, default to help if none passed.
if [ $# -lt 1 ]
then
ACTION=help
else
ACTION=$1
shift
fi
#for when running from scripts..
if [ $# -gt 0 ] && [ $1 == "--nologs" ]
then
NOLOGS=1
shift
else
NOLOGS=0
fi
ALLPROJECTS="auth map mediator player proxy room webapp"
if [ $# -lt 1 ]
then
PROJECTS=$ALLPROJECTS
elif [ $1 == "all" ]
then
PROJECTS=$ALLPROJECTS
else
PROJECTS=$@
fi
OVERRIDE=
if [ -f docker-compose.override.yml ]
then
OVERRIDE='-f docker-compose.override.yml'
fi
#configure docker compose command
COMPOSE="docker-compose -f docker-compose.yml ${OVERRIDE} -f platformservices.yml"
if [ "$(uname)" != "Darwin" ] && [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]
then
COMPOSE="sudo ${COMPOSE}"
fi
#setup docker ip.
NAME=${DOCKER_MACHINE_NAME-empty}
IP=127.0.0.1
if [ $NAME != "empty" ]
then
IP=$(docker-machine ip $NAME)
fi
up_log() {
if [ $NOLOGS -eq 0 ]
then
echo "${COMPOSE} up -d $PROJECTS, logs will continue in the foreground."
else
echo "${COMPOSE} up -d $PROJECTS, logs are viewable using go-run.sh logs $PROJECTS"
fi
${COMPOSE} up -d $@
if [ $NOLOGS -eq 0 ]
then
${COMPOSE} logs --tail="5" -f $@
fi
}
down_rm() {
echo "docker-compose stop $@"
${COMPOSE} stop $@
${COMPOSE} rm $@
}
gradle_build() {
for project in $@
do
echo -n "Evaluating ${project} for gradle build. :: "
if [ -d "${project}" ] && [ -e "${project}/build.gradle" ]
then
echo "Building project ${project} with gradle"
cd "$project"
../gradlew build
rc=$?
cd ..
if [ $rc != 0 ]
then
echo Gradle build failed. Please investigate, GameOn is unlikely to work until the issue is resolved.
exit 1
fi
else
echo "No need to gradle build project ${project}"
fi
done
}
usage() {
echo "Actions: start|stop|restart|rebuild|rm|logs"
echo "Use optional arguments to select one or more specific image"
}
case "$ACTION" in
logs)
${COMPOSE} logs -f $PROJECTS
;;
start|up)
up_log $PROJECTS
;;
stop|down)
echo "docker-compose stop $PROJECTS"
${COMPOSE} stop $PROJECTS
;;
restart)
down_rm $PROJECTS
up_log $PROJECTS
;;
rebuild)
down_rm $PROJECTS
echo "gradle build for $PROJECTS"
gradle_build $PROJECTS
if [ $? != 0 ]
then
echo Gradle build of $PROJECTS failed.. please examine logs and retry as appropriate.
exit 3
fi
echo "docker-compose build --pull $PROJECTS"
${COMPOSE} build --pull
if [ $? != 0 ]
then
echo Docker build of $PROJECTS failed.. please examine logs and retry as appropriate.
exit 2
fi
up_log $PROJECTS
;;
rm)
echo "docker-compose rm $PROJECTS"
${COMPOSE} rm $PROJECTS
;;
*)
usage
;;
esac