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_patch_command(stage) ⇒ Object
-
#archive_apply_command(stage) ⇒ Object
rubocop:enable Metrics/ParameterLists.
- #filename(ending) ⇒ Object
-
#initialize(repo, where_to_add:, name: nil, branch: nil, commit: nil, cwd: nil, paths: nil, owner: nil, group: nil) ⇒ GitArtifact
constructor
rubocop:disable Metrics/ParameterLists.
- #latest_commit ⇒ Object
- #paramshash ⇒ 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, owner: nil, group: nil) ⇒ GitArtifact
rubocop:disable Metrics/ParameterLists
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/dapp/git_artifact.rb', line 8 def initialize(repo, where_to_add:, name: nil, branch: nil, commit: nil, cwd: nil, paths: nil, owner: nil, group: nil) @repo = repo @name = name @where_to_add = where_to_add @branch = branch || repo.application.[:git_artifact_branch] || repo.branch @commit = commit @cwd = cwd @paths = 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
46 47 48 |
# File 'lib/dapp/git_artifact.rb', line 46 def any_changes?(from, to = latest_commit) !repo.(diff_command(from, to, quiet: true), returns: [0, 1]).status.success? end |
#apply_patch_command(stage) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/dapp/git_artifact.rb', line 33 def apply_patch_command(stage) current_commit = stage.layer_commit(self) prev_commit = stage.prev_source_stage.layer_commit(self) if prev_commit != current_commit || any_changes?(prev_commit, current_commit) [["git --git-dir=#{repo.container_build_dir_path} #{diff_command(prev_commit, current_commit)}", "#{sudo}git apply --whitespace=nowarn --directory=#{where_to_add} " \ '$(if [[ "$(git --version)" != "git version 1."* ]]; then echo "--unsafe-paths"; fi)'].join(' | ')] # FIXME else [] end end |
#archive_apply_command(stage) ⇒ Object
rubocop:enable Metrics/ParameterLists
25 26 27 28 29 30 31 |
# File 'lib/dapp/git_artifact.rb', line 25 def archive_apply_command(stage) credentials = [:owner, :group].map { |attr| "--#{attr}=#{send(attr)}" unless send(attr).nil? }.compact ["install #{credentials.join(' ')} -d #{where_to_add}", ["git --git-dir=#{repo.container_build_dir_path} archive #{stage.layer_commit(self)}:#{cwd} #{paths}", "#{sudo}tar -x -C #{where_to_add}"].join(' | ')] end |
#filename(ending) ⇒ Object
66 67 68 |
# File 'lib/dapp/git_artifact.rb', line 66 def filename(ending) "#{repo.name}#{name ? "_#{name}" : nil}#{ending}" end |
#latest_commit ⇒ Object
54 55 56 |
# File 'lib/dapp/git_artifact.rb', line 54 def latest_commit @latest_commit ||= commit || repo.latest_commit(branch) end |
#paramshash ⇒ Object
58 59 60 |
# File 'lib/dapp/git_artifact.rb', line 58 def paramshash Digest::SHA256.hexdigest [cwd, paths, owner, group].map(&:to_s).join(':::') end |
#patch_size(from, to) ⇒ Object
50 51 52 |
# File 'lib/dapp/git_artifact.rb', line 50 def patch_size(from, to) repo.("#{diff_command(from, to)} | wc -c").stdout.strip.to_i end |
#paths(with_cwd = false) ⇒ Object
62 63 64 |
# File 'lib/dapp/git_artifact.rb', line 62 def paths(with_cwd = false) [@paths].flatten.compact.map { |path| (with_cwd && cwd ? "#{cwd}/#{path}" : path).gsub(%r{^\/*|\/*$}, '') }.join(' ') if @paths end |