Class: Kikubari::Deploy::Deployer
- Inherits:
-
Object
- Object
- Kikubari::Deploy::Deployer
- Defined in:
- lib/deployer/deployer.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
-
#after_deploy_run ⇒ Object
Run comand line script after deploy.
- #before_deploy_run ⇒ Object
- #capture_stderr(command) ⇒ Object
-
#create_current_symlink_folder ⇒ Object
Create the current symlink to the deploy version folder.
-
#create_deploy_structure ⇒ Object
Create deployment structure.
-
#create_release_folder ⇒ Object
Create the folder where you will deploy the actual version of the code based on the configuration.
-
#create_structure ⇒ Object
Create te the folder structure as is in the YAML.
-
#create_sylinked_folders ⇒ Object
Create the Symlinked folders.
-
#create_symlink(folder, target_folder) ⇒ Object
Execute creation of symlinked folder.
- #create_symlinked_files ⇒ Object
-
#deploy ⇒ Object
Execute the deploy.
- #execute_shell(command) ⇒ Object
- #has_after_deploy_run_commands ⇒ Object
- #has_before_deploy_run_commands ⇒ Object
-
#initialize(config) ⇒ Deployer
constructor
A new instance of Deployer.
-
#rotate_folders ⇒ Object
Rotate old version folders.
-
#test_files ⇒ Object
Test if selected file already exist.
Constructor Details
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
17 18 19 |
# File 'lib/deployer/deployer.rb', line 17 def config @config end |
Instance Method Details
#after_deploy_run ⇒ Object
Run comand line script after deploy
120 121 122 123 124 125 126 127 128 |
# File 'lib/deployer/deployer.rb', line 120 def after_deploy_run return unless has_after_deploy_run_commands out = Array.new @logger.head "Executing After Deploy" @config.after.run.each do |run_task| out.push(execute_shell(run_task) ) end out end |
#before_deploy_run ⇒ Object
134 135 136 137 138 139 140 141 142 |
# File 'lib/deployer/deployer.rb', line 134 def before_deploy_run return unless has_before_deploy_run_commands out = Array.new @logger.head "Executing Before Deploy" @config.before.run.each do |run_task| out.push(execute_shell(run_task) ) end out end |
#capture_stderr(command) ⇒ Object
153 154 155 156 |
# File 'lib/deployer/deployer.rb', line 153 def capture_stderr ( command ) stdin, stdout, stderr = Open3.popen3( command ) ({ :stdout => stdout.readlines.join(""), :stderr => stderr.readlines.join("") }) end |
#create_current_symlink_folder ⇒ Object
Create the current symlink to the deploy version folder
48 49 50 51 52 |
# File 'lib/deployer/deployer.rb', line 48 def create_current_symlink_folder FileUtils.rm_f(@config.current_deploy_folder) if File.symlink?(@config.current_deploy_folder) FileUtils.ln_s @config.env_time_folder, @config.current_deploy_folder self end |
#create_deploy_structure ⇒ Object
Create deployment structure
100 101 102 103 |
# File 'lib/deployer/deployer.rb', line 100 def create_deploy_structure create_structure if @config.do.folder_structure self end |
#create_release_folder ⇒ Object
Create the folder where you will deploy the actual version of the code based on the configuration
40 41 42 43 |
# File 'lib/deployer/deployer.rb', line 40 def create_release_folder FileUtils.mkdir_p(@config.env_time_folder) unless File.directory? @config.env_time_folder self end |
#create_structure ⇒ Object
Create te the folder structure as is in the YAML
27 28 29 30 31 32 33 34 35 |
# File 'lib/deployer/deployer.rb', line 27 def create_structure @config.do.folder_structure.each_pair do |folder, target_folder| unless !target_folder.empty? && File.directory?(@config.deploy_folder.join(folder.to_s)) @logger.print "Creating Structure folder: #{folder}" FileUtils.mkdir_p @config.deploy_folder.join(folder.to_s) end end self end |
#create_sylinked_folders ⇒ Object
Create the Symlinked folders
70 71 72 73 74 75 76 77 78 |
# File 'lib/deployer/deployer.rb', line 70 def create_sylinked_folders @config.do.folder_structure.each_pair do |folder, target_folder| next if target_folder.empty? @logger.print "- linking: #{@config.env_time_folder}/#{target_folder}" raise "Folder: #{@config.env_time_folder.join(target_folder.to_s)} already exists and the symlink can't be created" if File.directory?(@config.env_time_folder.join(target_folder.to_s)) create_symlink( @config.deploy_folder.join(folder.to_s), @config.env_time_folder.join(target_folder.to_s) ) end self end |
#create_symlink(folder, target_folder) ⇒ Object
Execute creation of symlinked folder
83 84 85 86 |
# File 'lib/deployer/deployer.rb', line 83 def create_symlink( folder, target_folder ) raise ArgumentError , "Origin folder #{folder} is not a valid folder" unless File.directory?(folder) FileUtils.ln_s folder, target_folder end |
#create_symlinked_files ⇒ Object
89 90 91 92 93 94 |
# File 'lib/deployer/deployer.rb', line 89 def create_symlinked_files @config.do.link_files.each_pair do |source, target| @logger.print "- linking: #{@config.env_time_folder.join(target.to_s)}" FileUtils.ln_s(@config.deploy_folder.join(source.to_s), @config.env_time_folder.join(target.to_s)) end end |
#deploy ⇒ Object
Execute the deploy
161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/deployer/deployer.rb', line 161 def deploy before_deploy_run @logger.head "Executing Deploy" test_files if @config.do.test_files do_deploy create_sylinked_folders create_symlinked_files if @config.do.link_files create_current_symlink_folder rotate_folders after_deploy_run self end |
#execute_shell(command) ⇒ Object
144 145 146 147 148 149 150 |
# File 'lib/deployer/deployer.rb', line 144 def execute_shell(command) @logger.run(command, @config.env_time_folder) temp = capture_stderr "cd #{@config.env_time_folder.to_s.strip} && #{command} " @logger.result(temp[:stdout]) if temp[:stdout] != "" @logger.error(temp[:stderr]) if temp[:stderr] != "" temp end |
#has_after_deploy_run_commands ⇒ Object
113 114 115 |
# File 'lib/deployer/deployer.rb', line 113 def has_after_deploy_run_commands @config.after && @config.after.run && !@config.after.run.empty? end |
#has_before_deploy_run_commands ⇒ Object
130 131 132 |
# File 'lib/deployer/deployer.rb', line 130 def has_before_deploy_run_commands @config.before && @config.before.run && !@config.before.run.empty? end |
#rotate_folders ⇒ Object
Rotate old version folders
108 109 110 |
# File 'lib/deployer/deployer.rb', line 108 def rotate_folders DeployDir.rotate_folders( @config.environment_folder , @config.config.history_limit ) end |
#test_files ⇒ Object
Test if selected file already exist
58 59 60 61 62 63 64 65 |
# File 'lib/deployer/deployer.rb', line 58 def test_files @config.do.link_files.each_pair do |source, target| unless File.exist? @config.deploy_folder.join(source.to_s) raise ArgumentError, "Please verify this file exist: #{@config.deploy_folder.join(source.to_s)}" end end self end |