Class: R10kDeployer

Inherits:
Object
  • Object
show all
Includes:
ReleaseManager::Git::Utilities, ReleaseManager::Logger, ReleaseManager::VCSManager
Defined in:
lib/release_manager/r10k_deployer.rb

Instance Attribute Summary collapse

Attributes included from ReleaseManager::VCSManager

#vcs

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ReleaseManager::Git::Utilities

#add_all, #add_file, #add_remote, #apply_diff, #apply_patch, #author, #author_email, #author_name, #branch_exist?, #changed_files, #checkout_branch, #cherry_pick, #cli_create_commit, #clone, #create_branch, #create_commit, #create_diff, #create_diff_obj, #create_local_tag, #credentials, #current_branch, #current_branch?, #delete_branch, #fetch, #fetch_cli, #find_or_create_remote, #find_ref, #find_tag, #get_content, #git_command, #git_url?, #push_branch, #push_tags, #rebase_branch, #ref_exists?, #remote_exists?, #remote_from_name, #remote_from_url, #remote_url_matches?, #remove_file, #repo, #tag_exists?, #tags, #transports, #up2date?

Methods included from ReleaseManager::VCSManager

adapter_instance, adapter_types, default_instance

Methods included from ReleaseManager::Logger

#color, #log_level, #logger

Constructor Details

#initialize(path, opts) ⇒ R10kDeployer

Returns a new instance of R10kDeployer.



14
15
16
17
# File 'lib/release_manager/r10k_deployer.rb', line 14

def initialize(path, opts)
  @path = path
  @options = opts
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/release_manager/r10k_deployer.rb', line 8

def options
  @options
end

#pathObject (readonly) Also known as: control_repo_path

Returns the value of attribute path.



8
9
10
# File 'lib/release_manager/r10k_deployer.rb', line 8

def path
  @path
end

#previous_branchObject (readonly)

Returns the value of attribute previous_branch.



8
9
10
# File 'lib/release_manager/r10k_deployer.rb', line 8

def previous_branch
  @previous_branch
end

Class Method Details

.run(path, options) ⇒ Object



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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/release_manager/r10k_deployer.rb', line 38

def self.run(path, options)
  begin
    deploy = new(path, options)
    deploy.check_requirements
    deploy.logger.info "Deploying R10k-Control #{options[:dest_ref]} with version: #{options[:src_ref]}"
    deploy.run
  rescue GitError => e
    deploy.logger.fatal(e.message)
    code = 1
  rescue Gitlab::Error::Forbidden => e
    logger.fatal(e.message)
    logger.fatal("You don't have access to modify the repository")
  rescue Gitlab::Error::MissingCredentials => e
    deploy.logger.fatal(e.message)
    code = 1
  rescue PatchError => e
    deploy.logger.fatal(e.message)
    code = 1
  rescue ModNotFoundException => e
    deploy.logger.fatal(e.message)
    code = 1
  rescue InvalidBranchName => e
    deploy.logger.fatal(e.message)
    code = 1
  rescue InvalidMetadataSource
    deploy.logger.fatal "The puppet module's metadata.json source field must be a git url: ie. [email protected]:devops/module.git"
    code = 1
  rescue PuppetfileNotFoundException
    deploy.logger.fatal "Cannot find the puppetfile at #{puppetfile_path}"
    code = 1
  rescue InvalidModuleNameException => e
    deploy.logger.fatal e.message
    code = 1
  rescue Gitlab::Error::NotFound => e
    deploy.logger.fatal e.message
    deploy.logger.fatal "Either the project does not exist or you do not have enough permissions"
    code = 1
  rescue Exception => e
    deploy.logger.fatal e.message
    deploy.logger.fatal e.backtrace.join("\n")
    code = 1
  ensure
    exit code.to_i
  end
end

Instance Method Details

#check_requirementsObject



88
89
90
# File 'lib/release_manager/r10k_deployer.rb', line 88

def check_requirements
  raise PuppetfileNotFoundException unless File.exists?(control_repo_path)
end

#cleanup(branch = nil) ⇒ Object



31
32
33
34
# File 'lib/release_manager/r10k_deployer.rb', line 31

def cleanup(branch = nil)
  control_repo.checkout_branch(previous_branch, strategy: :force)
  control_repo.delete_branch(branch) if branch
end

#control_repoObject



84
85
86
# File 'lib/release_manager/r10k_deployer.rb', line 84

def control_repo
  @control_repo ||= setup_control_repo(puppetfile.source)
end

#runObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/release_manager/r10k_deployer.rb', line 19

def run
  begin
    @previous_branch = options[:src_ref]
    mr, branch_name = create_mr(options[:src_ref], options[:dest_ref], options[:remote])
  ensure
    # cleanup branch, checkout previous branch
  end
  if mr
    puts mr.web_url
  end
end