class Reina::App
Constants
- DEFAULT_APP_NAME_PREFIX
- DEFAULT_REGION
- DEFAULT_STAGE
Attributes
branch[R]
g[R]
heroku[R]
issue_number[R]
name[R]
project[R]
Public Class Methods
new(heroku, name, project, issue_number, branch)
click to toggle source
# File lib/reina/app.rb, line 9 def initialize(heroku, name, project, issue_number, branch) @heroku = heroku @name = name.to_s @project = project @issue_number = issue_number @branch = branch end
Public Instance Methods
add_buildpacks()
click to toggle source
# File lib/reina/app.rb, line 52 def add_buildpacks buildpacks = project.fetch(:buildpacks, []).map do |buildpack| { 'buildpack' => buildpack } end + app_json.fetch('buildpacks', []).map do |buildpack| { 'buildpack' => buildpack['url'] } end heroku.buildpack_installation.update(app_name, 'updates' => buildpacks.uniq) end
add_to_pipeline()
click to toggle source
# File lib/reina/app.rb, line 117 def add_to_pipeline return if project[:pipeline].blank? pipeline_id = heroku.pipeline.info(project[:pipeline])['id'] heroku.pipeline_coupling.create( 'app' => app_name, 'pipeline' => pipeline_id, 'stage' => DEFAULT_STAGE ) end
app_json()
click to toggle source
# File lib/reina/app.rb, line 141 def app_json return @app_json if @app_json f = File.join(name, 'app.json') return {} unless File.exists?(f) @app_json = JSON.parse(File.read(f)) end
app_name()
click to toggle source
# File lib/reina/app.rb, line 154 def app_name app_name_for(name) end
create_app()
click to toggle source
# File lib/reina/app.rb, line 32 def create_app heroku.app.create( 'name' => app_name, 'region' => project.fetch(:region, DEFAULT_REGION) ) end
deploy()
click to toggle source
# File lib/reina/app.rb, line 137 def deploy g.push(remote_name, 'master') end
domain_name()
click to toggle source
# File lib/reina/app.rb, line 150 def domain_name domain_name_for(app_name) end
execute_postdeploy_scripts()
click to toggle source
# File lib/reina/app.rb, line 128 def execute_postdeploy_scripts script = app_json.dig('scripts', 'postdeploy') return if script.blank? return if heroku? && ENV['HEROKU_API_KEY'].blank? `heroku run #{script} --app #{app_name}` end
fetch_repository()
click to toggle source
# File lib/reina/app.rb, line 17 def fetch_repository if Dir.exists?(name) @g = Git.open(name) else @g = Git.clone(github_url, name) end g.pull('origin', branch) g.checkout(g.branch(branch)) unless g.remotes.map(&:name).include?(remote_name) g.add_remote(remote_name, remote_url) end end
install_addons()
click to toggle source
# File lib/reina/app.rb, line 39 def install_addons addons = project.fetch(:addons, []) + app_json.fetch('addons', []) addons.each do |addon| if addon.is_a?(Hash) && addon.has_key?('options') addon['config'] = addon.extract!('options') else addon = { 'plan' => addon } end heroku.addon.create(app_name, addon) end end
parallel?()
click to toggle source
# File lib/reina/app.rb, line 162 def parallel? project[:parallel] != false end
remote_name()
click to toggle source
# File lib/reina/app.rb, line 158 def remote_name "heroku-#{app_name}" end
set_env_vars()
click to toggle source
# File lib/reina/app.rb, line 62 def set_env_vars config_vars = project.fetch(:config_vars, {}) except = config_vars[:except] if config_vars.has_key?(:from) copy = config_vars.fetch(:copy, []) config_vars = heroku.config_var.info_for_app(config_vars[:from]) vars_cache = {} copy.each do |h| unless h[:from].include?('#') s = config_vars[h[:from]] s << h[:append] if h[:append].present? config_vars[h[:to]] = s next end source, var = h[:from].split('#') source_app_name = app_name_for(source) if var == 'url'.freeze config_vars[h[:to]] = "https://#{domain_name_for(source_app_name)}" else vars_cache[source_app_name] ||= heroku.config_var.info_for_app(source_app_name) config_vars[h[:to]] = vars_cache[source_app_name][var] end end end config_vars.except!(*except) if except.present? config_vars['APP_NAME'] = app_name config_vars['HEROKU_APP_NAME'] = app_name config_vars['DOMAIN_NAME'] = domain_name config_vars['COOKIE_DOMAIN'] = '.herokuapp.com'.freeze app_json.fetch('env', {}).each do |key, hash| next if hash['value'].blank? || config_vars[key].present? config_vars[key] = hash['value'] end heroku.config_var.update(app_name, config_vars) end
setup_dynos()
click to toggle source
# File lib/reina/app.rb, line 106 def setup_dynos formation = app_json.fetch('formation', {}) return if formation.blank? formation.each do |k, h| h['size'] = 'free' heroku.formation.update(app_name, k, h) end end
Private Instance Methods
app_name_for(s)
click to toggle source
# File lib/reina/app.rb, line 172 def app_name_for(s) "#{DEFAULT_APP_NAME_PREFIX}#{s}-#{issue_number}" end
domain_name_for(s)
click to toggle source
# File lib/reina/app.rb, line 168 def domain_name_for(s) "#{s}.herokuapp.com" end
github_url()
click to toggle source
# File lib/reina/app.rb, line 176 def github_url return "https://github.com/#{project[:github]}" if ENV['GITHUB_AUTH'].blank? "https://#{ENV['GITHUB_AUTH']}@github.com/#{project[:github]}" end
heroku?()
click to toggle source
# File lib/reina/app.rb, line 186 def heroku? ENV['DYNO'].present? end
remote_url()
click to toggle source
# File lib/reina/app.rb, line 182 def remote_url "https://git.heroku.com/#{app_name}.git" end