Last active
March 30, 2023 09:58
-
-
Save mlocher/3e831316f022f21a1b27 to your computer and use it in GitHub Desktop.
Heroku deployment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This codeship custom script depends on: | |
# - API_KEY env var from Heroku | |
# - STAGING_APP_NAME | |
# - STAGING_APP_URL | |
set -e | |
export HEROKU_API_KEY="${API_KEY}" | |
# Turn on Heroku maintenance mode | |
heroku maintenance:on --app ${STAGING_APP_NAME} | |
# Push | |
git remote add heroku "[email protected]:${STAGING_APP_NAME}.git" | |
git push heroku -f "${COMMIT_ID}:refs/heads/master" | |
# if migrations are enabled | |
heroku_run rake db:migrate "${STAGING_APP_NAME}" | |
# heroku_run restart "${STAGING_APP_NAME}" | |
# Turn off Heroku maintenance mode | |
heroku maintenance:off --app ${STAGING_APP_NAME} | |
# check if the app is up and running | |
check_url "${STAGING_APP_URL}" |
Thanks for answering @mlocher!
I still "need" maintenance mode, so I'll have to keep using the script.
To "update" the script, simply replace all occurrences of heroku_run ${COMMAND} ${APPLICATION_NAME}
with the following command.
heroku run --exit-code --app ${APPLICATION_NAME} -- ${COMMAND}
So heroku_run rake db:migrate "testapp"
would get translated to heroku run --exit-code --app testapp -- rake db:migrate
Changes to the Heroku CLI made it possible to return the exit code directly and made the wrapper obsolete. (The wrapper is still available and basically translates the commands you pass to it into the above template. See the documentation article you linked to for all the details.)
Thank you very much @mlocher! I'll update the script.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script doesn't reflect the integrated Heroku deployment on Codeship (as we do not support maintenance mode in the integrated deployment). It is based on the integrated deployment though and matches it closely.
For an up to date version, please use the integrated Heroku deployment, which is maintained by the Codeship team. This script is unsupported and won't be updated with changes made to the integrated deployment. It was (is) provided as a starting point, but was never expected to be maintained by us (that's why it was released to my private account and not an official Codeship account).