dapp 0.32.10 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/bin/dapp +1 -23
  3. data/config/en/net_status.yml +7 -0
  4. data/lib/dapp.rb +3 -3
  5. data/lib/dapp/dapp.rb +13 -0
  6. data/lib/dapp/dapp/dappfile.rb +2 -2
  7. data/lib/dapp/dapp/deps/base.rb +5 -37
  8. data/lib/dapp/dapp/deps/common.rb +25 -0
  9. data/lib/dapp/dapp/deps/gitartifact.rb +2 -25
  10. data/lib/dapp/dapp/deps/toolchain.rb +1 -23
  11. data/lib/dapp/dapp/logging/base.rb +3 -3
  12. data/lib/dapp/dapp/ruby2go.rb +96 -0
  13. data/lib/dapp/dapp/sentry.rb +0 -1
  14. data/lib/dapp/dapp/shellout/base.rb +4 -2
  15. data/lib/dapp/dimg/build/stage/artifact_base.rb +7 -6
  16. data/lib/dapp/dimg/build/stage/base.rb +37 -7
  17. data/lib/dapp/dimg/build/stage/from.rb +1 -1
  18. data/lib/dapp/dimg/builder/ansible.rb +1 -209
  19. data/lib/dapp/dimg/builder/base.rb +0 -5
  20. data/lib/dapp/dimg/builder/none.rb +1 -34
  21. data/lib/dapp/dimg/builder/ruby2go.rb +51 -0
  22. data/lib/dapp/dimg/builder/shell.rb +1 -25
  23. data/lib/dapp/dimg/cli/command/dimg/bp.rb +10 -15
  24. data/lib/dapp/dimg/cli/command/dimg/build.rb +0 -5
  25. data/lib/dapp/dimg/config/directive/docker/base.rb +1 -1
  26. data/lib/dapp/dimg/dapp/command/build_context/export.rb +1 -1
  27. data/lib/dapp/dimg/dapp/command/build_context/import.rb +1 -1
  28. data/lib/dapp/dimg/dapp/command/cleanup_repo.rb +59 -90
  29. data/lib/dapp/dimg/dapp/command/common.rb +60 -74
  30. data/lib/dapp/dimg/dapp/command/mrproper.rb +2 -17
  31. data/lib/dapp/dimg/dapp/command/stages/cleanup_local.rb +9 -6
  32. data/lib/dapp/dimg/dimg.rb +26 -43
  33. data/lib/dapp/dimg/docker_registry/base/authorization.rb +1 -16
  34. data/lib/dapp/dimg/git_artifact.rb +142 -21
  35. data/lib/dapp/dimg/git_repo/base.rb +11 -0
  36. data/lib/dapp/dimg/git_repo/local.rb +14 -0
  37. data/lib/dapp/dimg/git_repo/remote.rb +25 -34
  38. data/lib/dapp/dimg/image/argument.rb +12 -58
  39. data/lib/dapp/dimg/image/stage.rb +202 -43
  40. data/lib/dapp/kube/kubernetes/client.rb +0 -6
  41. data/lib/dapp/kube/kubernetes/manager/deployment.rb +18 -30
  42. data/lib/dapp/version.rb +1 -1
  43. metadata +8 -8
  44. data/lib/dapp/dimg/builder/ansible/assets.rb +0 -349
  45. data/lib/dapp/dimg/exception/introspect_image.rb +0 -7
  46. data/lib/dapp/dimg/image/docker.rb +0 -144
@@ -38,13 +38,6 @@ module Dapp
38
38
 
39
39
  def proper_all
40
40
  flush_by_label('dapp')
41
- remove_build_dir
42
- end
43
-
44
- def remove_build_dir
45
- build_path.tap { |p| log_step_with_indent(:build_dir) { FileUtils.rm_rf(p) } }
46
- rescue ::Dapp::Error::Dapp => e
47
- raise unless e.net_status[:code] == :dappfile_not_found
48
41
  end
49
42
 
50
43
  def proper_dev_mode_cache
@@ -71,19 +64,11 @@ module Dapp
71
64
  end
72
65
 
73
66
  def proper_cache_all_images_names
74
- shellout!(%(#{host_docker} images --format='{{if ne "<none>" .Tag }}{{.Repository}}:{{.Tag}}{{ end }}' -f "label=dapp" -f "label=dapp-cache-version=#{::Dapp::BUILD_CACHE_VERSION}"))
75
- .stdout
76
- .lines
77
- .map(&:strip)
78
- .reject(&:empty?)
67
+ ruby2go_image_images([{ label: "dapp" }, { label: "dapp-cache-version=#{::Dapp::BUILD_CACHE_VERSION}" }], ignore_tagless: true).map { |i| i["RepoTags"].empty? ? i["Id"] : i["RepoTags"] }.flatten
79
68
  end
80
69
 
81
70
  def dapp_images_names_by_label(label)
82
- shellout!(%(#{host_docker} images --format='{{if ne "<none>" .Tag }}{{.Repository}}:{{.Tag}}{{ end }}' -f "label=dapp" -f "label=#{label}"))
83
- .stdout
84
- .lines
85
- .map(&:strip)
86
- .reject(&:empty?)
71
+ ruby2go_image_images([{ label: "dapp" }, { label: label }], ignore_tagless: true).map { |i| i["RepoTags"].empty? ? i["Id"] : i["RepoTags"] }.flatten
87
72
  end
88
73
  end
89
74
  end
@@ -24,7 +24,7 @@ module Dapp
24
24
  lock("#{name}.images") do
25
25
  remove_project_images begin
26
26
  dapp_project_dimgstages.select do |image|
27
- !actual_cache_project_dimgstages.map { |dimgstage| dimgstage[:id] }.include?(image[:id])
27
+ !actual_cache_project_dimgstages.map { |dimgstage| dimgstage["Id"] }.include?(image["Id"])
28
28
  end
29
29
  end
30
30
  end
@@ -32,7 +32,10 @@ module Dapp
32
32
  end
33
33
 
34
34
  def actual_cache_project_dimgstages
35
- @actual_cache_project_images_ids ||= prepare_docker_images("-f \"label=dapp-cache-version=#{::Dapp::BUILD_CACHE_VERSION}\" #{stage_cache}")
35
+ @actual_cache_project_dimgstages ||= begin
36
+ filters = [{ label: "dapp-cache-version=#{::Dapp::BUILD_CACHE_VERSION}", reference: stage_cache }]
37
+ prepare_docker_images(extra_filters: filters)
38
+ end
36
39
  end
37
40
 
38
41
  def stages_cleanup_by_repo
@@ -46,7 +49,7 @@ module Dapp
46
49
 
47
50
  # Удаление только образов старше 2ч
48
51
  dimgstages.delete_if do |dimgstage|
49
- Time.now.to_i - dimgstage[:created_at] < 2 * 60 * 60
52
+ Time.now.to_i - dimgstage["Created"] < 2 * 60 * 60
50
53
  end unless ENV['DAPP_STAGES_CLEANUP_LOCAL_DISABLED_DATE_POLICY']
51
54
 
52
55
  remove_project_images(dimgstages)
@@ -73,7 +76,7 @@ module Dapp
73
76
  end
74
77
 
75
78
  def dapp_project_image_artifacts_ids_in_labels(image)
76
- select_dapp_artifacts_ids(dapp_project_image_labels(image))
79
+ select_dapp_artifacts_ids(image['Labels'])
77
80
  end
78
81
 
79
82
  def proper_git_commit
@@ -81,7 +84,7 @@ module Dapp
81
84
  lock("#{name}.images") do
82
85
  unproper_images = []
83
86
  dapp_project_dimgstages.each do |dimgstage|
84
- dapp_project_image_labels(dimgstage).each do |repo_name, commit|
87
+ dimgstage["Labels"].each do |repo_name, commit|
85
88
  next if (repo = dapp_git_repositories[repo_name]).nil?
86
89
  unproper_images.concat(dapp_project_image_with_children(dimgstage)) unless repo.commit_exists?(commit)
87
90
  end
@@ -109,7 +112,7 @@ module Dapp
109
112
  end
110
113
 
111
114
  def dapp_project_image_parent(image)
112
- dapp_project_image_by_id(dapp_project_image_inspect(image)['Parent'])
115
+ dapp_project_image_by_id(image['ParentId'])
113
116
  end
114
117
  end
115
118
  end
@@ -13,6 +13,13 @@ module Dapp
13
13
  attr_reader :should_be_built
14
14
  attr_reader :dapp
15
15
 
16
+ def get_ruby2go_state_hash
17
+ {
18
+ "Dapp" => dapp.get_ruby2go_state_hash,
19
+ "TmpPath" => tmp_path.to_s,
20
+ }
21
+ end
22
+
16
23
  def initialize(config:, dapp:, should_be_built: false, ignore_signature_auto_calculation: false)
17
24
  @config = config
18
25
  @dapp = dapp
@@ -42,22 +49,19 @@ module Dapp
42
49
  end
43
50
 
44
51
  def build!
45
- with_introspection do
46
- dapp.lock("#{dapp.name}.images", readonly: true) do
47
- last_stage.build_lock! do
48
- begin
49
- builder.before_build_check
50
- last_stage.build!
51
- ensure
52
- after_stages_build!
53
- end
52
+ dapp.lock("#{dapp.name}.images", readonly: true) do
53
+ last_stage.build_lock! do
54
+ begin
55
+ builder.before_build_check
56
+ last_stage.build!
57
+ ensure
58
+ after_stages_build!
54
59
  end
55
60
  end
56
61
  end
57
62
  end
58
63
 
59
64
  def after_stages_build!
60
- return unless last_stage.image.built? || dev_mode? || force_save_cache?
61
65
  last_stage.save_in_cache!
62
66
  artifacts.each { |artifact| artifact.last_stage.save_in_cache! }
63
67
  end
@@ -158,7 +162,6 @@ module Dapp
158
162
  dapp.log_state(image_name, state: dapp.t(code: push ? 'state.push' : 'state.export'), styles: { status: :success })
159
163
  else
160
164
  dapp.lock("image.#{hashsum image_name}") do
161
- ::Dapp::Dimg::Image::Docker.reset_image_inspect(image_name)
162
165
  dapp.log_process(image_name, process: dapp.t(code: push ? 'status.process.pushing' : 'status.process.exporting')) { yield }
163
166
  end
164
167
  end
@@ -209,11 +212,12 @@ module Dapp
209
212
  def run_stage(stage_name, docker_options, command)
210
213
  stage_image = (stage_name.nil? ? last_stage : stage_by_name(stage_name)).image
211
214
  raise Error::Dimg, code: :dimg_stage_not_built, data: { stage_name: stage_name } unless stage_image.built?
212
- cmd = "#{dapp.host_docker} run #{[docker_options, stage_image.built_id, command].flatten.compact.join(' ')}"
215
+
216
+ args = [docker_options, stage_image.built_id, command].flatten.compact
213
217
  if dapp.dry_run?
214
- dapp.log(cmd)
218
+ dapp.log("docker run #{args.join(' ')}")
215
219
  else
216
- system(cmd) || raise(Error::Dimg, code: :dimg_not_run)
220
+ Image::Stage.ruby2go_command(dapp, command: :container_run, options: { args: args })
217
221
  end
218
222
  end
219
223
 
@@ -241,23 +245,10 @@ module Dapp
241
245
  dapp.dev_mode?
242
246
  end
243
247
 
244
- def force_save_cache?
245
- if ENV.key? "DAPP_FORCE_SAVE_CACHE"
246
- %w(yes 1 true).include? ENV["DAPP_FORCE_SAVE_CACHE"].to_s
247
- else
248
- !!dapp.options[:force_save_cache]
249
- end
250
- end
251
-
252
248
  def build_cache_version
253
249
  [::Dapp::BUILD_CACHE_VERSION, dev_mode? ? 1 : 0]
254
250
  end
255
251
 
256
- def introspect_image!(image:, options:)
257
- cmd = "#{dapp.host_docker} run -ti --rm --entrypoint #{dapp.bash_bin} #{options} #{image}"
258
- system(cmd)
259
- end
260
-
261
252
  def cleanup_tmp
262
253
  return unless tmp_dir_exists?
263
254
 
@@ -265,14 +256,14 @@ module Dapp
265
256
  # Такие файлы могут попасть туда при экспорте файлов артефакта.
266
257
  # Чтобы от них избавиться — запускаем docker-контейнер под root-пользователем
267
258
  # и удаляем примонтированную tmp-директорию.
268
- cmd = "".tap do |cmd|
269
- cmd << "#{dapp.host_docker} run --rm"
270
- cmd << " --volume #{dapp.tmp_base_dir}:#{dapp.tmp_base_dir}"
271
- cmd << " --label dapp=#{dapp.name}"
272
- cmd << " alpine:3.6"
273
- cmd << " rm -rf #{tmp_path}"
274
- end
275
- dapp.shellout! cmd
259
+ args = [
260
+ "--rm",
261
+ "--volume=#{dapp.tmp_base_dir}:#{dapp.tmp_base_dir}",
262
+ "--label=dapp=#{dapp.name}",
263
+ "alpine:3.6",
264
+ "rm", "-rf", tmp_path
265
+ ]
266
+ Image::Stage.ruby2go_command(dapp, command: :container_run, options: { args: args })
276
267
  end
277
268
 
278
269
  def stage_should_be_introspected_before_build?(name)
@@ -291,14 +282,6 @@ module Dapp
291
282
  !last_stage.image.tagged?
292
283
  end
293
284
  end
294
-
295
- def with_introspection
296
- yield
297
- rescue Exception::IntrospectImage => e
298
- data = e.net_status[:data]
299
- introspect_image!(image: data[:built_id], options: data[:options])
300
- raise data[:error]
301
- end
302
285
  end # Dimg
303
286
  end # Dimg
304
287
  end # Dapp
@@ -29,25 +29,10 @@ module Dapp
29
29
  [:realm, :service, :scope].map do |option|
30
30
  /#{option}="([[^"].]*)/ =~ header
31
31
  next unless Regexp.last_match(1)
32
-
33
- option_value = begin
34
- if option == :scope
35
- handle_scope_option(Regexp.last_match(1))
36
- else
37
- Regexp.last_match(1)
38
- end
39
- end
40
-
41
- [option, option_value]
32
+ [option, Regexp.last_match(1)]
42
33
  end.compact.to_h
43
34
  end
44
35
 
45
- def handle_scope_option(resourcescope)
46
- resource_type, resource_name, actions = resourcescope.split(":")
47
- actions = actions.split(",").map { |action| action == "delete" ? "*" : action }.join(",")
48
- [resource_type, resource_name, actions].join(":")
49
- end
50
-
51
36
  def authorization_auth
52
37
  @authorization_auth ||= begin
53
38
  if ::Dapp::Dapp.options_with_docker_credentials?
@@ -14,7 +14,7 @@ module Dapp
14
14
  # rubocop:disable Metrics/ParameterLists
15
15
  def initialize(repo, dimg, to:, name: nil, branch: nil, tag: nil, commit: nil,
16
16
  cwd: nil, include_paths: nil, exclude_paths: nil, owner: nil, group: nil, as: nil,
17
- stages_dependencies: {}, ignore_signature_auto_calculation: false)
17
+ stages_dependencies: {}, ignore_signature_auto_calculation: false, disable_go_git: nil)
18
18
  @repo = repo
19
19
  @dimg = dimg
20
20
  @name = name
@@ -34,6 +34,7 @@ module Dapp
34
34
  @as = as
35
35
 
36
36
  @stages_dependencies = stages_dependencies
37
+ @disable_go_git = disable_go_git unless disable_go_git.nil?
37
38
  end
38
39
  # rubocop:enable Metrics/ParameterLists
39
40
 
@@ -49,7 +50,7 @@ module Dapp
49
50
  end
50
51
 
51
52
  def submodule_artifact(submodule_params)
52
- embedded_artifact(submodule_params)
53
+ embedded_artifact(**submodule_params, disable_go_git: true)
53
54
  rescue Rugged::InvalidError => e
54
55
  raise Error::Rugged, code: :git_local_incorrect_gitmodules_params, data: { error: e.message }
55
56
  end
@@ -109,6 +110,7 @@ module Dapp
109
110
  options[:group] = group
110
111
 
111
112
  options[:ignore_signature_auto_calculation] = ignore_signature_auto_calculation
113
+ options[:disable_go_git] = embedded_params[:disable_go_git]
112
114
  end
113
115
  end
114
116
 
@@ -181,7 +183,37 @@ module Dapp
181
183
  end
182
184
  end
183
185
 
186
+ def disable_go_git?
187
+ return @disable_go_git unless @disable_go_git.nil?
188
+
189
+ @disable_go_git = (dev_mode? || !!ENV["DAPP_DISABLE_GO_GIT"] || begin
190
+ commit = dev_mode? ? nil : latest_commit
191
+ repo.submodules(
192
+ commit,
193
+ paths: include_paths_or_cwd,
194
+ exclude_paths: exclude_paths(true)
195
+ ).any?
196
+ end)
197
+ end
198
+
184
199
  def apply_archive_command(stage)
200
+ return apply_archive_command_old(stage) if disable_go_git?
201
+
202
+ res = repo.dapp.ruby2go_git_artifact(
203
+ "GitArtifact" => JSON.dump(get_ruby2go_state_hash),
204
+ "method" => "ApplyArchiveCommand",
205
+ "Stage" => JSON.dump(get_stub_stage_state(stage)),
206
+ )
207
+
208
+ raise res["error"] if res["error"]
209
+
210
+ self.set_ruby2go_state_hash(JSON.load(res["data"]["GitArtifact"]))
211
+ stage.set_ruby2go_state_hash(JSON.load(res["data"]["Stage"]))
212
+
213
+ res["data"]["result"]
214
+ end
215
+
216
+ def apply_archive_command_old(stage)
185
217
  [].tap do |commands|
186
218
  if archive_any_changes?(stage)
187
219
  case cwd_type(stage)
@@ -189,12 +221,12 @@ module Dapp
189
221
  stage.image.add_service_change_label(repo.dapp.dimgstage_g_a_type_label(paramshash).to_sym => 'directory')
190
222
 
191
223
  commands << "#{repo.dapp.install_bin} #{credentials.join(' ')} -d \"#{to}\""
192
- commands << "#{sudo}#{repo.dapp.tar_bin} -xf #{archive_file(stage)} -C \"#{to}\""
224
+ commands << "#{sudo} #{repo.dapp.tar_bin} -xf #{archive_file(stage)} -C \"#{to}\""
193
225
  when :file
194
226
  stage.image.add_service_change_label(repo.dapp.dimgstage_g_a_type_label(paramshash).to_sym => 'file')
195
227
 
196
228
  commands << "#{repo.dapp.install_bin} #{credentials.join(' ')} -d \"#{File.dirname(to)}\""
197
- commands << "#{sudo}#{repo.dapp.tar_bin} -xf #{archive_file(stage)} -C \"#{File.dirname(to)}\""
229
+ commands << "#{sudo} #{repo.dapp.tar_bin} -xf #{archive_file(stage)} -C \"#{File.dirname(to)}\""
198
230
  end
199
231
  end
200
232
  end
@@ -204,7 +236,36 @@ module Dapp
204
236
  stage.prev_stage.image.labels[repo.dapp.dimgstage_g_a_type_label(paramshash)].to_s.to_sym
205
237
  end
206
238
 
239
+ def get_stub_stage_state(stage)
240
+ stage.get_ruby2go_state_hash.tap do |stage_state|
241
+ # Data for StubStage specific for ApplyPatchCommand
242
+ stage_state["LayerCommitMap"] = {
243
+ paramshash => stage.layer_commit(self),
244
+ }
245
+ stage_state["PrevStage"]["LayerCommitMap" ] = {
246
+ paramshash => stage.prev_stage.layer_commit(self),
247
+ }
248
+ end
249
+ end
250
+
207
251
  def apply_patch_command(stage)
252
+ return apply_patch_command_old(stage) if disable_go_git?
253
+
254
+ res = repo.dapp.ruby2go_git_artifact(
255
+ "GitArtifact" => JSON.dump(get_ruby2go_state_hash),
256
+ "method" => "ApplyPatchCommand",
257
+ "Stage" => JSON.dump(get_stub_stage_state(stage)),
258
+ )
259
+
260
+ raise res["error"] if res["error"]
261
+
262
+ self.set_ruby2go_state_hash(JSON.load(res["data"]["GitArtifact"]))
263
+ stage.set_ruby2go_state_hash(JSON.load(res["data"]["Stage"]))
264
+
265
+ res["data"]["result"]
266
+ end
267
+
268
+ def apply_patch_command_old(stage)
208
269
  [].tap do |commands|
209
270
  if dev_mode?
210
271
  if any_changes?(*dev_patch_stage_commits(stage))
@@ -219,12 +280,12 @@ module Dapp
219
280
 
220
281
  commands << "#{repo.dapp.rm_bin} -rf $(#{repo.dapp.cat_bin} #{dimg.container_tmp_path('archives', files_to_remove_file_name)})"
221
282
  commands << "#{repo.dapp.install_bin} #{credentials.join(' ')} -d \"#{to}\""
222
- commands << "#{sudo}#{repo.dapp.tar_bin} -xf #{archive_file(stage)} -C \"#{to}\""
283
+ commands << "#{sudo} #{repo.dapp.tar_bin} -xf #{archive_file(stage)} -C \"#{to}\""
223
284
  commands << "#{repo.dapp.find_bin} \"#{to}\" -empty -type d -delete"
224
285
  when :file
225
286
  commands << "#{repo.dapp.rm_bin} -rf \"#{to}\""
226
287
  commands << "#{repo.dapp.install_bin} #{credentials.join(' ')} -d \"#{File.dirname(to)}\""
227
- commands << "#{sudo}#{repo.dapp.tar_bin} -xf #{archive_file(stage)} -C \"#{File.dirname(to)}\""
288
+ commands << "#{sudo} #{repo.dapp.tar_bin} -xf #{archive_file(stage)} -C \"#{File.dirname(to)}\""
228
289
  else
229
290
  raise
230
291
  end
@@ -234,10 +295,10 @@ module Dapp
234
295
  case archive_type(stage)
235
296
  when :directory
236
297
  commands << "#{repo.dapp.install_bin} #{credentials.join(' ')} -d \"#{to}\""
237
- commands << "#{sudo}#{repo.dapp.git_bin} apply --whitespace=nowarn --directory=\"#{to}\" --unsafe-paths #{patch_file(stage, *patch_stage_commits(stage))}"
298
+ commands << "#{sudo} #{repo.dapp.git_bin} apply --whitespace=nowarn --directory=\"#{to}\" --unsafe-paths #{patch_file(stage, *patch_stage_commits(stage))}"
238
299
  when :file
239
300
  commands << "#{repo.dapp.install_bin} #{credentials.join(' ')} -d \"#{File.dirname(to)}\""
240
- commands << "#{sudo}#{repo.dapp.git_bin} apply --whitespace=nowarn --directory=\"#{File.dirname(to)}\" --unsafe-paths #{patch_file(stage, *patch_stage_commits(stage))}"
301
+ commands << "#{sudo} #{repo.dapp.git_bin} apply --whitespace=nowarn --directory=\"#{File.dirname(to)}\" --unsafe-paths #{patch_file(stage, *patch_stage_commits(stage))}"
241
302
  else
242
303
  raise
243
304
  end
@@ -298,21 +359,81 @@ module Dapp
298
359
  end
299
360
  end
300
361
 
362
+ def get_ruby2go_state_hash
363
+ {
364
+ "Name" => @name.to_s,
365
+ "As" => @as.to_s,
366
+ "Branch" => @branch.to_s,
367
+ "Tag" => @tag.to_s,
368
+ "Commit" => @commit.to_s,
369
+ "To" => @to.to_s,
370
+ "Cwd" => @cwd.to_s,
371
+ "RepoPath" => File.join("/", @cwd.to_s),
372
+ "Owner" => @owner.to_s,
373
+ "Group" => @group.to_s,
374
+ "IncludePaths" => include_paths(true),
375
+ "ExcludePaths" => exclude_paths(true),
376
+ "StagesDependencies" => @stages_dependencies.map {|k, v| [_stages_map[k], Array(v).map(&:to_s)]}.to_h,
377
+ "Paramshash" => paramshash.to_s,
378
+ "PatchesDir" => dimg.tmp_path('patches'),
379
+ "ContainerPatchesDir" => dimg.container_tmp_path('patches'),
380
+ "ArchivesDir" => dimg.tmp_path('archives'),
381
+ "ContainerArchivesDir" => dimg.container_tmp_path('archives'),
382
+ }.tap {|res|
383
+ if repo.is_a? ::Dapp::Dimg::GitRepo::Local
384
+ res["LocalGitRepo"] = repo.get_ruby2go_state_hash
385
+ elsif repo.is_a? ::Dapp::Dimg::GitRepo::Remote
386
+ res["RemoteGitRepo"] = repo.get_ruby2go_state_hash
387
+ else
388
+ raise
389
+ end
390
+ }
391
+ end
392
+
393
+ def _stages_map
394
+ {
395
+ before_install: "beforeInstall",
396
+ install: "install",
397
+ before_setup: "beforeSetup",
398
+ setup: "setup",
399
+ build_artifact: "buildArtifact",
400
+ }
401
+ end
402
+
403
+ def _stages_map_reversed
404
+ _stages_map.map {|k, v| [v, k]}.to_h
405
+ end
406
+
407
+ def set_ruby2go_state_hash(new_state)
408
+ [
409
+ [:@name, new_state["Name"]],
410
+ [:@as, new_state["As"]],
411
+ [:@branch, new_state["Branch"]],
412
+ [:@tag, new_state["Tag"]],
413
+ [:@commit, new_state["Commit"]],
414
+ [:@cwd, new_state["Cwd"]],
415
+ [:@owner, new_state["Owner"]],
416
+ [:@group, new_state["Group"]],
417
+ ].each do |var, new_value|
418
+ if new_value != ""
419
+ instance_variable_set(var, new_value)
420
+ end
421
+ end
422
+
423
+ @stages_dependencies = new_state["StagesDependencies"].map do |k, v|
424
+ [_stages_map_reversed[k], v]
425
+ end.to_h
426
+ end
427
+
301
428
  def latest_commit
302
429
  @latest_commit ||= begin
303
- commit || begin
304
- if !tag.nil?
305
- repo.latest_tag_commit(tag)
306
- elsif !branch.nil?
307
- repo.latest_branch_commit(branch)
308
- else
309
- if local?
310
- repo.head_commit
311
- else
312
- repo.latest_branch_commit(repo.branch)
313
- end
314
- end
315
- end
430
+ res = repo.dapp.ruby2go_git_artifact("GitArtifact" => JSON.dump(get_ruby2go_state_hash), "method" => "LatestCommit")
431
+
432
+ raise res["error"] if res["error"]
433
+
434
+ self.set_ruby2go_state_hash(JSON.load(res["data"]["GitArtifact"]))
435
+
436
+ res["data"]["result"]
316
437
  end.tap do |c|
317
438
  repo.dapp.log_info("Repository `#{repo.name}`: latest commit `#{c}` to `#{to}`") unless ignore_signature_auto_calculation
318
439
  end