Class: ModuleDeployer
Instance Attribute Summary collapse
Instance Method Summary
collapse
#color, #log_level, #logger
Constructor Details
Returns a new instance of ModuleDeployer.
10
11
12
13
|
# File 'lib/release_manager/module_deployer.rb', line 10
def initialize(opts)
opts[:modulepath] = Dir.getwd if opts[:modulepath].nil?
@options = opts
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
7
8
9
|
# File 'lib/release_manager/module_deployer.rb', line 7
def options
@options
end
|
Instance Method Details
#add_module(puppet_module) ⇒ Object
50
51
52
53
54
55
56
57
|
# File 'lib/release_manager/module_deployer.rb', line 50
def add_module(puppet_module)
unless puppetfile.mod_exists?(puppet_module.name)
answer = ask("The #{puppet_module.name} module does not exist, do you want to add it? (y/n): ", String) { |q| q =~ /y|n/i }.downcase unless options[:auto]
if answer == 'y' or options[:auto]
puppetfile.add_module(puppet_module.name, git: puppet_module.repo, tag: "v#{puppet_module.version}") unless options[:dry_run]
end
end
end
|
#check_requirements ⇒ Object
#control_repo_remote ⇒ Object
36
37
38
|
# File 'lib/release_manager/module_deployer.rb', line 36
def control_repo_remote
@control_repo_remote ||= options[:remote] || puppetfile.source
end
|
#latest_version ⇒ Object
27
28
29
|
# File 'lib/release_manager/module_deployer.rb', line 27
def latest_version
puppet_module.latest_tag
end
|
#mod_path ⇒ Object
19
20
21
|
# File 'lib/release_manager/module_deployer.rb', line 19
def mod_path
@mod_path ||= options[:modulepath] || ENV['MOD_DIR'] || File.expand_path(Dir.getwd)
end
|
#puppet_module ⇒ Object
23
24
25
|
# File 'lib/release_manager/module_deployer.rb', line 23
def puppet_module
@puppet_module ||= PuppetModule.new(mod_path)
end
|
#puppetfile ⇒ Object
40
41
42
|
# File 'lib/release_manager/module_deployer.rb', line 40
def puppetfile
@puppetfile ||= Puppetfile.new(puppetfile_path)
end
|
#puppetfile_path ⇒ Object
15
16
17
|
# File 'lib/release_manager/module_deployer.rb', line 15
def puppetfile_path
@puppetfile_path ||= options[:puppetfile] || ENV['PUPPET_FILE_PATH'] || File.expand_path("~/repos/r10k-control/Puppetfile")
end
|
#remote_deploy? ⇒ Boolean
44
45
46
|
# File 'lib/release_manager/module_deployer.rb', line 44
def remote_deploy?
options[:remote]
end
|
#run ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/release_manager/module_deployer.rb', line 59
def run
begin
check_requirements
logger.info "Deploying module #{puppet_module.name} with version: #{latest_version}"
add_module(puppet_module)
if options[: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 options[:commit]
puts "Would have just pushed branch: #{puppetfile.current_branch} to remote: #{control_repo_remote}".green if options[:push]
else
puppetfile.write_version(puppet_module.name, latest_version)
puppetfile.write_source(puppet_module.name, puppet_module.source)
updated = puppetfile.write_to_file
unless updated
logger.warn "Module #{puppet_module.name} with version #{latest_version} has already been deployed, skipping deployment"
return
end
logger.info "Updated module #{puppet_module.name} in Puppetfile to version: #{latest_version}"
if options[:commit]
puppetfile.commit("bump #{puppet_module.name} to version #{latest_version}")
end
if remote_deploy?
puppetfile.push(control_repo_remote, puppetfile.current_branch)
logger.info "Just pushed branch: #{puppetfile.current_branch} to remote: #{control_repo_remote}"
end
end
rescue InvalidMetadataSource
logger.fatal "The puppet module's metadata.json source field must be a git url: ie. [email protected]:devops/module.git"
rescue PuppetfileNotFoundException
logger.fatal "Cannot find the puppetfile at #{puppetfile_path}"
exit -1
rescue InvalidModuleNameException => e
logger.fatal e.message
exit 1
rescue ModNotFoundException
logger.fatal "Invalid module path for #{mod_path}"
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
|