Class: ReleaseManager::DeployR10kCli

Inherits:
Object
  • Object
show all
Defined in:
lib/release_manager/cli/deploy_r10k_cli.rb

Class Method Summary collapse

Class Method Details

.puppetfile_pathObject



7
8
9
# File 'lib/release_manager/cli/deploy_r10k_cli.rb', line 7

def self.puppetfile_path
  ENV['PUPPET_FILE_PATH'] || File.join(File.expand_path(Dir.pwd), 'Puppetfile')
end

.runObject



20
21
22
23
24
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
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/release_manager/cli/deploy_r10k_cli.rb', line 20

def self.run
  options = {}
  @o = OptionParser.new do |opts|
    opts.program_name = 'deploy-r10k'
    opts.version = ReleaseManager::VERSION
    opts.on_head(<<-EOF

Summary: Deploys the source ref into the dest branch by diffing the two and applying the diff.  Generates a merge 
     request after committing the changes to the dest branch.

   1. fetches the latest code
   2. creates the necessary remotes
   3. Forks project
   4. creates new branch 
   5. creates diff and applies diff to new branch
   6. push branch and create merge request

   Examples:
  deploy-r10k -s dev -d qa
  deploy-r10k -p ~/repos/r10k-control -s dev -d qa
  deploy-r10k -s v0.5.1 -d production

Options:
    EOF
    )
    opts.on('-p', "--puppetfile [PUPPETFILE]", "Path to R10k Puppetfile, defaults to #{puppetfile_path}") do |p|
      options[:puppetfile] = File.expand_path(p)
    end
    opts.on('-s', "--source [SRC_REF]", "The source ref or branch you want to deploy") do |p|
      options[:src_ref] = p
    end
    opts.on('-d', "--dest [DEST_BRANCH]", "The destination branch you want to deploy to") do |p|
      options[:dest_ref] = p
    end
  end
  @o.parse!
  options[:puppetfile] = options[:puppetfile] || puppetfile_path
  options[:src_ref] ||= ARGV[0]
  options[:dest_ref] ||= ARGV[1]
  options[:remote] = true
  validate(options)
  path = File.dirname(options[:puppetfile])
  ReleaseManager::VCSManager.default_instance.validate_authorization
  R10kDeployer.run(path, options)
end

.validate(options) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/release_manager/cli/deploy_r10k_cli.rb', line 11

def self.validate(options)
  if options[:src_ref].nil? or options[:dest_ref].nil?
    puts "You must supply --source and --dest arguments".red
    puts @o
    exit 1
  end

end