forked from eclipse-archived/codewind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
executable file
·194 lines (175 loc) · 6.97 KB
/
start.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/env bash
#*******************************************************************************
# Copyright (c) 2019 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v2.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v20.html
#
# Contributors:
# IBM Corporation - initial API and implementation
#*******************************************************************************
# Colours for success and error messages
GREEN='\033[0;32m'
RED='\033[0;31m'
BLUE='\033[0;36m'
RESET='\033[0m'
DEVMODE=false
REMOTE_MODE=false
printf "\n\n${BLUE}Running 'start.sh' to start codewind. $RESET\n";
while [ "$#" -gt 0 ]; do
case $1 in
-t|--tag) TAG="$2"; shift 2;;
--dev) DEVMODE=true; shift 1;;
--remote) REMOTE_MODE=true; shift 1;;
*) shift 1;;
esac
done
# If no tag argument then set to latest
if [ -z "$TAG" ]; then
TAG='latest';
fi
printf "\nTag is set to $TAG\n";
# CREATE CODEWIND-WORKSPACE IF NOT EXISTS
printf "\n\n${BLUE}CREATING CODEWIND-WORKSPACE IF IT DOESN'T EXIST${RESET}\n"
mkdir -m 777 -p codewind-workspace
# Save the git config required to make an initial commit.
mkdir -m 777 -p codewind-workspace/.config
GIT_CONFIG=codewind-workspace/.config/git.config
rm $GIT_CONFIG
git config -f $GIT_CONFIG --add user.name "`git config --get user.name || echo 'codewind user'`"
git config -f $GIT_CONFIG --add user.email "`git config --get user.email || echo 'codewind.user@localhost'`"
# Set docker-compose file
if [ "$REMOTE_MODE" = true ]; then
printf "\nRemote mode is enabled\n";
DOCKER_COMPOSE_FILE="docker-compose.yaml"
else
printf "\nDefault Local mode is enabled\n";
DOCKER_COMPOSE_FILE="docker-compose.yaml -f docker-compose-local.yaml"
fi
if [ "$DEVMODE" = true ]; then
printf "\nDev mode is enabled\n";
DOCKER_COMPOSE_FILE="docker-compose.yaml -f docker-compose-dev.yaml"
fi
# REMOVE PREVIOUS DOCKER PROCESSES FOR CODEWIND
printf "\n\n${BLUE}CHECKING FOR EXISTING CODEWIND PROCESSES $RESET\n";
# Check for existing processes (stopped or running)
if [ $(docker ps -q -a --filter name=codewind | wc -l) -gt 0 ]; then
printf "\n${RED}Existing processes found $RESET\n";
# Check for running processes only
if [ $(docker ps -q --filter name=codewind | wc -l) -gt 0 ]; then
printf "\nStopping existing processes\n";
# Stop running processes
docker stop $(docker ps -q --filter name=codewind)
# Check stop command ran properly or exit
if [ $? -ne 0 ]; then
printf "\n${RED}Something went wrong while stopping existing processes.\n";
printf "Exiting $RESET\n";
exit;
fi
fi
printf "\nRemoving stopped processes";
# Remove all processes (if running now stopped)
docker rm $(docker ps -a -q --filter name=codewind)
# Check remove command ran properly or exit
if [ $? -ne 0 ]; then
printf "\n${RED}Something went wrong while removing existing processes.\n";
printf "Exiting $RESET\n";
exit;
else
printf "\n${GREEN}Existing processes stopped and removed $RESET\n";
fi
else
printf "\n${GREEN}No existing processes found $RESET\n";
fi
# REMOVE PREVIOUS DOCKER PROCESSES FOR CODEWIND
printf "\n\n${BLUE}CHECKING FOR EXISTING CODEWIND APPS $RESET\n";
# Check for existing processes (stopped or running)
if [ $(docker ps -q -a --filter name=mc- | wc -l) -gt 0 ]; then
printf "\n${RED}Existing applications found $RESET\n";
# Check for running processes only
if [ $(docker ps -q --filter name=mc- | wc -l) -gt 0 ]; then
printf "\nStopping existing applications\n";
# Stop running processes
docker stop $(docker ps -q --filter name=mc-)
# Check stop command ran properly or exit
if [ $? -ne 0 ]; then
printf "\n${RED}Something went wrong while stopping existing applications.\n";
printf "Exiting $RESET\n";
exit;
fi
fi
printf "\nRemoving stopped applications";
# Remove all processes (if running now stopped)
docker rm $(docker ps -a -q --filter name=mc-)
# Check remove command ran properly or exit
if [ $? -ne 0 ]; then
printf "\n${RED}Something went wrong while removing existing applications.\n";
printf "Exiting $RESET\n";
exit;
else
printf "\n${GREEN}Existing applications stopped and removed $RESET\n";
fi
else
printf "\n${GREEN}No existing applications found $RESET\n";
fi
# RUN DOCKER COMPOSE
# Docker-compose will use the built images and turn them into containers
printf "\n\n${BLUE}RUNNING DOCKER-COMPOSE IN: $PWD $RESET\n";
# Export variables for docker-compose substitution
# Export to overwrite .env file
export REPOSITORY='';
export TAG
export WORKSPACE_DIRECTORY=$PWD/codewind-workspace;
# Export HOST_OS for fix to Maven failing on Windows only as host
export HOST_OS=$(uname);
export REMOTE_MODE;
export HOST_HOME=$HOME
export ARCH=$(uname -m);
# Select the right images for this architecture.
if [ "$ARCH" = "x86_64" ]; then
export PLATFORM="-amd64"
else
export PLATFORM="-$ARCH"
fi
# If using Mingw64/Msys2 (a faux-Linux build environment on Windows), replace mingw with windows
if [[ $HOST_OS == *"MINGW"* ]]; then
export HOST_OS=windows
fi
docker-compose -f $DOCKER_COMPOSE_FILE up -d;
if [ $? -eq 0 ]; then
# Reset so we don't get conflicts
unset REPOSITORY;
unset WORKSPACE_DIRECTORY;
unset REMOTE_MODE;
printf "\n\n${GREEN}SUCCESSFULLY STARTED CONTAINERS $RESET\n";
printf "\nCurrent running codewind containers\n";
docker ps --filter name=codewind
else
printf "\n\n${RED}FAILED TO START CONTAINERS $RESET\n";
exit;
fi
printf "\n\n${BLUE}PAUSING TO ALLOW CONTAINERS TIME TO START $RESET\n";
sleep 20;
# Check to see if any containers exited straight away
printf "\n\n${BLUE}CHECKING FOR codewind CONTAINERS THAT EXITED STRAIGHT AFTER BEING RUN $RESET\n";
EXITED_PROCESSES=$(docker ps -q --filter "name=codewind" --filter "status=exited" | wc -l)
if [ $EXITED_PROCESSES -gt 0 ]; then
printf "\n${RED}Exited containers found $RESET\n";
# docker ps --filter "name=codewind" --filter "status=exited";
NUM_CODE_ZERO=$(docker ps -q --filter "name=codewind" --filter "status=exited" --filter "exited=0" | wc -l);
NUM_CODE_ONE=$(docker ps -q --filter "name=codewind" --filter "status=exited" --filter "exited=1" | wc -l);
if [ $NUM_CODE_ZERO -gt 0 ]; then
printf "\n${RED}$NUM_CODE_ZERO found with an exit code '0' $RESET\n";
docker ps --filter "name=codewind" --filter "status=exited" --filter "exited=0";
printf "\nUse 'docker logs [container name]' to find why the exit happened";
fi
if [ $NUM_CODE_ONE -gt 0 ]; then
printf "\n${RED}$NUM_CODE_ONE found with an exit code '1' $RESET\n";
docker ps --filter "name=codewind" --filter "status=exited" --filter "exited=1";
printf "\nUse 'docker logs [container name]' to debug exit";
fi
else
printf "\n${GREEN}No containers exited $RESET\n";
fi
printf "\n\n${BLUE}codewind CONTAINERS NOW AVAILABLE. PORTAL API ACCESSIBLE AT localhost:9090, PERFORMANCE UI at localhost:9095 $RESET\n";