Class: Dapp::GitArtifact
- Inherits:
-
Object
- Object
- Dapp::GitArtifact
- Defined in:
- lib/dapp/git_artifact.rb
Overview
Artifact from Git repo
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
Instance Method Summary collapse
- #any_changes?(from, to = latest_commit) ⇒ Boolean
-
#apply_archive_command(stage) ⇒ Object
rubocop:enable Metrics/ParameterLists.
- #apply_patch_command(stage) ⇒ Object
- #archive_command_excludes ⇒ Object
- #base_paths(paths, with_cwd = false) ⇒ Object
- #exclude_paths(with_cwd = false) ⇒ Object
- #full_name ⇒ Object
-
#initialize(repo, where_to_add:, name: nil, branch: nil, commit: nil, cwd: nil, paths: nil, exclude_paths: nil, owner: nil, group: nil) ⇒ GitArtifact
constructor
rubocop:disable Metrics/ParameterLists.
- #latest_commit ⇒ Object
- #paramshash ⇒ Object
- #patch_command_excludes ⇒ Object
- #patch_size(from, to) ⇒ Object
- #paths(with_cwd = false) ⇒ Object
Constructor Details
#initialize(repo, where_to_add:, name: nil, branch: nil, commit: nil, cwd: nil, paths: nil, exclude_paths: nil, owner: nil, group: nil) ⇒ GitArtifact
rubocop:disable Metrics/ParameterLists
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/dapp/git_artifact.rb', line 8 def initialize(repo, where_to_add:, name: nil, branch: nil, commit: nil, cwd: nil, paths: nil, exclude_paths: nil, owner: nil, group: nil) @repo = repo @name = name @where_to_add = where_to_add @branch = branch || repo.application.project.[:git_artifact_branch] || repo.branch @commit = commit cwd = File.(File.join('/', cwd))[1..-1] unless cwd.nil? || cwd.empty? @cwd = cwd @paths = paths @exclude_paths = exclude_paths @owner = owner @group = group end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/dapp/git_artifact.rb', line 5 def name @name end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
4 5 6 |
# File 'lib/dapp/git_artifact.rb', line 4 def repo @repo end |
Instance Method Details
#any_changes?(from, to = latest_commit) ⇒ Boolean
58 59 60 |
# File 'lib/dapp/git_artifact.rb', line 58 def any_changes?(from, to = latest_commit) !repo.(diff_command(from, to, quiet: true), returns: [0, 1]).status.success? end |
#apply_archive_command(stage) ⇒ Object
rubocop:enable Metrics/ParameterLists
27 28 29 30 31 32 33 |
# File 'lib/dapp/git_artifact.rb', line 27 def apply_archive_command(stage) credentials = [:owner, :group].map { |attr| "--#{attr}=#{send(attr)}" unless send(attr).nil? }.compact ["#{repo.application.project.install_path} #{credentials.join(' ')} -d #{where_to_add}", ["#{repo.application.project.git_path} --git-dir=#{repo.container_path} archive #{stage.layer_commit(self)}:#{cwd} #{paths.join(' ')}", "#{sudo}#{repo.application.project.tar_path} -x -C #{where_to_add} #{archive_command_excludes.join(' ')}"].join(' | ')] end |
#apply_patch_command(stage) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/dapp/git_artifact.rb', line 35 def apply_patch_command(stage) current_commit = stage.layer_commit(self) prev_commit = stage.prev_g_a_stage.layer_commit(self) if prev_commit != current_commit || any_changes?(prev_commit, current_commit) [["#{repo.application.project.git_path} --git-dir=#{repo.container_path} #{diff_command(prev_commit, current_commit)}", "#{sudo}#{repo.application.project.git_path} apply --whitespace=nowarn --directory=#{where_to_add} #{patch_command_excludes.join(' ')} --unsafe-paths"].join(' | ')] else [] end end |
#archive_command_excludes ⇒ Object
47 48 49 |
# File 'lib/dapp/git_artifact.rb', line 47 def archive_command_excludes exclude_paths.map { |path| %(--exclude=#{path}) } end |
#base_paths(paths, with_cwd = false) ⇒ Object
82 83 84 |
# File 'lib/dapp/git_artifact.rb', line 82 def base_paths(paths, with_cwd = false) [paths].flatten.compact.map { |path| (with_cwd && cwd ? File.join(cwd, path) : path).gsub(%r{^\/*|\/*$}, '') } end |
#exclude_paths(with_cwd = false) ⇒ Object
74 75 76 |
# File 'lib/dapp/git_artifact.rb', line 74 def exclude_paths(with_cwd = false) base_paths(@exclude_paths, with_cwd) end |
#full_name ⇒ Object
86 87 88 |
# File 'lib/dapp/git_artifact.rb', line 86 def full_name "#{repo.name}#{name ? "_#{name}" : nil}" end |
#latest_commit ⇒ Object
66 67 68 |
# File 'lib/dapp/git_artifact.rb', line 66 def latest_commit @latest_commit ||= commit || repo.latest_commit(branch) end |
#paramshash ⇒ Object
70 71 72 |
# File 'lib/dapp/git_artifact.rb', line 70 def paramshash Digest::SHA256.hexdigest [where_to_add, cwd, *paths, *exclude_paths, owner, group].map(&:to_s).join(':::') end |
#patch_command_excludes ⇒ Object
51 52 53 54 55 56 |
# File 'lib/dapp/git_artifact.rb', line 51 def patch_command_excludes exclude_paths.map do |path| base = File.join(where_to_add, path) path =~ /[\*\?\[\]\{\}]/ ? %(--exclude=#{base} ) : %(--exclude=#{base} --exclude=#{File.join(base, '*')}) end end |
#patch_size(from, to) ⇒ Object
62 63 64 |
# File 'lib/dapp/git_artifact.rb', line 62 def patch_size(from, to) repo.("#{diff_command(from, to)} | wc -c").stdout.strip.to_i end |
#paths(with_cwd = false) ⇒ Object
78 79 80 |
# File 'lib/dapp/git_artifact.rb', line 78 def paths(with_cwd = false) base_paths(@paths, with_cwd) end |