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 0
/
Copy pathupgrade.sh
executable file
·91 lines (89 loc) · 4.51 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
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";
DOMAINKEY="$DOMAINKEY_MASTER";
RANCHER_ACCESSKEY="$RANCHER_ACCESSKEY_MASTER";
RANCHER_SECRETKEY="$RANCHER_SECRETKEY_MASTER";
RANCHER_URL="$RANCHER_URL_MASTER";
apiKey="$apiKey_master";
site="$site_master";
secret="$secret_master";
SERVICE_NAME="$SERVICE_NAME_MASTER";
BACKEND_HOST="$BACKEND_HOST_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";
DOMAINKEY="$DOMAINKEY_DEVELOP";
RANCHER_ACCESSKEY="$RANCHER_ACCESSKEY_DEVELOP";
RANCHER_SECRETKEY="$RANCHER_SECRETKEY_DEVELOP";
RANCHER_URL="$RANCHER_URL_DEVELOP";
apiKey="$apiKey_develop";
site="$site_develop";
secret="$secret_develop";
SERVICE_NAME="$SERVICE_NAME_DEVELOP";
BACKEND_HOST="$BACKEND_HOST_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";
DOMAINKEY="$DOMAINKEY_STAGING";
RANCHER_ACCESSKEY="$RANCHER_ACCESSKEY_STAGING";
RANCHER_SECRETKEY="$RANCHER_SECRETKEY_STAGING";
RANCHER_URL="$RANCHER_URL_STAGING";
apiKey="$apiKey_staging";
site="$site_staging";
secret="$secret_staging";
SERVICE_NAME="$SERVICE_NAME_STAGING";
BACKEND_HOST="$BACKEND_HOST_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";
DOMAINKEY="$DOMAINKEY_QA";
RANCHER_ACCESSKEY="$RANCHER_ACCESSKEY_QA";
RANCHER_SECRETKEY="$RANCHER_SECRETKEY_QA";
RANCHER_URL="$RANCHER_URL_QA";
apiKey="$apiKey_qa";
site="$site_qa";
secret="$secret_qa";
SERVICE_NAME="$SERVICE_NAME_QA";
BACKEND_HOST="$BACKEND_HOST_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'/subscription_backend_service_flowz:'$TAG'","kind": "container","labels":{"io.rancher.container.pull_image": "always","io.rancher.scheduler.affinity:host_label": "'"$BACKEND_HOST"'"},"ports": ["3039:3039/tcp","4039:4039/tcp"],"environment": {"RDBHost": "'"$RDB_HOST"'","RDBPort": "'"$RDB_PORT"'","rdb":"'"$rdb"'","x_api_token":"'"$x_api_token"'","domainKey":"'"$DOMAINKEY"'","apiKey":"'"$apiKey"'","site":"'"$site"'","secret":"'"$secret"'"},"healthCheck": {"type": "instanceHealthCheck","healthyThreshold": 2,"initializingTimeout": 60000,"interval": 2000,"name": null,"port": 3039,"recreateOnQuorumStrategyConfig": {"type": "recreateOnQuorumStrategyConfig","quorum": 1},"reinitializingTimeout": 60000,"responseTimeout": 60000,"strategy": "recreateOnQuorum","unhealthyThreshold": 3},"networkMode": "managed"}},"toServiceStrategy":null}' \
$RANCHER_URL/v2-beta/projects/$ENV_ID/services/$SERVICE_ID?action=upgrade