Class: Suspenders::Adapters::Heroku

Inherits:
Object
  • Object
show all
Defined in:
lib/suspenders/adapters/heroku.rb

Instance Method Summary collapse

Constructor Details

#initialize(app_builder) ⇒ Heroku

Returns a new instance of Heroku.


4
5
6
# File 'lib/suspenders/adapters/heroku.rb', line 4

def initialize(app_builder)
  @app_builder = app_builder
end

Instance Method Details

#create_heroku_pipelineObject


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/suspenders/adapters/heroku.rb', line 58

def create_heroku_pipeline
  pipelines_plugin = `heroku help | grep pipelines`
  if pipelines_plugin.empty?
    puts "You need heroku pipelines plugin. Run: brew upgrade heroku-toolbelt"
    exit 1
  end

  run_toolbelt_command(
    "pipelines:create #{heroku_app_name} \
      -a #{heroku_app_name}-staging --stage staging",
    "staging"
  )

  run_toolbelt_command(
    "pipelines:add #{heroku_app_name} \
      -a #{heroku_app_name}-production --stage production",
    "production"
  )
end

#create_production_heroku_app(flags) ⇒ Object


25
26
27
28
29
# File 'lib/suspenders/adapters/heroku.rb', line 25

def create_production_heroku_app(flags)
  app_name = heroku_app_name_for("production")

  run_toolbelt_command "create #{app_name} #{flags}", "production"
end

#create_staging_heroku_app(flags) ⇒ Object


19
20
21
22
23
# File 'lib/suspenders/adapters/heroku.rb', line 19

def create_staging_heroku_app(flags)
  app_name = heroku_app_name_for("staging")

  run_toolbelt_command "create #{app_name} #{flags}", "staging"
end

#set_heroku_application_hostObject


78
79
80
81
82
83
84
85
# File 'lib/suspenders/adapters/heroku.rb', line 78

def set_heroku_application_host
  %w[staging production].each do |environment|
    run_toolbelt_command(
      "config:add APPLICATION_HOST=#{heroku_app_name}-#{environment}.herokuapp.com",
      environment
    )
  end
end

#set_heroku_backup_scheduleObject


49
50
51
52
53
54
55
56
# File 'lib/suspenders/adapters/heroku.rb', line 49

def set_heroku_backup_schedule
  %w[staging production].each do |environment|
    run_toolbelt_command(
      "pg:backups:schedule DATABASE_URL --at '10:00 UTC'",
      environment
    )
  end
end

#set_heroku_buildpacksObject


87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/suspenders/adapters/heroku.rb', line 87

def set_heroku_buildpacks
  %w[staging production].each do |environment|
    run_toolbelt_command(
      "buildpacks:add --index 1 heroku/nodejs",
      environment
    )
    run_toolbelt_command(
      "buildpacks:add --index 2 heroku/ruby",
      environment
    )
  end
end

#set_heroku_honeybadger_envObject


40
41
42
43
44
45
46
47
# File 'lib/suspenders/adapters/heroku.rb', line 40

def set_heroku_honeybadger_env
  %w[staging production].each do |environment|
    run_toolbelt_command(
      "config:add HONEYBADGER_ENV=#{environment}",
      environment
    )
  end
end

#set_heroku_rails_secretsObject


31
32
33
34
35
36
37
38
# File 'lib/suspenders/adapters/heroku.rb', line 31

def set_heroku_rails_secrets
  %w[staging production].each do |environment|
    run_toolbelt_command(
      "config:add SECRET_KEY_BASE=#{generate_secret}",
      environment
    )
  end
end

#set_heroku_remotesObject


8
9
10
11
12
13
14
15
16
17
# File 'lib/suspenders/adapters/heroku.rb', line 8

def set_heroku_remotes
  remotes = <<~SHELL
    #{command_to_join_heroku_app("staging")}
    #{command_to_join_heroku_app("production")}

    git config heroku.remote staging
  SHELL

  app_builder.append_file "bin/setup", remotes
end