Install - HearstAT/ensemble GitHub Wiki

Ensemble Install

Base Install

  • Start by cloning this project
    • git clone https://github.com/HearstAT/ensemble.git
  • Install Isolated (Preferred for Normal Dev, Shared Systems, and when utilizing rake setup commands)
    • bundle install --binstubs --path vendor/bundle
  • Install to System
    • bundle install
    • Note: Only recommended when installing to a system where ensemble will be the other app running (e.g.; Docker, AWS EC2)
  • Install Options
    • Manually Install Ensemble: Manual Options
    • Rake Tasks (More Automated): Rake Options

Manual

  • Assumptions:
    • Commands are being run from the project directory unless otherwise stated

Manual - Docker

version: '2'

services:
  rails:
    restart: always
    build: 
      context: .
      dockerfile: Dockerfile
      args:
        BUILD_ENV: production
    ports:
      - "3000:3000"
    env_file:
      - '.env'
  • Example if pulling image
version: '2'

services:
  rails:
    restart: always
    image: hearstat/ensemble
    ports:
      - "3000:3000"
    env_file:
      - '.env'
  • Run the following commands
    • Bring Up Server
      • Non-Detached: docker-compose up --build
      • Detached (In Background): docker-compose up --build -d
      • Note: add -f $FILENAME.yml before up in the commands above to use a differently filename from docker-compose.yml
    • Run DB Commands
      • docker-compose exec rails bundle exec rake db:create
      • docker-compose exec rails bundle exec rake db:migrate

Manual - Docker Development

  • Create a Compose File in the root of the project directory
  • Filename: docker-compose.yml
version: '2'

services:
  rails:
    restart: always
    build: 
      context: .
      dockerfile: Dockerfile
      args:
        BUILD_ENV: production
    ports:
      - "3000:3000"
      - "1234:1234"
      - "26162:26162"
    env_file:
      - '.env'
  • Run the following commands
    • Bring Up Server
      • Non-Detached: docker-compose up --build
      • Detached (In Background): docker-compose up --build -d
      • Note: add -f $FILENAME.yml before up in the commands above to use a differently filename from docker-compose.yml
    • Run DB Commands
      • docker-compose exec rails bundle exec rake db:create
      • docker-compose exec rails bundle exec rake db:migrate
      • docker-compose exec rails bundle exec rake db:seed

Manual - Docker w/ Postgres Container

  • TODO
docker-compose -f dev-docker-compose.yml up --build
docker-compose exec website bundle exec rake db:create
docker-compose exec website bundle exec rake db:migrate
docker-compose exec website bundle exec bin/rake gather:pagerduty_incidents

Cleaning up:

docker-compose stop
docker-compose rm

Manual - Docker w/ Postgres Container Development

  • TODO
docker-compose -f dev-docker-compose.yml up --build
docker-compose exec website bundle exec rake db:create
docker-compose exec website bundle exec rake db:migrate
docker-compose exec website bundle exec bin/rake db:seed

Then navigate to http://localhost:3000 and login with the credentials from the db/seeds.rb file

Cleaning up:

docker-compose stop
docker-compose rm

Manual - Local

  • Database
    • Create
      • bundle exec rake db:create
      • bundle exec rake db:migrate
    • Seed:
      • Create a BU and a PD account in the UI or follow here
      • bundle exec bin gather:pagerduty_incidents
  • Start Ensemble
    • bundle exec rails s

Manual - Local Development

  • Database
    • Create
      • bundle exec rake db:create
      • bundle exec rake db:migrate
    • Seed:
      • Either follow This Steps
      • Or run this command: bundle exec rake db:seed
  • Start Ensemble
    • bundle exec rails s

However this falls out of date from time to time and will not have your email address/domain.

Manual - Database Configure

To create the first user you will need to use the rails console (like irb for rails) and create the first user. Note you will want to use an actual email address since it will send an email

Start console first via bundle exec rails c

Domain Creation
Domain.create!(domain: 'example.com')
User.create!(email: '[email protected]', password: 'password', password_confirmation: 'password', admin: true)
Account Creation
Domain.create!(domain: 'example.com')
newuser = User.new(email: '[email protected]', password: 'password', password_confirmation: 'password', admin: true)
newuser.confirm
newuser.save!
Pagerduty Setup

TODO - Need to proof out these commands

PD.create!

Rake

We have created rake tasks to automate the bulk of the setup

Rake - Default List

These are the defaults for the rake command arguments below. There are some difference between the Local and Docker setups, but they are almost identical.

  • ARG List:
    • Local: env vendor db_name db_user db_pass db_host db_pool db_port
      • Vendor default is true
    • Docker: env mount db_name db_user db_pass db_host db_port db_pool
      • Mount default is false
  • Defaults:
    • env: 'prod'
    • db_name: 'railstest'
    • db_user: 'railstest1'
    • db_pass: 'railstest'
    • db_host: local_ip
    • db_port: 5432
    • db_pool: 10
  • Calling rake task with all args looks like this
    • bundle exec rake setup:local['dev','true','railstest','railstest1','railstest','127.0.0.1','5432','10']

Rake - Docker

This command will automatically pull or build the Ensemble docker image to setup a full dockerized setup to run or test with

bundle exec rake install:docker

bundle exec rake install:docker['dev']

Rake - Docker w/ Postgres Container

This command will automatically pull or build the Ensemble and Postgres docker images to setup a full dockerized setup to run or test with

bundle exec rake install:docker_ps

bundle exec rake install:docker_ps['dev']

Rake - Local

Will install Ensemble locally and setup the database as needed

  • Quick Run - Defaults
    • bundle exec rake install:local
  • Development Quick Run
    • bundle exec rake install:local['dev]

Rake - Local w/ Postgres

Will install Ensemble locally and setup a sqlite database for testing

  • Quick Run - Defaults

bundle exec rake install:local_ps['dev']

Cloudformation

There is an example of a cloudformation template in this repo here

AWS CLI Launch

Here are a few options to launch the stack via CLI.

  • All Options
aws --region us-west-2 \
    cloudformation create-stack \
    --stack-name metrics-a \
    --disable-rollback \
    --template-body file://cloudformation/ensemble-single-instance.yml \
    --parameters \
        ParameterKey=HostedZone,ParameterValue=domain.com \
        ParameterKey=SSLCertificateARN,ParameterValue=dfaf3c \
        ParameterKey=MetricsSubdomain,ParameterValue=metrics-a \
        ParameterKey=InstanceType,ParameterValue=t2.micro \
        ParameterKey=KeyName,ParameterValue=arg3da \
        ParameterKey=SSHSecurityGroup,ParameterValue=arg3da \
        ParameterKey=CIDRA,ParameterValue=192.168.0.10 \
        ParameterKey=CIDRB,ParameterValue=192.168.0.11 \
        ParameterKey=DBSnapShot,ParameterValue=arg3da \ # Only use if restoring or building from DB snapshot
        ParameterKey=DBUser,ParameterValue=arg3da \
        ParameterKey=DBPassword,ParameterValue=arg3da \
        ParameterKey=DBInstanceType,ParameterValue=db.t2.micro \
        ParameterKey=DBPublic,ParameterValue=false \
        ParameterKey=DBName,ParameterValue=railstest \ # Use only for Existing DB or Snapshot so correct name goes to config
        ParameterKey=DBURL,ParameterValue=https://railsdb.domain.com # Only if existing DB is being used
  • Limited w/ Defaults
aws --region us-west-2 \
    cloudformation create-stack \
    --stack-name metrics-a \
    --disable-rollback \
    --template-body file://cloudformation/ensemble-single-instance.yml \
    --parameters \
        ParameterKey=HostedZone,ParameterValue=domain.com \
        ParameterKey=SSLCertificateARN,ParameterValue=arn:aws:acm: \
        ParameterKey=MetricsSubdomain,ParameterValue=metrics-a \
        ParameterKey=KeyName,ParameterValue=ssh_key_set_name \
        ParameterKey=SSHSecurityGroup,ParameterValue=ssh_allow_group \
        ParameterKey=CIDRA,ParameterValue=192.168.0.10 \
        ParameterKey=CIDRB,ParameterValue=192.168.0.11 \
        ParameterKey=DBUser,ParameterValue=railstest1 \
        ParameterKey=DBPassword,ParameterValue=railstest
⚠️ **GitHub.com Fallback** ⚠️