Class: ModuleDeployer
- Inherits:
-
Object
- Object
- ModuleDeployer
- Defined in:
- lib/release_manager/module_deployer.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #check_requirements ⇒ Object
- #control_repo_remote ⇒ Object
-
#initialize(opts) ⇒ ModuleDeployer
constructor
A new instance of ModuleDeployer.
- #latest_version ⇒ Object
- #mod_path ⇒ Object
- #puppet_module ⇒ Object
- #puppetfile ⇒ Object
- #puppetfile_path ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(opts) ⇒ ModuleDeployer
Returns a new instance of ModuleDeployer.
7 8 9 10 |
# File 'lib/release_manager/module_deployer.rb', line 7 def initialize(opts) opts[:modulepath] = Dir.getwd if opts[:modulepath].nil? = opts end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/release_manager/module_deployer.rb', line 5 def end |
Instance Method Details
#check_requirements ⇒ Object
28 29 30 31 |
# File 'lib/release_manager/module_deployer.rb', line 28 def check_requirements raise PuppetfileNotFoundException unless File.exists?(puppetfile_path) raise ModNotFoundException if !mod_path || ! File.exists?(mod_path) end |
#control_repo_remote ⇒ Object
33 34 35 |
# File 'lib/release_manager/module_deployer.rb', line 33 def control_repo_remote @control_repo_remote ||= [:remote] || puppetfile.source end |
#latest_version ⇒ Object
24 25 26 |
# File 'lib/release_manager/module_deployer.rb', line 24 def latest_version puppet_module.latest_tag end |
#mod_path ⇒ Object
16 17 18 |
# File 'lib/release_manager/module_deployer.rb', line 16 def mod_path @mod_path ||= [:modulepath] || ENV['MOD_DIR'] || File.(Dir.getwd) end |
#puppet_module ⇒ Object
20 21 22 |
# File 'lib/release_manager/module_deployer.rb', line 20 def puppet_module @puppet_module ||= PuppetModule.new(mod_path) end |
#puppetfile ⇒ Object
37 38 39 |
# File 'lib/release_manager/module_deployer.rb', line 37 def puppetfile @puppetfile ||= Puppetfile.new(puppetfile_path) end |
#puppetfile_path ⇒ Object
12 13 14 |
# File 'lib/release_manager/module_deployer.rb', line 12 def puppetfile_path @puppetfile_path ||= [:puppetfile] || ENV['PUPPET_FILE_PATH'] || File.("~/repos/r10k-control/Puppetfile") end |
#run ⇒ Object
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 71 72 73 74 75 76 |
# File 'lib/release_manager/module_deployer.rb', line 41 def run begin check_requirements puts "Found module #{puppet_module.name} with version: #{latest_version}".green if [:dry_run] puts "Would have updated module #{puppet_module.name} in Puppetfile to version: #{latest_version}".green puts "Would have committed with message: bump #{puppet_module.name} to version: #{latest_version}".green if [:commit] puts "Would have just pushed branch: #{puppetfile.current_branch} to remote: #{control_repo_remote}".green if [:push] else puts "Updated module #{puppet_module.name} in Puppetfile to version: #{latest_version}".green puppetfile.write_version(puppet_module.name, latest_version) puppetfile.write_source(puppet_module.name, puppet_module.source) puppetfile.write_to_file if [:commit] puppetfile.commit("bump #{puppet_module.name} to version #{latest_version}") puts "Commited with message: bump #{puppet_module.name} to version #{latest_version}".green end if [:push] puppetfile.push(control_repo_remote, puppetfile.current_branch) puts "Just pushed branch: #{puppetfile.current_branch} to remote: #{control_repo_remote}".green end end rescue InvalidMetadataSource puts "The puppet module's metadata.json source field must be a git url: ie. [email protected]:devops/module.git".red rescue PuppetfileNotFoundException puts "Cannot find the puppetfile at #{puppetfile_path}".red exit -1 rescue InvalidModuleNameException => e puts e. exit 1 rescue ModNotFoundException puts "Invalid module path for #{mod_path}".red puts "This means that the metadata.json name field does not match\nthe module name found in the Puppetfile or this is not a puppet module".fatal exit -1 end end |