Skip to content
This repository was archived by the owner on Mar 1, 2023. It is now read-only.

Commit 0d94c0c

Browse files
authored
Update deploy and upgrade scripts to work on Unix (#176)
* Fix sed usage in Heroku upgrade/deploy scripts * Fix sed usage in CF upgrade script * Check existing buildpack before attempting to update it
1 parent 626c64d commit 0d94c0c

File tree

3 files changed

+47
-36
lines changed

3 files changed

+47
-36
lines changed

deployment/deploy-heroku.sh

+20-18
Original file line numberDiff line numberDiff line change
@@ -53,32 +53,34 @@ CONFIG_DIR="$SCRIPT_DIR"/config
5353
###################
5454

5555
pushd "$ASSETS_DIR"/api
56-
heroku create ${API_HOST} --buildpack https://github.com/heroku/heroku-buildpack-ruby.git#v200
57-
heroku addons:create heroku-postgresql:hobby-dev -a ${API_HOST}
58-
heroku addons:create heroku-redis:hobby-dev -a ${API_HOST}
59-
heroku config:set WEBSOCKET_PORT=4443 CLIENT_ORIGIN=https://${WEB_HOST}.herokuapp.com SESSION_TIME=${SESSION_TIME} -a ${API_HOST}
56+
heroku create ${API_HOST} --buildpack https://github.com/heroku/heroku-buildpack-ruby.git#v200
57+
heroku addons:create heroku-postgresql:hobby-dev -a ${API_HOST}
58+
heroku addons:create heroku-redis:hobby-dev -a ${API_HOST}
59+
heroku config:set WEBSOCKET_PORT=4443 CLIENT_ORIGIN=https://${WEB_HOST}.herokuapp.com SESSION_TIME=${SESSION_TIME} -a ${API_HOST}
6060

61-
rm -rf .git # blow away any existent git directory from a previous run
62-
git init .
63-
git add .
64-
git commit -m "Packaging for initial Heroku deployment"
65-
git push --set-upstream https://git.heroku.com/${API_HOST}.git master
66-
heroku run rake admin:create_user [email protected] ADMIN_PASSWORD=password -a ${API_HOST}
61+
rm -rf .git # blow away any existent git directory from a previous run
62+
git init .
63+
git add .
64+
git commit -m "Packaging for initial Heroku deployment"
65+
git push --set-upstream https://git.heroku.com/${API_HOST}.git master
66+
heroku run rake admin:create_user [email protected] ADMIN_PASSWORD=password -a ${API_HOST}
6767
popd
6868

6969
###########################
7070
# Deploy the web frontend
7171
###########################
7272

73-
cp "$CONFIG_DIR"/config.js "$ASSETS_DIR"/web/public_html
7473
pushd "$ASSETS_DIR"/web
75-
sed -i '' "s/{{api-app-name}}/${API_HOST}/" public_html/config.js
74+
sed \
75+
-e "s/{{api-app-name}}/${API_HOST}/" \
76+
<"$CONFIG_DIR"/config.js \
77+
>"$ASSETS_DIR"/web/public_html/config.js
7678

77-
heroku create ${WEB_HOST} --buildpack https://github.com/heroku/heroku-buildpack-static
79+
heroku create ${WEB_HOST} --buildpack https://github.com/heroku/heroku-buildpack-static
7880

79-
rm -rf .git # blow away any existent git directory from a previous run
80-
git init .
81-
git add .
82-
git commit -m "Packaging for initial Heroku deployment"
83-
git push --set-upstream https://git.heroku.com/${WEB_HOST}.git master
81+
rm -rf .git # blow away any existent git directory from a previous run
82+
git init .
83+
git add .
84+
git commit -m "Packaging for initial Heroku deployment"
85+
git push --set-upstream https://git.heroku.com/${WEB_HOST}.git master
8486
popd

deployment/upgrade-cf.sh

+9-4
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,23 @@ set -e
44

55
WEB_HOST=$1
66
API_HOST=$2
7-
CF_URL=${3:-https://api.run.pivotal.io}
7+
API_ENDPOINT=${3:-https://api.run.pivotal.io}
8+
APP_DOMAIN=${4:-cfapps.io}
89
SESSION_TIME=${SESSION_TIME:-'""'}
910

1011
# The directory in which this script is located
1112
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1213
ASSETS_DIR="$SCRIPT_DIR"/assets
1314
CONFIG_DIR="$SCRIPT_DIR"/config
1415

15-
cf login -a $CF_URL
16+
cf login -a $API_ENDPOINT
1617

1718
cf push -f "$CONFIG_DIR"/manifest-api.yml -p "$ASSETS_DIR"/api --var api-app-name=$API_HOST --var web-app-name=$WEB_HOST --var pcf-url=$CF_URL --var session-time=$SESSION_TIME
1819

19-
sed -i '' "s/{{api-app-name}}/${API_HOST}/" "$CONFIG_DIR"/config.js
20-
cp "$CONFIG_DIR"/config.js "$ASSETS_DIR"/web
20+
sed \
21+
-e "s/{{api-app-name}}/${API_HOST}/" \
22+
-e "s/{{pcf-url}}/${APP_DOMAIN}/" \
23+
<"$CONFIG_DIR"/config.js \
24+
>"$ASSETS_DIR"/web/config.js
25+
2126
cf push -f "$CONFIG_DIR"/manifest-web.yml -p "$ASSETS_DIR"/web --var api-app-name=$API_HOST --var web-app-name=$WEB_HOST

deployment/upgrade-heroku.sh

+18-14
Original file line numberDiff line numberDiff line change
@@ -61,26 +61,30 @@ fi
6161
###################
6262

6363
pushd "$ASSETS_DIR"/api
64-
heroku buildpacks:set -a ${API_HOST} https://github.com/heroku/heroku-buildpack-ruby.git#v200
65-
66-
rm -rf .git # blow away any existent git directory from a previous run
67-
git init .
68-
git add .
69-
git commit -m "Packaging for Heroku upgrade"
70-
git push --force --set-upstream https://git.heroku.com/${API_HOST}.git master
64+
BUILDPACK='https://github.com/heroku/heroku-buildpack-ruby.git#v200'
65+
if [[ ! $(heroku buildpacks -a ${API_HOST}) =~ ${BUILDPACK} ]]; then
66+
heroku buildpacks:set -a ${API_HOST} ${BUILDPACK}
67+
fi
68+
rm -rf .git # blow away any existent git directory from a previous run
69+
git init .
70+
git add .
71+
git commit -m "Packaging for Heroku upgrade"
72+
git push --force --set-upstream https://git.heroku.com/${API_HOST}.git master
7173
popd
7274

7375
###########################
7476
# Upgrade the web frontend
7577
###########################
7678

77-
cp "$CONFIG_DIR"/config.js "$ASSETS_DIR"/web/public_html
7879
pushd "$ASSETS_DIR"/web
79-
sed -i '' "s/{{api-app-name}}/${API_HOST}/" public_html/config.js
80+
sed \
81+
-e "s/{{api-app-name}}/${API_HOST}/" \
82+
<"$CONFIG_DIR"/config.js \
83+
>"$ASSETS_DIR"/web/public_html/config.js
8084

81-
rm -rf .git # blow away any existent git directory from a previous run
82-
git init .
83-
git add .
84-
git commit -m "Packaging for Heroku upgrade"
85-
git push --force --set-upstream https://git.heroku.com/${WEB_HOST}.git master
85+
rm -rf .git # blow away any existent git directory from a previous run
86+
git init .
87+
git add .
88+
git commit -m "Packaging for Heroku upgrade"
89+
git push --force --set-upstream https://git.heroku.com/${WEB_HOST}.git master
8690
popd

0 commit comments

Comments
 (0)