Class: Deployer
- Inherits:
-
Object
- Object
- Deployer
- Defined in:
- app/deployer.rb
Instance Attribute Summary collapse
-
#push ⇒ Object
Returns the value of attribute push.
Class Method Summary collapse
Instance Method Summary collapse
- #deploy ⇒ Object
- #deployment_file ⇒ Object
- #deployment_path ⇒ Object
-
#git_url ⇒ Object
Hack to avoid problems with github responses using git gem over https.
-
#initialize(push) ⇒ Deployer
constructor
A new instance of Deployer.
- #repository_name ⇒ Object
- #root ⇒ Object
- #undeploy ⇒ Object
- #write_descriptor ⇒ Object
Constructor Details
#initialize(push) ⇒ Deployer
Returns a new instance of Deployer.
30 31 32 |
# File 'app/deployer.rb', line 30 def initialize(push) @push = push end |
Instance Attribute Details
#push ⇒ Object
Returns the value of attribute push.
28 29 30 |
# File 'app/deployer.rb', line 28 def push @push end |
Class Method Details
.deploy(push) ⇒ Object
34 35 36 37 |
# File 'app/deployer.rb', line 34 def self.deploy(push) push.deploy DeployerTask.async(:deploy, :id=>push.id) end |
.undeploy(push, async = true) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'app/deployer.rb', line 39 def self.undeploy(push, async = true) puts "Undeploying #{push.repo_name}/#{push.branch}" push.undeploy if async DeployerTask.async(:undeploy, :id=>push.id) else Deployer.new(push).undeploy end end |
.undeploy_branch(branch) ⇒ Object
49 50 51 52 53 |
# File 'app/deployer.rb', line 49 def self.undeploy_branch(branch) Deployment.all(:branch=>branch).each do |d| Deployer.undeploy(d.push, false) end end |
Instance Method Details
#deploy ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/deployer.rb', line 61 def deploy begin clone_repo freeze_gems write_descriptor push.deployed push.save d = Deployment.create( :created_at=>Time.now, :push=>push, :branch=>push.branch, :path=>deployment_path, :context=>"/#{repository_name}") d.save! rescue Exception => ex puts ex push.failed end end |
#deployment_file ⇒ Object
94 95 96 |
# File 'app/deployer.rb', line 94 def deployment_file "#{repository_name}-knob.yml" end |
#deployment_path ⇒ Object
86 87 88 |
# File 'app/deployer.rb', line 86 def deployment_path @deployment_path ||= ENV['DEPLOYMENTS'] end |
#git_url ⇒ Object
Hack to avoid problems with github responses using git gem over https
82 83 84 |
# File 'app/deployer.rb', line 82 def git_url push.repo_url.sub('https://github.com/', 'git://github.com/') end |
#repository_name ⇒ Object
90 91 92 |
# File 'app/deployer.rb', line 90 def repository_name @repo_name ||= push.master? ? push.repo_name : "#{push.repo_name}-#{push.branch}" end |
#root ⇒ Object
98 99 100 |
# File 'app/deployer.rb', line 98 def root "#{deployment_path}/#{repository_name}" end |
#undeploy ⇒ Object
55 56 57 58 59 |
# File 'app/deployer.rb', line 55 def undeploy TorqueBox::DeployUtils.undeploy( deployment_file ) remove_repo if ( File.exist?( root ) ) push.undeployed end |
#write_descriptor ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'app/deployer.rb', line 102 def write_descriptor repo = push.find_repository if repo config = repo.config.nil? ? {} : YAML.load(repo.config) config['application'] ||= {} config['application']['root'] = root config['application']['env'] ||= 'production' descriptor = TorqueBox::DeployUtils.basic_deployment_descriptor(config) descriptor.merge! config TorqueBox::DeployUtils.deploy_yaml( descriptor, deployment_file ) else puts "Unable to find repository #{push.repo_name}/#{push.branch}" end end |