-
Notifications
You must be signed in to change notification settings - Fork 0
/
heroku-deploy
executable file
·87 lines (68 loc) · 2.47 KB
/
heroku-deploy
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
#!/usr/bin/env bash
## Push to Heroku
##
## Because Heroku doesn't clearly support Python / Node hybrid projects I've
## hacked together this script to facilitate deploying to Heroku. The idea is
## to build everything Node is needed for locally, commit the build artifacts,
## and push that to Heroku. This way all we need from Heroku is a Python
## runtime.
##
## So the way it works is we clone our upstream (e.g. the GitHub origin repo)
## into a scratch temp directory on our system. Then build the node artificats,
## i.e. using npm, grunt, bower, etc. Then we commit those artifacts using git
## and push to Heroku. We don't push to origin (probably GitHub) because we
## don't want to version control the build artifacts. We delete the scratch
## repo when we're done.
RDIO_API_KEY=''
RDIO_API_SECRET=''
function choice {
CHOICE=''
local prompt="$*"
local answer
read -p "$prompt" answer
case "$answer" in
[yY1] ) CHOICE='y';;
[nN0] ) CHOICE='n';;
* ) CHOICE='n';;
esac
}
echo "Push to Heroku?"
echo "We'll clone a scratch copy of this repo and alter it in a temp directory."
echo "After pushing to Heroku the scratch copy will be removed."
echo
choice "Is this okay? [y/N] "
if [[ "$CHOICE" == "y" ]]; then
# if Rdio auth keys missing, prompt user
if [[ "$RDIO_API_KEY" == "" ]]; then
read -p "Enter Rdio API Key: " RDIO_API_KEY
fi
if [[ "$RDIO_API_SECRET" == "" ]]; then
read -p "Enter Rdio API Shared Secret: " RDIO_API_SECRET
fi
# use a temp repo so our alterations don't get reused
tmpdir=$(mktemp -d -t bingio)
# find upstream git repo url
upstream=$(git remote show origin | grep -o -m1 "https://.*$")
# clone repo and push into it
git clone $upstream $tmpdir
pushd $tmpdir
# run make-prod
./make-prod
# need to remove package.json so Heroku doesn't assume node.js app
git rm package.json
# pick a sed binary
type gsed && sedbin=gsed || sedbin=sed
# remove dist/ from .gitignore and add it to index
$($sedbin --in-place "s/dist//" .gitignore)
git add dist/
git ci -am 'auto-generated heroku release'
git remote add heroku git@heroku.com:bingio.git
# need to force because upstream will have different history
git push --force heroku master
# cleanup temp repo
popd
rm -rf $tmpdir
# set the env vars
heroku config:set RDIO_API_KEY=${RDIO_API_KEY}
heroku config:set RDIO_API_SECRET=${RDIO_API_SECRET}
fi