Class: Kumade::Deployer

Inherits:
Object
  • Object
show all
Defined in:
lib/kumade/deployer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDeployer

Returns a new instance of Deployer.



8
9
10
11
12
13
# File 'lib/kumade/deployer.rb', line 8

def initialize
  @git      = Git.new
  @heroku   = Heroku.new
  @branch   = @git.current_branch
  @packager = Packager.new(@git)
end

Instance Attribute Details

#gitObject (readonly)

Returns the value of attribute git.



6
7
8
# File 'lib/kumade/deployer.rb', line 6

def git
  @git
end

#herokuObject (readonly)

Returns the value of attribute heroku.



6
7
8
# File 'lib/kumade/deployer.rb', line 6

def heroku
  @heroku
end

#packagerObject (readonly)

Returns the value of attribute packager.



6
7
8
# File 'lib/kumade/deployer.rb', line 6

def packager
  @packager
end

Instance Method Details

#deployObject



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/kumade/deployer.rb', line 15

def deploy
  begin
    ensure_heroku_remote_exists
    pre_deploy
    heroku.sync
    heroku.migrate_database
    heroku.restart_app
  rescue => deploying_error
    Kumade.configuration.outputter.error("#{deploying_error.class}: #{deploying_error.message}")
  ensure
    post_deploy
  end
end

#ensure_clean_gitObject



48
49
50
# File 'lib/kumade/deployer.rb', line 48

def ensure_clean_git
  git.ensure_clean_git
end

#ensure_heroku_remote_existsObject



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/kumade/deployer.rb', line 52

def ensure_heroku_remote_exists
  if git.remote_exists?(Kumade.configuration.environment)
    if git.heroku_remote?
      Kumade.configuration.outputter.success("#{Kumade.configuration.environment} is a Heroku remote")
    else
      Kumade.configuration.outputter.error(%{Cannot deploy: "#{Kumade.configuration.environment}" remote does not point to Heroku})
    end
  else
    Kumade.configuration.outputter.error(%{Cannot deploy: "#{Kumade.configuration.environment}" remote does not exist})
  end
end

#package_assetsObject



36
37
38
# File 'lib/kumade/deployer.rb', line 36

def package_assets
  @packager.run
end

#post_deployObject



44
45
46
# File 'lib/kumade/deployer.rb', line 44

def post_deploy
  heroku.delete_deploy_branch
end

#pre_deployObject



29
30
31
32
33
34
# File 'lib/kumade/deployer.rb', line 29

def pre_deploy
  ensure_clean_git
  run_predeploy_task
  package_assets
  sync_origin
end

#sync_originObject



40
41
42
# File 'lib/kumade/deployer.rb', line 40

def sync_origin
  git.push(@branch)
end