dapp 0.35.21 → 0.35.22
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.
- checksums.yaml +4 -4
- data/lib/dapp/dimg/build/stage/ga_latest_patch.rb +4 -2
- data/lib/dapp/dimg/dimg/git_artifact.rb +2 -12
- data/lib/dapp/dimg/git_artifact.rb +68 -564
- data/lib/dapp/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57be5b4eb14655fa5d40d393d3a4dd013eb96cd0d025770c3db2e3d5a4749bce
|
4
|
+
data.tar.gz: db9f0fe8f87c03c913da3dd8ca14083fab32face1752b810e88079a4bf22cd21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 575993cdd9d454b58d83295110ab47b130e791ef66905a78a0738429ee99ca131c769fa81a95491ec2926b2367d0499575c2daf341b6549e3754bada3698fb6f
|
7
|
+
data.tar.gz: f1ebdd957e12c5a62ab87532a14db8b7bd675a42272dfcaf3fb63d9b93a168ff04206823c8ee240ecee883585c536e6c037ef14e6ca93b4e08db67688bb55547
|
@@ -29,12 +29,14 @@ module Dapp
|
|
29
29
|
|
30
30
|
def commit_list
|
31
31
|
dimg.git_artifacts
|
32
|
-
.select { |ga| ga.repo.commit_exists?(prev_stage.layer_commit(ga)) && ga.
|
32
|
+
.select { |ga| ga.repo.commit_exists?(prev_stage.layer_commit(ga)) && !ga.is_patch_empty(self) }
|
33
33
|
.map(&method(:layer_commit))
|
34
34
|
end
|
35
35
|
|
36
36
|
def git_artifacts_dev_patch_hashes
|
37
|
-
|
37
|
+
# FIXME: dev-mode support in GitArtifact
|
38
|
+
# dimg.git_artifacts.map(&:dev_patch_hash)
|
39
|
+
nil
|
38
40
|
end
|
39
41
|
end # GALatestPatch
|
40
42
|
end # Stage
|
@@ -28,22 +28,12 @@ module Dapp
|
|
28
28
|
def generate_git_artifacts(repo, omit_empty: true, **git_artifact_options)
|
29
29
|
[].tap do |artifacts|
|
30
30
|
artifacts << (artifact = ::Dapp::Dimg::GitArtifact.new(repo, self, ignore_signature_auto_calculation: ignore_signature_auto_calculation, **git_artifact_options))
|
31
|
-
|
32
|
-
artifacts
|
33
|
-
else
|
34
|
-
artifacts.concat(generate_git_embedded_artifacts(artifact))
|
35
|
-
end
|
31
|
+
artifacts
|
36
32
|
end.select do |artifact|
|
37
|
-
!omit_empty || !artifact.
|
33
|
+
!omit_empty || !artifact.is_empty
|
38
34
|
end
|
39
35
|
end
|
40
36
|
|
41
|
-
def generate_git_embedded_artifacts(artifact)
|
42
|
-
[].tap do |artifacts|
|
43
|
-
artifacts.concat(submodules_artifacts = artifact.embedded_artifacts)
|
44
|
-
artifacts.concat(submodules_artifacts.map(&method(:generate_git_embedded_artifacts)).flatten)
|
45
|
-
end
|
46
|
-
end
|
47
37
|
end # GitArtifact
|
48
38
|
end # Mod
|
49
39
|
end # Dimg
|
@@ -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)
|
18
18
|
@repo = repo
|
19
19
|
@dimg = dimg
|
20
20
|
@name = name
|
@@ -34,175 +34,31 @@ 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?
|
38
|
-
end
|
39
|
-
# rubocop:enable Metrics/ParameterLists
|
40
|
-
|
41
|
-
def embedded_artifacts
|
42
|
-
[submodules_artifacts, nested_git_directory_artifacts].flatten
|
43
|
-
end
|
44
|
-
|
45
|
-
def submodules_artifacts
|
46
|
-
commit = dev_mode? ? nil : latest_commit
|
47
|
-
repo.submodules_params(commit,
|
48
|
-
paths: include_paths_or_cwd,
|
49
|
-
exclude_paths: exclude_paths(true)).map(&method(:submodule_artifact))
|
50
|
-
end
|
51
|
-
|
52
|
-
def submodule_artifact(submodule_params)
|
53
|
-
embedded_artifact(**submodule_params, disable_go_git: true)
|
54
|
-
rescue Rugged::InvalidError => e
|
55
|
-
raise Error::Rugged, code: :git_local_incorrect_gitmodules_params, data: { error: e.message }
|
56
|
-
end
|
57
|
-
|
58
|
-
def nested_git_directory_artifacts
|
59
|
-
return [] unless dev_mode?
|
60
|
-
repo
|
61
|
-
.nested_git_directories_patches(paths: include_paths_or_cwd, exclude_paths: exclude_paths(true), **diff_patches_options)
|
62
|
-
.map(&method(:nested_git_directory_artifact))
|
63
|
-
end
|
64
|
-
|
65
|
-
def nested_git_directory_artifact(patch)
|
66
|
-
params = {}.tap do |p|
|
67
|
-
p[:path] = patch.delta.new_file[:path]
|
68
|
-
p[:type] = :local
|
69
|
-
end
|
70
|
-
embedded_artifact(params)
|
71
|
-
end
|
72
37
|
|
73
|
-
def embedded_artifact(embedded_params)
|
74
|
-
embedded_rel_path = embedded_params[:path]
|
75
|
-
embedded_repo = begin
|
76
|
-
if embedded_params[:type] == :remote
|
77
|
-
GitRepo::Remote.get_or_create(repo.dapp, embedded_rel_path, url: embedded_params[:url])
|
78
|
-
elsif embedded_params[:type] == :local
|
79
|
-
embedded_path = File.join(repo.workdir_path, embedded_params[:path])
|
80
|
-
GitRepo::Local.new(repo.dapp, embedded_rel_path, embedded_path)
|
81
|
-
else
|
82
|
-
raise
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
self.class.new(embedded_repo, dimg, embedded_artifact_options(embedded_params))
|
87
|
-
end
|
88
|
-
|
89
|
-
def embedded_artifact_options(embedded_params)
|
90
|
-
embedded_rel_path = embedded_params[:path]
|
91
|
-
|
92
|
-
{}.tap do |options|
|
93
|
-
options[:name] = repo.dapp.consistent_uniq_slugify("embedded-#{embedded_rel_path}")
|
94
|
-
options[:cwd] = begin
|
95
|
-
subpath = Pathname(cwd).subpath_of(embedded_rel_path)
|
96
|
-
subpath = '' if subpath == '.'
|
97
|
-
subpath
|
98
|
-
end
|
99
|
-
options[:to] = Pathname(cwd).subpath_of?(embedded_rel_path) ? to : File.join(to, embedded_rel_path)
|
100
|
-
options[:include_paths] = embedded_inherit_paths(include_paths, embedded_rel_path)
|
101
|
-
options[:exclude_paths] = embedded_inherit_paths(exclude_paths, embedded_rel_path)
|
102
|
-
options[:stages_dependencies] = begin
|
103
|
-
stages_dependencies
|
104
|
-
.map { |stage, paths| [stage, embedded_inherit_paths(paths, embedded_rel_path)] }
|
105
|
-
.to_h
|
106
|
-
end
|
107
|
-
options[:branch] = embedded_params[:branch]
|
108
|
-
options[:commit] = embedded_params[:commit]
|
109
|
-
options[:owner] = owner
|
110
|
-
options[:group] = group
|
111
|
-
|
112
|
-
options[:ignore_signature_auto_calculation] = ignore_signature_auto_calculation
|
113
|
-
options[:disable_go_git] = embedded_params[:disable_go_git]
|
114
|
-
end
|
115
|
-
end
|
116
38
|
|
117
|
-
|
118
|
-
|
119
|
-
.select { |path| check_path?(embedded_rel_path, path) || check_subpath?(embedded_rel_path, path) }
|
120
|
-
.map { |path| embedded_inherit_path(path, embedded_rel_path) }
|
121
|
-
.flatten
|
122
|
-
.compact
|
39
|
+
@all_include_paths = base_paths(@include_paths, true)
|
40
|
+
@all_exclude_paths = repo.exclude_paths + base_paths(@exclude_paths, true)
|
123
41
|
end
|
42
|
+
# rubocop:enable Metrics/ParameterLists
|
124
43
|
|
125
|
-
def
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
until path_parts.empty?
|
131
|
-
current_path_part = path_parts.shift
|
132
|
-
test_path = [test_path, current_path_part].compact.join('/')
|
133
|
-
|
134
|
-
match = File.fnmatch(test_path, embedded_rel_path, File::FNM_PATHNAME|File::FNM_DOTMATCH)
|
135
|
-
break unless match || File.fnmatch(File.join(test_path, '**', '*'), embedded_rel_path, File::FNM_PATHNAME|File::FNM_DOTMATCH)
|
136
|
-
|
137
|
-
any = (current_path_part == '**')
|
138
|
-
|
139
|
-
if any
|
140
|
-
inherited_paths << [current_path_part, path_parts].flatten.join('/')
|
141
|
-
inherited_paths << path_parts.join('/') unless path_parts.empty?
|
142
|
-
elsif match && !path_parts.empty?
|
143
|
-
inherited_paths << path_parts.join('/')
|
144
|
-
break
|
145
|
-
elsif path_parts.empty?
|
146
|
-
inherited_paths << '**'
|
147
|
-
break
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
inherited_paths
|
152
|
-
end
|
153
|
-
|
154
|
-
def cwd_type(stage)
|
155
|
-
if dev_mode?
|
156
|
-
p = repo.workdir_path.join(cwd)
|
157
|
-
if p.exist?
|
158
|
-
if p.directory?
|
159
|
-
:directory
|
160
|
-
else
|
161
|
-
:file
|
162
|
-
end
|
163
|
-
end
|
164
|
-
elsif cwd == ''
|
165
|
-
:directory
|
166
|
-
else
|
167
|
-
cwd_type_by_commit(repo.lookup_commit(stage.layer_commit(self)))
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
def cwd_type_by_commit(commit)
|
172
|
-
cwd_entry = begin
|
173
|
-
commit.tree.path(cwd)
|
174
|
-
rescue Rugged::TreeError
|
175
|
-
end
|
176
|
-
|
177
|
-
if cwd_entry
|
178
|
-
if cwd_entry[:type] == :tree
|
179
|
-
:directory
|
44
|
+
def base_paths(paths, with_cwd = false)
|
45
|
+
[paths].flatten.compact.map do |path|
|
46
|
+
if with_cwd && !cwd.empty?
|
47
|
+
File.join(cwd, path)
|
180
48
|
else
|
181
|
-
|
49
|
+
path
|
182
50
|
end
|
51
|
+
.chomp('/')
|
52
|
+
.reverse.chomp('/')
|
53
|
+
.reverse
|
183
54
|
end
|
184
55
|
end
|
185
56
|
|
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
|
-
|
199
57
|
def apply_archive_command(stage)
|
200
|
-
return apply_archive_command_old(stage) if disable_go_git?
|
201
|
-
|
202
58
|
res = repo.dapp.ruby2go_git_artifact(
|
203
59
|
"GitArtifact" => JSON.dump(get_ruby2go_state_hash),
|
204
60
|
"method" => "ApplyArchiveCommand",
|
205
|
-
"Stage" => JSON.dump(
|
61
|
+
"Stage" => JSON.dump(merge_layer_commit_stub_stage_state(stage.get_ruby2go_state_hash, stage)),
|
206
62
|
)
|
207
63
|
|
208
64
|
raise res["error"] if res["error"]
|
@@ -213,48 +69,23 @@ module Dapp
|
|
213
69
|
Array(res["data"]["result"])
|
214
70
|
end
|
215
71
|
|
216
|
-
def
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
commands << "#{sudo} #{repo.dapp.tar_bin} -xf #{archive_file(stage)} -C \"#{to}\""
|
225
|
-
when :file
|
226
|
-
stage.image.add_service_change_label(repo.dapp.dimgstage_g_a_type_label(paramshash).to_sym => 'file')
|
227
|
-
|
228
|
-
commands << "#{repo.dapp.install_bin} #{credentials.join(' ')} -d \"#{File.dirname(to)}\""
|
229
|
-
commands << "#{sudo} #{repo.dapp.tar_bin} -xf #{archive_file(stage)} -C \"#{File.dirname(to)}\""
|
230
|
-
end
|
231
|
-
end
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
def archive_type(stage)
|
236
|
-
stage.prev_stage.image.labels[repo.dapp.dimgstage_g_a_type_label(paramshash)].to_s.to_sym
|
237
|
-
end
|
72
|
+
def merge_layer_commit_stub_stage_state(stage_state, stage)
|
73
|
+
# Data for StubStage specific for ApplyPatchCommand
|
74
|
+
stage_state["LayerCommitMap"] = {
|
75
|
+
paramshash => stage.layer_commit(self),
|
76
|
+
}
|
77
|
+
stage_state["PrevStage"]["LayerCommitMap" ] = {
|
78
|
+
paramshash => stage.prev_stage.layer_commit(self),
|
79
|
+
}
|
238
80
|
|
239
|
-
|
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
|
81
|
+
stage_state
|
249
82
|
end
|
250
83
|
|
251
84
|
def apply_patch_command(stage)
|
252
|
-
return apply_patch_command_old(stage) if disable_go_git?
|
253
|
-
|
254
85
|
res = repo.dapp.ruby2go_git_artifact(
|
255
86
|
"GitArtifact" => JSON.dump(get_ruby2go_state_hash),
|
256
87
|
"method" => "ApplyPatchCommand",
|
257
|
-
"Stage" => JSON.dump(
|
88
|
+
"Stage" => JSON.dump(merge_layer_commit_stub_stage_state(stage.get_ruby2go_state_hash, stage)),
|
258
89
|
)
|
259
90
|
|
260
91
|
raise res["error"] if res["error"]
|
@@ -265,48 +96,6 @@ module Dapp
|
|
265
96
|
Array(res["data"]["result"])
|
266
97
|
end
|
267
98
|
|
268
|
-
def apply_patch_command_old(stage)
|
269
|
-
[].tap do |commands|
|
270
|
-
if dev_mode?
|
271
|
-
if any_changes?(*dev_patch_stage_commits(stage))
|
272
|
-
case archive_type(stage)
|
273
|
-
when :directory
|
274
|
-
files_to_remove_file_name = file_name('dev_files_to_remove')
|
275
|
-
File.open(dimg.tmp_path('archives', files_to_remove_file_name), File::RDWR | File::CREAT) do |f|
|
276
|
-
diff_patches(*dev_patch_stage_commits(stage))
|
277
|
-
.map {|p| File.join(to, cwd, p.delta.new_file[:path])}
|
278
|
-
.each(&f.method(:puts))
|
279
|
-
end
|
280
|
-
|
281
|
-
commands << "#{repo.dapp.rm_bin} -rf $(#{repo.dapp.cat_bin} #{dimg.container_tmp_path('archives', files_to_remove_file_name)})"
|
282
|
-
commands << "#{repo.dapp.install_bin} #{credentials.join(' ')} -d \"#{to}\""
|
283
|
-
commands << "#{sudo} #{repo.dapp.tar_bin} -xf #{archive_file(stage)} -C \"#{to}\""
|
284
|
-
commands << "#{repo.dapp.find_bin} \"#{to}\" -empty -type d -delete"
|
285
|
-
when :file
|
286
|
-
commands << "#{repo.dapp.rm_bin} -rf \"#{to}\""
|
287
|
-
commands << "#{repo.dapp.install_bin} #{credentials.join(' ')} -d \"#{File.dirname(to)}\""
|
288
|
-
commands << "#{sudo} #{repo.dapp.tar_bin} -xf #{archive_file(stage)} -C \"#{File.dirname(to)}\""
|
289
|
-
else
|
290
|
-
raise
|
291
|
-
end
|
292
|
-
end
|
293
|
-
else
|
294
|
-
if patch_any_changes?(stage)
|
295
|
-
case archive_type(stage)
|
296
|
-
when :directory
|
297
|
-
commands << "#{repo.dapp.install_bin} #{credentials.join(' ')} -d \"#{to}\""
|
298
|
-
commands << "#{sudo} #{repo.dapp.git_bin} apply --whitespace=nowarn --directory=\"#{to}\" --unsafe-paths #{patch_file(stage, *patch_stage_commits(stage))}"
|
299
|
-
when :file
|
300
|
-
commands << "#{repo.dapp.install_bin} #{credentials.join(' ')} -d \"#{File.dirname(to)}\""
|
301
|
-
commands << "#{sudo} #{repo.dapp.git_bin} apply --whitespace=nowarn --directory=\"#{File.dirname(to)}\" --unsafe-paths #{patch_file(stage, *patch_stage_commits(stage))}"
|
302
|
-
else
|
303
|
-
raise
|
304
|
-
end
|
305
|
-
end
|
306
|
-
end
|
307
|
-
end
|
308
|
-
end
|
309
|
-
|
310
99
|
def calculate_stage_dependencies_checksum(stage)
|
311
100
|
res = repo.dapp.ruby2go_git_artifact(
|
312
101
|
"GitArtifact" => JSON.dump(get_ruby2go_state_hash),
|
@@ -324,46 +113,11 @@ module Dapp
|
|
324
113
|
end
|
325
114
|
|
326
115
|
def stage_dependencies_checksum(stage)
|
327
|
-
return stage_dependencies_checksum_old(stage) if dev_mode?
|
328
116
|
stage_dependencies_key = [stage.name, commit]
|
329
117
|
@stage_dependencies_checksums ||= {}
|
330
118
|
@stage_dependencies_checksums[stage_dependencies_key] ||= calculate_stage_dependencies_checksum(stage)
|
331
119
|
end
|
332
120
|
|
333
|
-
def stage_dependencies_checksum_old(stage)
|
334
|
-
return [] if (stage_dependencies = stages_dependencies[stage.name]).empty?
|
335
|
-
|
336
|
-
paths = base_paths(stage_dependencies, true)
|
337
|
-
commit = dev_mode? ? nil : latest_commit
|
338
|
-
|
339
|
-
stage_dependencies_key = [stage.name, commit]
|
340
|
-
|
341
|
-
@stage_dependencies_warning ||= {}
|
342
|
-
@stage_dependencies_checksums ||= {}
|
343
|
-
@stage_dependencies_checksums[stage_dependencies_key] ||= begin
|
344
|
-
if dev_mode?
|
345
|
-
dev_patch_hash(paths: paths)
|
346
|
-
else
|
347
|
-
if (entries = repo_entries(commit, paths: paths)).empty? && @stage_dependencies_warning[stage.name].nil?
|
348
|
-
@stage_dependencies_warning[stage.name] = true
|
349
|
-
code = cwd_type_by_commit(repo.lookup_commit(commit)) == :file ? :stage_dependencies_file_not_found : :stage_dependencies_not_found
|
350
|
-
repo.dapp.log_warning(desc: { code: code,
|
351
|
-
data: { repo: repo.respond_to?(:url) ? repo.url : 'local',
|
352
|
-
dependencies: stage_dependencies.join(', ') } })
|
353
|
-
end
|
354
|
-
|
355
|
-
entries
|
356
|
-
.sort_by {|root, entry| File.join(root, entry[:name])}
|
357
|
-
.reduce(nil) {|prev_hash, (root, entry)|
|
358
|
-
content = nil
|
359
|
-
content = repo.lookup_object(entry[:oid]).content if entry[:type] == :blob
|
360
|
-
|
361
|
-
hexdigest prev_hash, File.join(root, entry[:name]), entry[:filemode].to_s, content
|
362
|
-
}
|
363
|
-
end
|
364
|
-
end
|
365
|
-
end
|
366
|
-
|
367
121
|
def patch_size(from_commit)
|
368
122
|
res = repo.dapp.ruby2go_git_artifact(
|
369
123
|
"GitArtifact" => JSON.dump(get_ruby2go_state_hash),
|
@@ -378,24 +132,6 @@ module Dapp
|
|
378
132
|
res["data"]["result"]
|
379
133
|
end
|
380
134
|
|
381
|
-
def patch_size_old(from_commit)
|
382
|
-
to_commit = dev_mode? ? nil : latest_commit
|
383
|
-
diff_patches(from_commit, to_commit).reduce(0) do |bytes, patch|
|
384
|
-
bytes += patch.delta.deleted? ? patch.delta.old_file[:size] : patch.delta.new_file[:size]
|
385
|
-
bytes
|
386
|
-
end
|
387
|
-
end
|
388
|
-
|
389
|
-
def dev_patch_hash(**options)
|
390
|
-
return unless dev_mode?
|
391
|
-
hexdigest begin
|
392
|
-
diff_patches(nil, nil, **options).map do |patch|
|
393
|
-
file = patch.delta.new_file
|
394
|
-
[file[:path], File.read(File.join(repo.workdir_path, file[:path])), file[:mode]]
|
395
|
-
end
|
396
|
-
end
|
397
|
-
end
|
398
|
-
|
399
135
|
def get_ruby2go_state_hash
|
400
136
|
{
|
401
137
|
"Name" => @name.to_s,
|
@@ -408,10 +144,9 @@ module Dapp
|
|
408
144
|
"RepoPath" => File.join("/", @cwd.to_s),
|
409
145
|
"Owner" => @owner.to_s,
|
410
146
|
"Group" => @group.to_s,
|
411
|
-
"IncludePaths" =>
|
412
|
-
"ExcludePaths" =>
|
147
|
+
"IncludePaths" => @all_include_paths,
|
148
|
+
"ExcludePaths" => @all_exclude_paths,
|
413
149
|
"StagesDependencies" => @stages_dependencies.map {|k, v| [_stages_map[k], Array(v).map(&:to_s)]}.to_h,
|
414
|
-
"Paramshash" => paramshash.to_s,
|
415
150
|
"PatchesDir" => dimg.tmp_path('patches'),
|
416
151
|
"ContainerPatchesDir" => dimg.container_tmp_path('patches'),
|
417
152
|
"ArchivesDir" => dimg.tmp_path('archives'),
|
@@ -477,307 +212,76 @@ module Dapp
|
|
477
212
|
end
|
478
213
|
|
479
214
|
def paramshash
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
def full_name
|
484
|
-
"#{repo.name}#{name ? "_#{name}" : nil}"
|
485
|
-
end
|
486
|
-
|
487
|
-
def archive_any_changes?(stage)
|
488
|
-
repo_entries(stage_commit(stage)).any?
|
489
|
-
end
|
490
|
-
|
491
|
-
def patch_any_changes?(stage)
|
492
|
-
any_changes?(*patch_stage_commits(stage))
|
493
|
-
end
|
494
|
-
|
495
|
-
def empty?
|
496
|
-
repo_entries(latest_commit).empty?
|
497
|
-
end
|
498
|
-
|
499
|
-
protected
|
500
|
-
|
501
|
-
def hexdigest(*args)
|
502
|
-
Digest::SHA256.hexdigest args.compact.map {|arg| arg.to_s.force_encoding("ASCII-8BIT")}.join(":::")
|
503
|
-
end
|
504
|
-
|
505
|
-
attr_reader :dimg
|
506
|
-
attr_reader :to
|
507
|
-
attr_reader :commit
|
508
|
-
attr_reader :branch
|
509
|
-
attr_reader :tag
|
510
|
-
attr_reader :cwd
|
511
|
-
attr_reader :owner
|
512
|
-
attr_reader :group
|
513
|
-
attr_reader :stages_dependencies
|
514
|
-
attr_reader :ignore_signature_auto_calculation
|
515
|
-
|
516
|
-
def sudo
|
517
|
-
repo.dapp.sudo_command(owner: owner, group: group)
|
518
|
-
end
|
519
|
-
|
520
|
-
def credentials
|
521
|
-
[:owner, :group].map { |attr| "--#{attr}=#{send(attr)}" unless send(attr).nil? }.compact
|
522
|
-
end
|
523
|
-
|
524
|
-
def archive_file(stage)
|
525
|
-
commit = stage_commit(stage)
|
526
|
-
if repo.dapp.options[:use_system_tar]
|
527
|
-
archive_file_with_system_tar(stage, commit)
|
528
|
-
else
|
529
|
-
archive_file_with_tar_writer(stage, commit)
|
530
|
-
end
|
531
|
-
dimg.container_tmp_path('archives', archive_file_name(commit))
|
532
|
-
end
|
533
|
-
|
534
|
-
def archive_file_with_tar_writer(stage, commit)
|
535
|
-
tar_write(dimg.tmp_path('archives', archive_file_name(commit))) do |tar|
|
536
|
-
each_archive_entry(stage, commit) do |path, content, mode|
|
537
|
-
relative_path = path.reverse.chomp('/').reverse
|
538
|
-
if mode == 0o120000 # symlink
|
539
|
-
tar.add_symlink relative_path, content, mode
|
540
|
-
else
|
541
|
-
tar.add_file relative_path, mode do |tf|
|
542
|
-
tf.write content
|
543
|
-
end
|
544
|
-
end
|
545
|
-
end
|
546
|
-
end
|
547
|
-
rescue Gem::Package::TooLongFileName => e
|
548
|
-
raise Error::TarWriter, message: e.message
|
549
|
-
end
|
550
|
-
|
551
|
-
def archive_file_with_system_tar(stage, commit)
|
552
|
-
dimg.tmp_path('archives', archive_file_name(commit)).tap do |archive_path|
|
553
|
-
relative_archive_file_path = File.join('archives_files', file_name(commit))
|
554
|
-
each_archive_entry(stage, commit) do |path, content, mode|
|
555
|
-
file_path = dimg.tmp_path(relative_archive_file_path, path)
|
556
|
-
|
557
|
-
if mode == 0o120000 # symlink
|
558
|
-
FileUtils.symlink(content, file_path)
|
559
|
-
else
|
560
|
-
IO.write(file_path, content)
|
561
|
-
FileUtils.chmod(mode, file_path)
|
562
|
-
end
|
563
|
-
end
|
564
|
-
|
565
|
-
repo.dapp.shellout!("tar -C #{dimg.tmp_path(relative_archive_file_path)} -cf #{archive_path} .")
|
566
|
-
end
|
567
|
-
end
|
215
|
+
@paramshash ||= begin
|
216
|
+
res = repo.dapp.ruby2go_git_artifact("GitArtifact" => JSON.dump(get_ruby2go_state_hash), "method" => "GetParamshash")
|
568
217
|
|
569
|
-
|
570
|
-
return path if cwd.empty?
|
571
|
-
|
572
|
-
case cwd_type(stage)
|
573
|
-
when :directory
|
574
|
-
path
|
575
|
-
.reverse
|
576
|
-
.chomp(cwd.reverse)
|
577
|
-
.chomp('/')
|
578
|
-
.reverse
|
579
|
-
when :file
|
580
|
-
File.basename(to)
|
581
|
-
else
|
582
|
-
raise
|
583
|
-
end
|
584
|
-
end
|
218
|
+
raise res["error"] if res["error"]
|
585
219
|
|
586
|
-
|
587
|
-
file_name(commit, ext: 'tar')
|
588
|
-
end
|
220
|
+
self.set_ruby2go_state_hash(JSON.load(res["data"]["GitArtifact"]))
|
589
221
|
|
590
|
-
|
591
|
-
File.open(dimg.tmp_path('patches', patch_file_name(from_commit, to_commit)), File::RDWR | File::CREAT) do |f|
|
592
|
-
diff_patches(from_commit, to_commit).each { |patch| f.write change_patch_new_file_path(stage, patch) }
|
222
|
+
res["data"]["result"]
|
593
223
|
end
|
594
|
-
dimg.container_tmp_path('patches', patch_file_name(from_commit, to_commit))
|
595
224
|
end
|
596
225
|
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
prepare_native_path = proc do |path_with_cwd|
|
601
|
-
case archive_type(stage)
|
602
|
-
when :directory
|
603
|
-
path_with_cwd.sub(cwd, '')
|
604
|
-
when :file
|
605
|
-
File.basename(to)
|
606
|
-
else
|
607
|
-
raise
|
608
|
-
end
|
609
|
-
end
|
610
|
-
|
611
|
-
modify_patch_line = proc do |line_number, path_char|
|
612
|
-
action_part, path_part = lines[line_number].strip.split(' ', 2)
|
613
|
-
if (path_with_cwd = path_part.partition("#{path_char}/").last).start_with?(cwd)
|
614
|
-
prepare_native_path.call(path_with_cwd).tap do |native_path|
|
615
|
-
if native_path
|
616
|
-
expected_path = File.join(path_char, native_path)
|
617
|
-
lines[line_number] = [action_part, expected_path].join(' ') + "\n"
|
618
|
-
end
|
619
|
-
end
|
620
|
-
end
|
621
|
-
end
|
622
|
-
|
623
|
-
modify_patch_first_line = proc do
|
624
|
-
old_file_path = prepare_native_path.call(patch.delta.old_file[:path])
|
625
|
-
new_file_path = prepare_native_path.call(patch.delta.new_file[:path])
|
626
|
-
lines[0] = ['diff --git', File.join('a', old_file_path), File.join('b', new_file_path)].join(' ') + "\n"
|
627
|
-
end
|
628
|
-
|
629
|
-
modify_patch = proc do |*modify_patch_line_args|
|
630
|
-
native_paths = modify_patch_line_args.map { |args| modify_patch_line.call(*args) }
|
631
|
-
unless (native_paths = native_paths.compact.uniq).empty?
|
632
|
-
raise Error::Build, code: :unsupported_patch_format, data: { patch: patch.to_s } unless native_paths.one?
|
633
|
-
modify_patch_first_line.call
|
634
|
-
end
|
635
|
-
end
|
636
|
-
|
637
|
-
case
|
638
|
-
when patch.delta.deleted? then modify_patch.call([3, 'a'])
|
639
|
-
when patch.delta.added? then modify_patch.call([4, 'b'])
|
640
|
-
when patch.delta.modified?
|
641
|
-
if patch_file_mode_changed?(patch)
|
642
|
-
if patch.changes.zero?
|
643
|
-
modify_patch_first_line.call
|
644
|
-
else
|
645
|
-
modify_patch.call([4, 'a'], [5, 'b'])
|
646
|
-
end
|
647
|
-
else
|
648
|
-
modify_patch.call([2, 'a'], [3, 'b'])
|
649
|
-
end
|
650
|
-
else
|
651
|
-
raise
|
652
|
-
end
|
653
|
-
end.join
|
654
|
-
end
|
655
|
-
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
656
|
-
|
657
|
-
def patch_file_mode_changed?(patch)
|
658
|
-
patch.delta.old_file[:mode] != patch.delta.new_file[:mode]
|
659
|
-
end
|
226
|
+
def full_name
|
227
|
+
@full_name ||= begin
|
228
|
+
res = repo.dapp.ruby2go_git_artifact("GitArtifact" => JSON.dump(get_ruby2go_state_hash), "method" => "FullName")
|
660
229
|
|
661
|
-
|
662
|
-
file_name(from_commit, to_commit, ext: 'patch')
|
663
|
-
end
|
230
|
+
raise res["error"] if res["error"]
|
664
231
|
|
665
|
-
|
666
|
-
"#{[paramshash, args].flatten.compact.join('_')}#{".#{ext}" unless ext.nil? }"
|
667
|
-
end
|
232
|
+
self.set_ruby2go_state_hash(JSON.load(res["data"]["GitArtifact"]))
|
668
233
|
|
669
|
-
|
670
|
-
(@repo_entries ||= {})[[commit, paths]] ||= begin
|
671
|
-
repo
|
672
|
-
.blobs_entries(commit, paths: paths, exclude_paths: exclude_paths(true))
|
673
|
-
.select { |_, entry| !submodule_mode?(entry[:filemode]) }
|
234
|
+
res["data"]["result"]
|
674
235
|
end
|
675
236
|
end
|
676
237
|
|
677
|
-
def
|
678
|
-
|
679
|
-
diff_patches(commit, nil).each do |patch|
|
680
|
-
file = patch.delta.new_file
|
681
|
-
host_file_path = File.join(repo.workdir_path, file[:path])
|
682
|
-
next unless File.exist?(host_file_path)
|
238
|
+
def is_patch_empty(stage)
|
239
|
+
return @is_patch_empty if !@is_patch_empty.nil?
|
683
240
|
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
241
|
+
@is_patch_empty = begin
|
242
|
+
res = repo.dapp.ruby2go_git_artifact(
|
243
|
+
"GitArtifact" => JSON.dump(get_ruby2go_state_hash),
|
244
|
+
"method" => "IsPatchEmpty",
|
245
|
+
"Stage" => JSON.dump(merge_layer_commit_stub_stage_state({"PrevStage" => {}}, stage)),
|
246
|
+
)
|
690
247
|
|
691
|
-
|
692
|
-
content = repo.lookup_object(entry[:oid]).content
|
693
|
-
yield slice_cwd(stage, entry_file_path), content, entry[:filemode]
|
694
|
-
end
|
695
|
-
end
|
696
|
-
end
|
248
|
+
raise res["error"] if res["error"]
|
697
249
|
|
698
|
-
|
699
|
-
(@diff_patches ||= {})[[from_commit, to_commit, paths]] ||= begin
|
700
|
-
repo
|
701
|
-
.patches(from_commit, to_commit, paths: paths, exclude_paths: exclude_paths(true), **diff_patches_options)
|
702
|
-
.select do |patch|
|
703
|
-
file_mode = patch.delta.status == :deleted ? patch.delta.old_file[:mode] : patch.delta.new_file[:mode]
|
704
|
-
!(submodule_mode?(file_mode) || # FIXME: https://github.com/libgit2/rugged/issues/727
|
705
|
-
nested_git_directory_mode?(file_mode))
|
706
|
-
end
|
707
|
-
end
|
708
|
-
end
|
250
|
+
self.set_ruby2go_state_hash(JSON.load(res["data"]["GitArtifact"]))
|
709
251
|
|
710
|
-
|
711
|
-
{}.tap do |opts|
|
712
|
-
opts[:force_text] = true
|
713
|
-
if dev_mode?
|
714
|
-
opts[:include_untracked] = true
|
715
|
-
opts[:recurse_untracked_dirs] = true
|
716
|
-
end
|
252
|
+
res["data"]["result"]
|
717
253
|
end
|
718
254
|
end
|
719
255
|
|
720
|
-
def
|
721
|
-
|
722
|
-
end
|
256
|
+
def is_empty
|
257
|
+
return @is_empty if !@is_empty.nil?
|
723
258
|
|
724
|
-
|
725
|
-
|
726
|
-
|
259
|
+
@is_empty = begin
|
260
|
+
res = repo.dapp.ruby2go_git_artifact(
|
261
|
+
"GitArtifact" => JSON.dump(get_ruby2go_state_hash),
|
262
|
+
"method" => "IsEmpty",
|
263
|
+
)
|
727
264
|
|
728
|
-
|
729
|
-
case
|
730
|
-
when !include_paths(true).empty? then include_paths(true)
|
731
|
-
when !cwd.empty? then [cwd]
|
732
|
-
else
|
733
|
-
[]
|
734
|
-
end
|
735
|
-
end
|
736
|
-
|
737
|
-
def exclude_paths(with_cwd = false)
|
738
|
-
repo.exclude_paths + base_paths(@exclude_paths, with_cwd)
|
739
|
-
end
|
265
|
+
raise res["error"] if res["error"]
|
740
266
|
|
741
|
-
|
742
|
-
base_paths(@include_paths, with_cwd)
|
743
|
-
end
|
267
|
+
self.set_ruby2go_state_hash(JSON.load(res["data"]["GitArtifact"]))
|
744
268
|
|
745
|
-
|
746
|
-
[paths].flatten.compact.map do |path|
|
747
|
-
if with_cwd && !cwd.empty?
|
748
|
-
File.join(cwd, path)
|
749
|
-
else
|
750
|
-
path
|
751
|
-
end
|
752
|
-
.chomp('/')
|
753
|
-
.reverse.chomp('/')
|
754
|
-
.reverse
|
269
|
+
res["data"]["result"]
|
755
270
|
end
|
756
271
|
end
|
757
272
|
|
758
|
-
|
759
|
-
stage.layer_commit(self)
|
760
|
-
end
|
761
|
-
|
762
|
-
def patch_stage_commits(stage)
|
763
|
-
[stage.prev_stage.layer_commit(self), stage.layer_commit(self)]
|
764
|
-
end
|
765
|
-
|
766
|
-
def dev_patch_stage_commits(stage)
|
767
|
-
[stage.prev_stage.layer_commit(self), nil]
|
768
|
-
end
|
769
|
-
|
770
|
-
def any_changes?(from_commit, to_commit)
|
771
|
-
diff_patches(from_commit, to_commit).any?
|
772
|
-
end
|
773
|
-
|
774
|
-
def dev_mode?
|
775
|
-
local? && dimg.dev_mode?
|
776
|
-
end
|
273
|
+
protected
|
777
274
|
|
778
|
-
|
779
|
-
|
780
|
-
|
275
|
+
attr_reader :dimg
|
276
|
+
attr_reader :to
|
277
|
+
attr_reader :commit
|
278
|
+
attr_reader :branch
|
279
|
+
attr_reader :tag
|
280
|
+
attr_reader :cwd
|
281
|
+
attr_reader :owner
|
282
|
+
attr_reader :group
|
283
|
+
attr_reader :stages_dependencies
|
284
|
+
attr_reader :ignore_signature_auto_calculation
|
781
285
|
end
|
782
286
|
end
|
783
287
|
end
|
data/lib/dapp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dapp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.35.
|
4
|
+
version: 0.35.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Stolyarov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mixlib-shellout
|