Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stevenharman/98576bf49b050b9e59fb26626b7cceff to your computer and use it in GitHub Desktop.
Save stevenharman/98576bf49b050b9e59fb26626b7cceff to your computer and use it in GitHub Desktop.

Revisions

  1. stevenharman revised this gist May 30, 2020. 2 changed files with 4 additions and 8 deletions.
    5 changes: 4 additions & 1 deletion bin-heroku_release.sh
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,10 @@
    #
    # Usage: bin/heroku_deploy

    . ./shell_colors
    RED='\033[0;31m'
    GREEN='\033[0;32m'
    YELLOW='\033[0;33m'
    NO_COLOR='\033[0m'

    set -euo pipefail

    7 changes: 0 additions & 7 deletions bin-shell_colors.sh
    Original file line number Diff line number Diff line change
    @@ -1,7 +0,0 @@
    #!/usr/bin/env bash

    RED='\033[0;31m'
    GREEN='\033[0;32m'
    YELLOW='\033[0;33m'
    NO_COLOR='\033[0m'
    CLEAR_LINE='\r\033[K'
  2. stevenharman revised this gist Jun 27, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions app.json
    Original file line number Diff line number Diff line change
    @@ -6,8 +6,8 @@
    },
    "stack": "heroku-16",
    "formation": [
    { "process": "web", "quantity": 1},
    { "process": "worker", "quantity": 1}
    { "process": "web", "quantity": 1 },
    { "process": "worker", "quantity": 1 }
    ],
    "addons": [
    "heroku-postgresql:hobby-dev"
  3. stevenharman renamed this gist Nov 16, 2017. 1 changed file with 0 additions and 0 deletions.
  4. stevenharman revised this gist Nov 16, 2017. No changes.
  5. stevenharman revised this gist Nov 15, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions bin-heroku_release.sh
    Original file line number Diff line number Diff line change
    @@ -14,10 +14,10 @@ if [ -z "$schema_version" ]; then
    fi

    if [ "$schema_version" -eq "0" ]; then
    printf "\n⚠️${YELLOW} [Release Phase]: Loading the database schema.${NO_COLOR}\n"
    printf "\n${YELLOW} [Release Phase]: Loading the database schema.${NO_COLOR}\n"
    bin/rails db:schema:load
    else
    printf "\n⚠️${YELLOW} [Release Phase]: Running database migrations.${NO_COLOR}\n"
    printf "\n${YELLOW} [Release Phase]: Running database migrations.${NO_COLOR}\n"
    bin/rails db:migrate
    fi

  6. stevenharman revised this gist Nov 15, 2017. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions bin-heroku_release.sh
    Original file line number Diff line number Diff line change
    @@ -9,16 +9,16 @@ set -euo pipefail
    schema_version=$(bin/rails db:version | { grep "^Current version: [0-9]\\+$" || true; } | tr -s ' ' | cut -d ' ' -f3)

    if [ -z "$schema_version" ]; then
    printf "💀${RED} Database schema version could not be determined. Does the database exist?${NO_COLOR}\n"
    printf "💀${RED} [Release Phase]: Database schema version could not be determined. Does the database exist?${NO_COLOR}\n"
    exit 1
    fi

    if [ "$schema_version" -eq "0" ]; then
    printf "\n⚠️${YELLOW} Loading the database schema.${NO_COLOR}\n"
    printf "\n⚠️${YELLOW} [Release Phase]: Loading the database schema.${NO_COLOR}\n"
    bin/rails db:schema:load
    else
    printf "\n⚠️${YELLOW} Running database migrations.${NO_COLOR}\n"
    printf "\n⚠️${YELLOW} [Release Phase]: Running database migrations.${NO_COLOR}\n"
    bin/rails db:migrate
    fi

    printf "\n🎉${GREEN} Release Phase: database is up to date.${NO_COLOR}\n"
    printf "\n🎉${GREEN} [Release Phase]: Database is up to date.${NO_COLOR}\n"
  7. stevenharman created this gist Nov 15, 2017.
    13 changes: 13 additions & 0 deletions 01_README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    # Heroku Release Phase + Review Apps + Rails

    This is a simplified, but fairly thorough, set of scripts and configuration to enable [Heroku Release Phase](https://devcenter.heroku.com/articles/release-phase) for Rails apps.
    Further, this particular set up plays nicely with [Heroku Review Apps](https://devcenter.heroku.com/articles/github-integration-review-apps) in that the `release` phase script will:

    1. Fail, loudly, if the DB does not yet exist.
    1. Load the DB schema if the current schema version (as determined by `bin/rails db:version`) is `0`.
    1. Run DB migrations otherwise.

    For a "normal" app that usually means it will run the DB migrations.
    For a Review App, on the first deploy the `release` phase will `bin/rails db:schema:load`.
    And then the `postdeploy` script will seed data.
    During subsequent deploys to the Review App, the `release` phase will `bin/rails db:migrate`.
    5 changes: 5 additions & 0 deletions Procfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    web: bundle exec puma -C ./config/puma.rb
    worker: DB_POOL_SIZE=${WORKER_CONCURRENCY:-20} bundle exec sidekiq -c ${WORKER_CONCURRENCY:-20} -t ${WORKER_TIMEOUT:-25} -q default,1 -q mailers,1

    # === Heroku Release Phase, ignored by `heroku local`. See: https://devcenter.heroku.com/articles/release-phase
    release: bin/heroku_release
    30 changes: 30 additions & 0 deletions app.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    {
    "name": "your-app-name",
    "description": "Configuration for per-Pull-Request Reviews Apps on Heroku.",
    "scripts": {
    "postdeploy": "LOG_LEVEL=INFO bin/rake review_app:seed"
    },
    "stack": "heroku-16",
    "formation": [
    { "process": "web", "quantity": 1},
    { "process": "worker", "quantity": 1}
    ],
    "addons": [
    "heroku-postgresql:hobby-dev"
    ],
    "buildpacks": [
    {
    "url": "heroku/ruby"
    }
    ],
    "env": {
    "Lots of other Env Vars...": "as you need",

    "HEROKU_APP_NAME": {
    "required": true
    },
    "HEROKU_PARENT_APP_NAME": {
    "required": true
    }
    }
    }
    24 changes: 24 additions & 0 deletions bin-heroku_release.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #!/usr/bin/env bash
    #
    # Usage: bin/heroku_deploy

    . ./shell_colors

    set -euo pipefail

    schema_version=$(bin/rails db:version | { grep "^Current version: [0-9]\\+$" || true; } | tr -s ' ' | cut -d ' ' -f3)

    if [ -z "$schema_version" ]; then
    printf "💀${RED} Database schema version could not be determined. Does the database exist?${NO_COLOR}\n"
    exit 1
    fi

    if [ "$schema_version" -eq "0" ]; then
    printf "\n⚠️${YELLOW} Loading the database schema.${NO_COLOR}\n"
    bin/rails db:schema:load
    else
    printf "\n⚠️${YELLOW} Running database migrations.${NO_COLOR}\n"
    bin/rails db:migrate
    fi

    printf "\n🎉${GREEN} Release Phase: database is up to date.${NO_COLOR}\n"
    7 changes: 7 additions & 0 deletions bin-shell_colors.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    #!/usr/bin/env bash

    RED='\033[0;31m'
    GREEN='\033[0;32m'
    YELLOW='\033[0;33m'
    NO_COLOR='\033[0m'
    CLEAR_LINE='\r\033[K'
    23 changes: 23 additions & 0 deletions review_app.rake
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    # frozen_string_literal: true

    namespace :review_app do
    desc 'Ensure environment is one we shish to spread seed in'
    task :ensure_review_app do
    abort 'This is not a Heroku Review App' unless review_app?
    end

    desc 'Seeds a review app with a subset of realistic-looking data'
    task :seed, [] => %w[
    ensure_review_app
    environment
    db:seed
    seed:administrator
    seed:widgets
    ] do
    Rails.logger.tagged('Seed App') { |l| l.info("Finished seeding new Review App: #{ENV['HEROKU_APP_NAME']}") }
    end

    def review_app?
    !!ENV['HEROKU_PARENT_APP_NAME']
    end
    end