#!/bin/sh # This codeship custom script depends on: # - API_KEY env var from Heroku # It uses the CI_COMMITTER_NAME value to determine which Heroku # app to deploy to. Each developer has their own environment. set -e export HEROKU_API_KEY="${API_KEY}" # default feature branch app STAGING_APP_NAME="flinstone-environment" # update STAGING_APP_NAME based on the name of the committer if [ "${CI_COMMITTER_NAME}" = "Fred" ]; then STAGING_APP_NAME="freds-environment"; elif [ "${CI_COMMITTER_NAME}" = "Barney" ]; then STAGING_APP_NAME="barneys-environment"; fi STAGING_APP_URL="${STAGING_APP_NAME}.herokuapp.com" echo "${CI_COMMITTER_EMAIL},${CI_COMMITTER_NAME},${CI_COMMITTER_USERNAME},${STAGING_APP_URL}" # Turn on Heroku maintenance mode heroku maintenance:on --app ${STAGING_APP_NAME} # Push to remote - force a push in all cases on feature branches git remote add heroku git@heroku.com:${STAGING_APP_NAME}.git git push heroku -f ${COMMIT_ID}:refs/heads/master # run migrations and update static content heroku_run "python manage.py collectstatic --noinput" ${STAGING_APP_NAME} heroku_run "python manage.py migrate --noinput" ${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}"