Class: HerokuRailsDeploy::Deployer

Inherits:
Object
  • Object
show all
Extended by:
PrivateAttr
Defined in:
lib/heroku_rails_deploy/deployer.rb

Defined Under Namespace

Classes: Options

Constant Summary collapse

PRODUCTION_BRANCH_REGEX =
/\A((master)|(release\/.+)|(hotfix\/.+))\z/
PRODUCTION =
'production'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_file, args) ⇒ Deployer

Returns a new instance of Deployer.



25
26
27
28
29
30
31
# File 'lib/heroku_rails_deploy/deployer.rb', line 25

def initialize(config_file, args)
  raise "Missing config file #{config_file}" unless File.file?(config_file)
  @app_registry = YAML.load(File.read(config_file))
  @config_file = config_file
  @args = args
  @options = parse_options
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



16
17
18
# File 'lib/heroku_rails_deploy/deployer.rb', line 16

def args
  @args
end

#config_fileObject (readonly)

Returns the value of attribute config_file.



16
17
18
# File 'lib/heroku_rails_deploy/deployer.rb', line 16

def config_file
  @config_file
end

Instance Method Details

#production?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/heroku_rails_deploy/deployer.rb', line 72

def production?
  options.try(:environment) == PRODUCTION
end

#runObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/heroku_rails_deploy/deployer.rb', line 33

def run
  return unless options

  app_name = app_registry.fetch(options.environment) do
    raise OptionParser::InvalidArgument.new("Invalid environment '#{options.environment}'. " \
      "Must be in #{app_registry.keys.join(', ')}")
  end

  raise 'Only master, release or hotfix branches can be deployed to production' if production? && !production_branch?(options.revision)

  no_uncommitted_changes!

  puts "Deploying to Heroku app #{app_name} for environment #{options.environment}"

  if !options.skip_avro_schemas && (production? || options.register_avro_schemas)
    puts 'Checking for pending Avro schemas'
    pending_schemas = list_pending_schemas(app_name)
    if pending_schemas.any?
      puts 'Registering Avro schemas'
      register_avro_schemas!(registry_url(app_name), pending_schemas)
    else
      puts 'No pending Avro schemas'
    end
  end

  puts 'Pushing code'
  push_code(app_name, options.revision)

  puts 'Checking for pending migrations'
  if pending_migrations?(app_name)
    puts 'Running migrations'
    run_migrations(app_name)
    puts 'Restarting dynos'
    restart_dynos(app_name)
  else
    puts 'No migrations required'
  end
end