This repository has been archived by the owner on Oct 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
upgrade.sh
91 lines (88 loc) · 5.34 KB
/
upgrade.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
# curl -u ""$RANCHER_USER":"$RANCHER_PASS"" \
# -X POST \
# -H 'Accept: application/json' \
# -H 'Content-Type: application/json' \
# -d '{
# "inServiceStrategy":{"launchConfig": {"imageUuid":"docker:obdev/web_builder_fronted_flowz:master","kind": "container","labels":{"io.rancher.container.pull_image": "always","io.rancher.scheduler.affinity:host_label": "machine=webbuilder-front"},"ports": ["443:443/tcp","80:80/tcp"],"version": "41b922d1-afaf-4401-91cd-7e8cd453cbaf","healthCheck": {"type": "instanceHealthCheck","healthyThreshold": 2,"initializingTimeout": 60000,"interval": 2000,"name": null,"port": 80,"recreateOnQuorumStrategyConfig": {"type": "recreateOnQuorumStrategyConfig","quorum": 1},"reinitializingTimeout": 60000,"requestLine": "GET \"http://localhost\" \"HTTP/1.0\"","responseTimeout": 60000,"strategy": "recreateOnQuorum","unhealthyThreshold": 3},"networkMode": "managed"}},"toServiceStrategy":null}' \
# 'http://rancher.flowz.com:8080/v2-beta/projects/1a29/services/1s477?action=upgrade'
if [ "$TRAVIS_BRANCH" = "master" ]
then
{
echo "call $TRAVIS_BRANCH branch"
ENV_ID=`curl -u ""$RANCHER_ACCESSKEY_MASTER":"$RANCHER_SECRETKEY_MASTER"" -X GET -H 'Accept: application/json' -H 'Content-Type: application/json' "$RANCHER_URL_MASTER/v2-beta/projects?name=Production" | jq '.data[].id' | tr -d '"'`
echo $ENV_ID
USERNAME="$DOCKER_USERNAME_FLOWZ";
TAG="latest";
FRONT_HOST="$FRONT_HOST_MASTER";
RANCHER_ACCESSKEY="$RANCHER_ACCESSKEY_MASTER";
RANCHER_SECRETKEY="$RANCHER_SECRETKEY_MASTER";
RANCHER_URL="$RANCHER_URL_MASTER";
SERVICE_NAME="$SERVICE_NAME_MASTER";
BACKEND_HOST="$BACKEND_HOST_MASTER";
STACK_SERVICE_NAME_FOR_FRONT="$STACK_SERVICE_NAME_FOR_FRONT_MASTER";
RDB_HOST="$RDB_HOST_MASTER";
RDB_PORT="$RDB_PORT_MASTER";
}
elif [ "$TRAVIS_BRANCH" = "develop" ]
then
{
echo "call $TRAVIS_BRANCH branch"
ENV_ID=`curl -u ""$RANCHER_ACCESSKEY_DEVELOP":"$RANCHER_SECRETKEY_DEVELOP"" -X GET -H 'Accept: application/json' -H 'Content-Type: application/json' "$RANCHER_URL_DEVELOP/v2-beta/projects?name=Develop" | jq '.data[].id' | tr -d '"'`
echo $ENV_ID
USERNAME="$DOCKER_USERNAME";
TAG="dev";
FRONT_HOST="$FRONT_HOST_DEVELOP";
RANCHER_ACCESSKEY="$RANCHER_ACCESSKEY_DEVELOP";
RANCHER_SECRETKEY="$RANCHER_SECRETKEY_DEVELOP";
RANCHER_URL="$RANCHER_URL_DEVELOP";
SERVICE_NAME="$SERVICE_NAME_DEVELOP";
BACKEND_HOST="$BACKEND_HOST_DEVELOP";
STACK_SERVICE_NAME_FOR_FRONT="$STACK_SERVICE_NAME_FOR_FRONT_DEVELOP";
RDB_HOST="$RDB_HOST_DEVELOP";
RDB_PORT="$RDB_PORT_DEVELOP";
}
elif [ "$TRAVIS_BRANCH" = "staging" ]
then
{
echo "call $TRAVIS_BRANCH branch"
ENV_ID=`curl -u ""$RANCHER_ACCESSKEY_STAGING":"$RANCHER_SECRETKEY_STAGING"" -X GET -H 'Accept: application/json' -H 'Content-Type: application/json' "$RANCHER_URL_STAGING/v2-beta/projects?name=Staging" | jq '.data[].id' | tr -d '"'`
echo $ENV_ID
USERNAME="$DOCKER_USERNAME";
TAG="staging";
FRONT_HOST="$FRONT_HOST_STAGING";
RANCHER_ACCESSKEY="$RANCHER_ACCESSKEY_STAGING";
RANCHER_SECRETKEY="$RANCHER_SECRETKEY_STAGING";
RANCHER_URL="$RANCHER_URL_STAGING";
SERVICE_NAME="$SERVICE_NAME_STAGING";
BACKEND_HOST="$BACKEND_HOST_STAGING";
STACK_SERVICE_NAME_FOR_FRONT="$STACK_SERVICE_NAME_FOR_FRONT_STAGING";
RDB_HOST="$RDB_HOST_STAGING";
RDB_PORT="$RDB_PORT_STAGING";
}
else
{
echo "call $TRAVIS_BRANCH branch"
ENV_ID=`curl -u ""$RANCHER_ACCESSKEY_QA":"$RANCHER_SECRETKEY_QA"" -X GET -H 'Accept: application/json' -H 'Content-Type: application/json' "$RANCHER_URL_QA/v2-beta/projects?name=Develop" | jq '.data[].id' | tr -d '"'`
echo $ENV_ID
USERNAME="$DOCKER_USERNAME";
TAG="qa";
FRONT_HOST="$FRONT_HOST_QA";
RANCHER_ACCESSKEY="$RANCHER_ACCESSKEY_QA";
RANCHER_SECRETKEY="$RANCHER_SECRETKEY_QA";
RANCHER_URL="$RANCHER_URL_QA";
SERVICE_NAME="$SERVICE_NAME_QA";
BACKEND_HOST="$BACKEND_HOST_QA";
STACK_SERVICE_NAME_FOR_FRONT="$STACK_SERVICE_NAME_FOR_FRONT_QA";
RDB_HOST="$RDB_HOST_QA";
RDB_PORT="$RDB_PORT_QA";
}
fi
SERVICE_ID=`curl -u ""$RANCHER_ACCESSKEY":"$RANCHER_SECRETKEY"" -X GET -H 'Accept: application/json' -H 'Content-Type: application/json' "$RANCHER_URL/v2-beta/projects/$ENV_ID/services?name=$SERVICE_NAME" | jq '.data[].id' | tr -d '"'`
echo $SERVICE_ID
curl -u ""$RANCHER_ACCESSKEY":"$RANCHER_SECRETKEY"" \
-X POST \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"inServiceStrategy":{"launchConfig": {"imageUuid":"docker:'$USERNAME'/web_builder_fronted_flowz:'$TAG'","kind": "container","labels":{"io.rancher.container.pull_image": "always","io.rancher.scheduler.affinity:host_label": "'"$FRONT_HOST"'", "io.rancher.scheduler.affinity:container_label_soft_ne": "'"$STACK_SERVICE_NAME_FOR_FRONT"'"},"healthCheck": {"type": "instanceHealthCheck","healthyThreshold": 2,"initializingTimeout": 60000,"interval": 2000,"name": null,"port": 80,"recreateOnQuorumStrategyConfig": {"type": "recreateOnQuorumStrategyConfig","quorum": 1},"reinitializingTimeout": 60000,"requestLine": "GET \"http://localhost\" \"HTTP/1.0\"","responseTimeout": 60000,"strategy": "recreateOnQuorum","unhealthyThreshold": 3},"networkMode": "managed"}},"toServiceStrategy":null}' \
$RANCHER_URL/v2-beta/projects/$ENV_ID/services/$SERVICE_ID?action=upgrade