Class: Hercules::Deployer
- Inherits:
-
Object
- Object
- Hercules::Deployer
- Defined in:
- lib/deployer.rb
Overview
The Deployer is responsible for clonning the repository, copying the code, and calling the deploy triggers.
Instance Method Summary collapse
-
#deploy ⇒ Object
This method will do the deploy: git clone, run bundle install and call the triggers callbacks.
-
#initialize(logger, config, branch) ⇒ Deployer
constructor
-
logger is the object of Logger class that will log the deploy actions.
-
Constructor Details
#initialize(logger, config, branch) ⇒ Deployer
-
logger is the object of Logger class that will log the deploy actions.
-
config is the hash configuration of the project we want to deploy.
Will be a subtree of the configuration YAML
-
branch is the name of the branch we are deploying.
15 16 17 18 19 20 21 |
# File 'lib/deployer.rb', line 15 def initialize(logger, config, branch) @log = logger @config = config @branch = branch @cmd = CommandRunner.new(@log) @trigger_class = nil end |
Instance Method Details
#deploy ⇒ Object
This method will do the deploy: git clone, run bundle install and call the triggers callbacks.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/deployer.rb', line 25 def deploy git = GitHandler.new @config git.deploy_branch(@branch) do |dir, branch| Bundler.with_clean_env do @cmd.cd(dir) bundle_path = "#{dir}/../../../bundles/#{@branch}" FileUtils.mkdir_p(bundle_path) FileUtils.mkdir_p("#{dir}/vendor") FileUtils.ln_s(bundle_path, "#{dir}/vendor/bundle", :force => true) @cmd.run!("bundle install --deployment") @trigger_class = look_for_triggers(dir) @log.debug "Do we have a before trigger? #{has_before_trigger?} Trigger Class: #{@trigger_class.inspect}" before_trigger(dir) if has_before_trigger? end end @log.warn "Branch #{@branch} deployed" dir = "#{git.branches_path}/#{@branch}" Bundler.with_clean_env do @log.debug "Do we have an after trigger? #{has_after_trigger?} Trigger Class: #{@trigger_class.inspect}" after_trigger(dir) if has_after_trigger? end ensure # Now we must store the deploy output output_dir = "#{@config['target_directory']}/logs/#{@branch}/" FileUtils.mkdir_p output_dir @cmd.store_output "#{output_dir}/#{git.last_commit}.log" end |