Class: Dapp::Dimg::GitArtifact

Inherits:
Object
  • Object
show all
Includes:
Helper::Tar, Helper::Trivia
Defined in:
lib/dapp/dimg/git_artifact.rb

Overview

Git repo artifact

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper::Trivia

#check_path?, #check_subpath?, #class_to_lowercase, class_to_lowercase, #delete_file, #ignore_path?, #ignore_path_base, #kwargs, #make_path, #path_checker, #search_file_upward

Methods included from Helper::Tar

#tar_gz_read, #tar_read, #tar_write

Constructor Details

#initialize(repo, dimg, to:, name: nil, branch: nil, tag: nil, commit: nil, cwd: nil, include_paths: nil, exclude_paths: nil, owner: nil, group: nil, as: nil, stages_dependencies: {}, ignore_signature_auto_calculation: false) ⇒ GitArtifact

rubocop:disable Metrics/ParameterLists



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dapp/dimg/git_artifact.rb', line 15

def initialize(repo, dimg, to:, name: nil, branch: nil, tag: nil, commit: nil,
               cwd: nil, include_paths: nil, exclude_paths: nil, owner: nil, group: nil, as: nil,
               stages_dependencies: {}, ignore_signature_auto_calculation: false)
  @repo = repo
  @dimg = dimg
  @name = name

  @ignore_signature_auto_calculation = ignore_signature_auto_calculation

  @branch = branch
  @tag = tag
  @commit = commit

  @to = to
  @cwd = (cwd.nil? || cwd.empty? || cwd == '/') ? '' : File.expand_path(File.join('/', cwd, '/'))[1..-1]
  @include_paths = include_paths
  @exclude_paths = exclude_paths
  @owner = owner
  @group = group
  @as = as
  @stages_dependencies = stages_dependencies
end

Instance Attribute Details

#asObject (readonly)

Returns the value of attribute as.



10
11
12
# File 'lib/dapp/dimg/git_artifact.rb', line 10

def as
  @as
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/dapp/dimg/git_artifact.rb', line 9

def name
  @name
end

#repoObject (readonly)

Returns the value of attribute repo.



8
9
10
# File 'lib/dapp/dimg/git_artifact.rb', line 8

def repo
  @repo
end

Instance Method Details

#_stages_mapObject



147
148
149
150
151
152
153
154
155
# File 'lib/dapp/dimg/git_artifact.rb', line 147

def _stages_map
  {
    before_install: "beforeInstall",
    install: "install",
    before_setup: "beforeSetup",
    setup: "setup",
    build_artifact: "buildArtifact",
  }
end

#_stages_map_reversedObject



157
158
159
# File 'lib/dapp/dimg/git_artifact.rb', line 157

def _stages_map_reversed
  _stages_map.map {|k, v| [v, k]}.to_h
end

#apply_archive_command(stage) ⇒ Object

rubocop:enable Metrics/ParameterLists



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/dapp/dimg/git_artifact.rb', line 39

def apply_archive_command(stage)
  res = repo.dapp.ruby2go_git_artifact(
    "GitArtifact" => JSON.dump(get_ruby2go_state_hash),
    "method" => "ApplyArchiveCommand",
    "Stage" => JSON.dump(merge_layer_commit_stub_stage_state(stage.get_ruby2go_state_hash, stage)),
  )

  raise res["error"] if res["error"]

  self.set_ruby2go_state_hash(JSON.load(res["data"]["GitArtifact"]))
  stage.set_ruby2go_state_hash(JSON.load(res["data"]["Stage"]))

  Array(res["data"]["result"])
end

#apply_patch_command(stage) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/dapp/dimg/git_artifact.rb', line 66

def apply_patch_command(stage)
  res = repo.dapp.ruby2go_git_artifact(
    "GitArtifact" => JSON.dump(get_ruby2go_state_hash),
    "method" => "ApplyPatchCommand",
    "Stage" => JSON.dump(merge_layer_commit_stub_stage_state(stage.get_ruby2go_state_hash, stage)),
  )

  raise res["error"] if res["error"]

  self.set_ruby2go_state_hash(JSON.load(res["data"]["GitArtifact"]))
  stage.set_ruby2go_state_hash(JSON.load(res["data"]["Stage"]))

  Array(res["data"]["result"])
end

#calculate_stage_dependencies_checksum(stage) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/dapp/dimg/git_artifact.rb', line 81

def calculate_stage_dependencies_checksum(stage)
  res = repo.dapp.ruby2go_git_artifact(
    "GitArtifact" => JSON.dump(get_ruby2go_state_hash),
    "method" => "StageDependenciesChecksum",
    "StageName" => ::Dapp::Helper::CaseConversion.snake_case_to_lower_camel_case(stage.name.to_s),
  )

  raise res["error"] if res["error"]

  self.set_ruby2go_state_hash(JSON.load(res["data"]["GitArtifact"]))

  result = res["data"]["result"]
  return [] if result == ""
  return result
end

#full_nameObject



208
209
210
211
212
213
214
215
216
217
218
# File 'lib/dapp/dimg/git_artifact.rb', line 208

def full_name
  @full_name ||= begin
    res = repo.dapp.ruby2go_git_artifact("GitArtifact" => JSON.dump(get_ruby2go_state_hash), "method" => "FullName")

    raise res["error"] if res["error"]

    self.set_ruby2go_state_hash(JSON.load(res["data"]["GitArtifact"]))

    res["data"]["result"]
  end
end

#get_ruby2go_state_hashObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/dapp/dimg/git_artifact.rb', line 117

def get_ruby2go_state_hash
  {
    "Name" => @name.to_s,
    "As" => @as.to_s,
    "Branch" => @branch.to_s,
    "Tag" => @tag.to_s,
    "Commit" => @commit.to_s,
    "To" => @to.to_s,
    "Cwd" => @cwd.to_s,
    "RepoPath" => File.join("/", @cwd.to_s),
    "Owner" => @owner.to_s,
    "Group" => @group.to_s,
    "IncludePaths" => @include_paths,
    "ExcludePaths" => @exclude_paths,
    "StagesDependencies" => @stages_dependencies.map {|k, v| [_stages_map[k], Array(v).map(&:to_s)]}.to_h,
    "PatchesDir" => dimg.tmp_path('patches'),
    "ContainerPatchesDir" => dimg.container_tmp_path('patches'),
    "ArchivesDir" => dimg.tmp_path('archives'),
    "ContainerArchivesDir" => dimg.container_tmp_path('archives'),
  }.tap {|res|
    if repo.is_a? ::Dapp::Dimg::GitRepo::Local
      res["LocalGitRepo"] = repo.get_ruby2go_state_hash
    elsif repo.is_a? ::Dapp::Dimg::GitRepo::Remote
      res["RemoteGitRepo"] = repo.get_ruby2go_state_hash
    else
      raise
    end
  }
end

#is_emptyObject



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/dapp/dimg/git_artifact.rb', line 238

def is_empty
  return @is_empty if !@is_empty.nil?

  @is_empty = begin
    res = repo.dapp.ruby2go_git_artifact(
      "GitArtifact" => JSON.dump(get_ruby2go_state_hash),
      "method" => "IsEmpty",
    )

    raise res["error"] if res["error"]

    self.set_ruby2go_state_hash(JSON.load(res["data"]["GitArtifact"]))

    res["data"]["result"]
  end
end

#is_patch_empty(stage) ⇒ Object



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/dapp/dimg/git_artifact.rb', line 220

def is_patch_empty(stage)
  return @is_patch_empty if !@is_patch_empty.nil?

  @is_patch_empty = begin
    res = repo.dapp.ruby2go_git_artifact(
      "GitArtifact" => JSON.dump(get_ruby2go_state_hash),
      "method" => "IsPatchEmpty",
      "Stage" => JSON.dump(merge_layer_commit_stub_stage_state({"PrevStage" => {}}, stage)),
    )

    raise res["error"] if res["error"]

    self.set_ruby2go_state_hash(JSON.load(res["data"]["GitArtifact"]))

    res["data"]["result"]
  end
end

#latest_commitObject



182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/dapp/dimg/git_artifact.rb', line 182

def latest_commit
  @latest_commit ||= begin
    res = repo.dapp.ruby2go_git_artifact("GitArtifact" => JSON.dump(get_ruby2go_state_hash), "method" => "LatestCommit")

    raise res["error"] if res["error"]

    self.set_ruby2go_state_hash(JSON.load(res["data"]["GitArtifact"]))

    res["data"]["result"]
  end.tap do |c|
    repo.dapp.log_info("Repository `#{repo.name}`: latest commit `#{c}` to `#{to}`") unless ignore_signature_auto_calculation
  end
end

#merge_layer_commit_stub_stage_state(stage_state, stage) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/dapp/dimg/git_artifact.rb', line 54

def merge_layer_commit_stub_stage_state(stage_state, stage)
  # Data for StubStage specific for ApplyPatchCommand
  stage_state["LayerCommitMap"] = {
    paramshash => stage.layer_commit(self),
  }
  stage_state["PrevStage"]["LayerCommitMap" ] = {
    paramshash => stage.prev_stage.layer_commit(self),
  }

  stage_state
end

#paramshashObject



196
197
198
199
200
201
202
203
204
205
206
# File 'lib/dapp/dimg/git_artifact.rb', line 196

def paramshash
  @paramshash ||= begin
    res = repo.dapp.ruby2go_git_artifact("GitArtifact" => JSON.dump(get_ruby2go_state_hash), "method" => "GetParamshash")

    raise res["error"] if res["error"]

    self.set_ruby2go_state_hash(JSON.load(res["data"]["GitArtifact"]))

    res["data"]["result"]
  end
end

#patch_size(from_commit) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/dapp/dimg/git_artifact.rb', line 103

def patch_size(from_commit)
  res = repo.dapp.ruby2go_git_artifact(
    "GitArtifact" => JSON.dump(get_ruby2go_state_hash),
    "method" => "PatchSize",
    "FromCommit" => from_commit,
  )

  raise res["error"] if res["error"]

  self.set_ruby2go_state_hash(JSON.load(res["data"]["GitArtifact"]))

  res["data"]["result"]
end

#set_ruby2go_state_hash(new_state) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/dapp/dimg/git_artifact.rb', line 161

def set_ruby2go_state_hash(new_state)
  [
    [:@name, new_state["Name"]],
    [:@as, new_state["As"]],
    [:@branch, new_state["Branch"]],
    [:@tag, new_state["Tag"]],
    [:@commit, new_state["Commit"]],
    [:@cwd, new_state["Cwd"]],
    [:@owner, new_state["Owner"]],
    [:@group, new_state["Group"]],
  ].each do |var, new_value|
    if new_value != ""
      instance_variable_set(var, new_value)
    end
  end

  @stages_dependencies = new_state["StagesDependencies"].map do |k, v|
    [_stages_map_reversed[k], v]
  end.to_h
end

#stage_dependencies_checksum(stage) ⇒ Object



97
98
99
100
101
# File 'lib/dapp/dimg/git_artifact.rb', line 97

def stage_dependencies_checksum(stage)
  stage_dependencies_key = [stage.name, commit]
  @stage_dependencies_checksums ||= {}
  @stage_dependencies_checksums[stage_dependencies_key] ||= calculate_stage_dependencies_checksum(stage)
end