This repository has been archived by the owner on Mar 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-to-jelastic.sh
62 lines (52 loc) · 1.7 KB
/
deploy-to-jelastic.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
#! /bin/bash
if [ $# -lt 5 ] ; then
echo "Usage: $0 hosterUrl appId login password envName [deploy_group = cp] [path-to-manifest = manifest.jps] [tag = latest] [useExistingVolumes = false]"
exit 0
fi
. helpers.sh
HOSTER_URL=$1
APPID=$2
SESSION=$(getSession $3 $4 ${HOSTER_URL})
ENV_NAME=$5
DEPLOY_GROUP=${6:-cp}
MANIFEST=${7:-manifest.jps}
TAG=${8:-latest}
USE_EXISTING_VOLUMES=${9:-false}
wasEnvCreated() {
echo "envName = $2" >&2
local envs=$1
local envName=$2
echo "Check if environment <$envName> exists..." >&2
local envExists=$(echo $envs | jq '[.infos[].env.envName]' | jq "index(\"$envName\")")
echo "Existence of environment <$envName> checked" >&2
echo $envExists
}
redeployEnvironment() {
local session=$1
local envName=$2
local deployGroup=$3
local tag=$4
local useExistingVolumes=$5
echo "Redeploying group <$deployGroup> of environment <$envName>" >&2
local cmd=$(curl -k \
-H "${CONTENT_TYPE}" \
-A "${USER_AGENT}" \
-X POST \
-fsS ${HOSTER_URL}/1.0/environment/control/rest/redeploycontainersbygroup \
-d "appid=${APPID}&session=${session}&envName=${envName}&tag=${tag}&nodeGroup=${deployGroup}&useExistingVolumes=${useExistingVolumes}&delay=20")
# TODO: when the redeploy has worked, the exitOnFail interprets that as an error
# exitOnFail $cmd
echo "Environment redeployed" >&2
}
deployToJelastic() {
ENVS=$(getEnvs $SESSION)
CREATED=$(wasEnvCreated "$ENVS" "${ENV_NAME}")
if [ "${CREATED}" == "null" ]; then
installEnv $SESSION "${ENV_NAME}" "$MANIFEST"
else
startEnvIfNecessary $SESSION "${ENV_NAME}" "$ENVS"
redeployEnvironment $SESSION "${ENV_NAME}" ${DEPLOY_GROUP} ${TAG} ${USE_EXISTING_VOLUMES}
fi
exit 0
}
deployToJelastic