-
Notifications
You must be signed in to change notification settings - Fork 2
/
deploy.sh
executable file
·64 lines (47 loc) · 1.78 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
#!/bin/bash
deploy_tarball="$HOME/deploy_tarball.tar.gz"
heroku_base_url="https://api.heroku.com/apps/$HEROKU_APP_NAME"
heroku_sources_url="$heroku_base_url/sources"
heroku_builds_url="$heroku_base_url/builds"
function create_tarball() {
echo " - Creating tarball"
tar -zcf "$deploy_tarball" .
echo " tarball: $deploy_tarball"
}
function create_source_endpoint() {
echo " - Creating source endpoint"
curl -s -n -X POST "$heroku_sources_url" \
-H 'Accept: application/vnd.heroku+json; version=3' \
-H "Authorization: Bearer $HEROKU_API_KEY" > /tmp/sources.json
get_url="$(cat /tmp/sources.json | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["source_blob"]["get_url"]' )"
put_url="$(cat /tmp/sources.json | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["source_blob"]["put_url"]' )"
echo " get_url: $get_url"
echo " put_url: $put_url"
}
function upload_to_source_endpoint() {
echo " - Uploading to source endpoint"
curl -s "$put_url" -X PUT -H 'Content-Type:' --data-binary @$deploy_tarball
}
function create_build() {
echo " - Creating a build"
curl -s -n -X POST "$heroku_builds_url" \
-d "{\"source_blob\":{\"url\":\"$get_url\", \"version\": \"$REVISION\"}}" \
-H 'Accept: application/vnd.heroku+json; version=3.streaming-build-output' \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $HEROKU_API_KEY" > /tmp/deploy.json
stream_url="$(cat /tmp/deploy.json | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["output_stream_url"]' )"
}
function stream_result() {
echo " - Waiting for results"
echo ""
curl $stream_url
}
function main() {
echo "Deployment via Heroku API"
create_tarball
create_source_endpoint
upload_to_source_endpoint
create_build
stream_result
}
main