forked from KyberNetwork/KyberSwap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·138 lines (132 loc) · 2.79 KB
/
deploy.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
#!/bin/bash
print_usage() {
cat <<EOF
Usage: You need to include all 4 argument -b, -e, -d, -s
-h, --help: print this message
-b, --branch: deployment branch
-e, --env: deployment environment
-d, --domain: domain name and AWS S3 bucket name
-s, --secret: secret travis-ci api token
EOF
}
if (( $# != 8 )) && (( $# != 1 )) ; then
echo "The number of flags must be exactly 4 including: -b, -e, -d, -s"
print_usage
exit 1
fi
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h|--help)
print_usage
exit 0
;;
-b|--branch)
branch="$2"
shift # past argument
shift # past value
;;
-e|--env)
build_env="$2"
shift # past argument
shift # past value
;;
-d|--domain)
domain_name="$2"
shift # past argument
shift # past value
;;
-s|--secret)
secret_token="$2"
shift # past argument
shift # past value
;;
*) # unknown option
echo "Invalid option: $1 $2"
print_usage
exit 1
;;
esac
done
body=$(cat << EOF
{
"request": {
"branch": "$branch",
"config": {
"sudo": "required",
"language": "node_js",
"cache": {
"directories": [
"node_modules"
]
},
"node_js": [
"8"
],
"script": [
"echo \"npm test temporarily disabled\""
],
"install": [
"npm install",
"npm run build-$build_env",
"mkdir upload",
"mv dist/$build_env/index.html upload",
"mv dist/$build_env/*.css upload",
"mv dist/$build_env/*.js upload"
],
"deploy": [
{
"provider": "s3",
"access_key_id": "\$AWS_ACCESS_KEY_ID",
"secret_access_key": "\$AWS_SECRET_ACCESS_KEY",
"bucket": "$domain_name",
"region": "ap-southeast-1",
"acl": "public_read",
"local_dir": "upload",
"skip_cleanup": true,
"on": {
"branch": "$branch"
}
},
{
"provider": "s3",
"access_key_id": "\$AWS_ACCESS_KEY_ID",
"secret_access_key": "\$AWS_SECRET_ACCESS_KEY",
"bucket": "$domain_name",
"region": "ap-southeast-1",
"acl": "public_read",
"local_dir": "upload",
"upload-dir": "swap",
"skip_cleanup": true,
"on": {
"branch": "$branch"
}
},
{
"provider": "s3",
"access_key_id": "\$AWS_ACCESS_KEY_ID",
"secret_access_key": "\$AWS_SECRET_ACCESS_KEY",
"bucket": "$domain_name",
"region": "ap-southeast-1",
"acl": "public_read",
"local_dir": "upload",
"upload-dir": "transfer",
"skip_cleanup": true,
"on": {
"branch": "$branch"
}
}
]
}
}
}
EOF
)
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Travis-API-Version: 3" \
-H "Authorization: token $secret_token" \
-d "$body" \
https://api.travis-ci.com/repo/KyberNetwork%2FKyberSwap/requests