dapp 0.14.31 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/dapp +0 -4
- data/lib/dapp.rb +0 -4
- data/lib/dapp/cli.rb +0 -4
- data/lib/dapp/cli/command/base.rb +1 -8
- data/lib/dapp/dapp.rb +4 -26
- data/lib/dapp/dimg/cli/command/base.rb +4 -0
- data/lib/dapp/dimg/config/directive/git_artifact_remote.rb +1 -3
- data/lib/dapp/dimg/git_artifact.rb +55 -51
- data/lib/dapp/dimg/git_repo/base.rb +31 -1
- data/lib/dapp/kube/dapp/command/deploy.rb +1 -8
- data/lib/dapp/version.rb +2 -2
- metadata +3 -33
- data/lib/dapp/dapp/sentry.rb +0 -112
- data/lib/dapp/helper/url.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42f6d6fce7254c75aa1746062ff9490bb38aaa34
|
4
|
+
data.tar.gz: 644155d4d9e2788eb5e0563e26a84b9dcf35b73e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3db6d327a4f8b90d26674653df5f5c6c1f9733fad3152bee49d228daf452900ccfa823159aa040f123b381560ceb7db2b43fc5618d272cb00680bc6865d3a4d7
|
7
|
+
data.tar.gz: 5d0229d66b4643e90cf6531b3326161b5fe2c103875ccba9acc132b66e6a2cd3fecceec5f2bd96a508518694a8df7b0570cbfe586c9b9fc257fb4a1d352f9d77
|
data/bin/dapp
CHANGED
data/lib/dapp.rb
CHANGED
@@ -24,8 +24,6 @@ require 'openssl'
|
|
24
24
|
require 'etc'
|
25
25
|
require 'zlib'
|
26
26
|
require 'slugify'
|
27
|
-
require 'sentry-raven'
|
28
|
-
require 'toml-rb'
|
29
27
|
|
30
28
|
require 'dapp/version'
|
31
29
|
require 'dapp/core_ext/hash'
|
@@ -36,7 +34,6 @@ require 'dapp/helper/sha256'
|
|
36
34
|
require 'dapp/helper/net_status'
|
37
35
|
require 'dapp/helper/tar'
|
38
36
|
require 'dapp/helper/yaml'
|
39
|
-
require 'dapp/helper/url'
|
40
37
|
require 'dapp/prctl'
|
41
38
|
require 'dapp/error/base'
|
42
39
|
require 'dapp/error/dapp'
|
@@ -52,7 +49,6 @@ require 'dapp/config/config'
|
|
52
49
|
require 'dapp/config/error/config'
|
53
50
|
require 'dapp/dapp/lock'
|
54
51
|
require 'dapp/dapp/ssh_agent'
|
55
|
-
require 'dapp/dapp/sentry'
|
56
52
|
require 'dapp/dapp/git_artifact'
|
57
53
|
require 'dapp/dapp/dappfile'
|
58
54
|
require 'dapp/dapp/chef'
|
data/lib/dapp/cli.rb
CHANGED
@@ -58,9 +58,6 @@ module Dapp
|
|
58
58
|
|
59
59
|
def run_dapp_command(run_method, *args)
|
60
60
|
dapp = ::Dapp::Dapp.new(*args)
|
61
|
-
::Dapp::CLI.dapp_object = dapp
|
62
|
-
dapp.sentry_message("Manual usage: `#{self.run_method}` command") unless ENV['CI']
|
63
|
-
|
64
61
|
begin
|
65
62
|
if block_given?
|
66
63
|
yield dapp
|
@@ -70,16 +67,12 @@ module Dapp
|
|
70
67
|
end
|
71
68
|
end
|
72
69
|
|
73
|
-
def run_method
|
74
|
-
class_to_lowercase
|
75
|
-
end
|
76
|
-
|
77
70
|
def run(_argv = ARGV)
|
78
71
|
raise
|
79
72
|
end
|
80
73
|
|
81
74
|
def cli_options(**kwargs)
|
82
|
-
config.merge(
|
75
|
+
config.merge(**kwargs)
|
83
76
|
end
|
84
77
|
end
|
85
78
|
end
|
data/lib/dapp/dapp.rb
CHANGED
@@ -12,13 +12,10 @@ module Dapp
|
|
12
12
|
include Logging::Paint
|
13
13
|
|
14
14
|
include SshAgent
|
15
|
-
include Sentry
|
16
|
-
|
17
15
|
include Helper::Sha256
|
18
|
-
extend
|
16
|
+
extend Helper::Trivia
|
19
17
|
include Helper::Trivia
|
20
18
|
include Helper::Tar
|
21
|
-
include Helper::Url
|
22
19
|
|
23
20
|
include Deps::Gitartifact
|
24
21
|
include Deps::Base
|
@@ -38,18 +35,6 @@ module Dapp
|
|
38
35
|
self.class.options
|
39
36
|
end
|
40
37
|
|
41
|
-
def settings
|
42
|
-
@settings ||= begin
|
43
|
-
settings_path = File.join(self.class.home_dir, "settings.toml")
|
44
|
-
|
45
|
-
if File.exists? settings_path
|
46
|
-
TomlRB.load_file(settings_path)
|
47
|
-
else
|
48
|
-
{}
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
38
|
def name
|
54
39
|
@name ||= begin
|
55
40
|
if git_url
|
@@ -90,18 +75,15 @@ module Dapp
|
|
90
75
|
self.class.tmp_base_dir
|
91
76
|
end
|
92
77
|
|
93
|
-
def
|
94
|
-
@
|
78
|
+
def build_path(*path)
|
79
|
+
@build_path ||= begin
|
95
80
|
if option_build_dir
|
96
81
|
Pathname.new(option_build_dir)
|
97
82
|
else
|
98
83
|
path('.dapp_build')
|
99
84
|
end.expand_path.tap(&:mkpath)
|
100
85
|
end
|
101
|
-
|
102
|
-
|
103
|
-
def build_path(*path)
|
104
|
-
make_path(build_dir, *path)
|
86
|
+
make_path(@build_path, *path)
|
105
87
|
end
|
106
88
|
|
107
89
|
def local_git_artifact_exclude_paths(&blk)
|
@@ -147,10 +129,6 @@ module Dapp
|
|
147
129
|
end
|
148
130
|
|
149
131
|
class << self
|
150
|
-
def home_dir
|
151
|
-
File.join(Dir.home, ".dapp")
|
152
|
-
end
|
153
|
-
|
154
132
|
def options
|
155
133
|
@options ||= {}
|
156
134
|
end
|
@@ -3,13 +3,11 @@ module Dapp
|
|
3
3
|
module Config
|
4
4
|
module Directive
|
5
5
|
class GitArtifactRemote < GitArtifactLocal
|
6
|
-
include ::Dapp::Helper::Url
|
7
|
-
|
8
6
|
attr_reader :_url, :_name, :_branch, :_commit
|
9
7
|
|
10
8
|
def initialize(url, **kwargs, &blk)
|
11
9
|
@_url = url
|
12
|
-
@_name =
|
10
|
+
@_name = url.gsub(%r{.*?([^\/ ]+)\.git}, '\\1')
|
13
11
|
|
14
12
|
super(**kwargs, &blk)
|
15
13
|
end
|
@@ -68,12 +68,12 @@ module Dapp
|
|
68
68
|
stage.image.add_service_change_label :"dapp-git-#{paramshash}-type" => 'directory'
|
69
69
|
|
70
70
|
commands << "#{repo.dimg.dapp.install_bin} #{credentials.join(' ')} -d \"#{to}\""
|
71
|
-
commands << "#{sudo}#{repo.dimg.dapp.tar_bin} -xf #{archive_file(stage, *
|
71
|
+
commands << "#{sudo}#{repo.dimg.dapp.tar_bin} -xf #{archive_file(stage, *archive_stage_commit(stage))} -C \"#{to}\""
|
72
72
|
when :file
|
73
73
|
stage.image.add_service_change_label :"dapp-git-#{paramshash}-type" => 'file'
|
74
74
|
|
75
75
|
commands << "#{repo.dimg.dapp.install_bin} #{credentials.join(' ')} -d \"#{File.dirname(to)}\""
|
76
|
-
commands << "#{sudo}#{repo.dimg.dapp.tar_bin} -xf #{archive_file(stage, *
|
76
|
+
commands << "#{sudo}#{repo.dimg.dapp.tar_bin} -xf #{archive_file(stage, *archive_stage_commit(stage))} -C \"#{File.dirname(to)}\""
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
@@ -121,30 +121,34 @@ module Dapp
|
|
121
121
|
def stage_dependencies_checksum(stage)
|
122
122
|
return [] if (stage_dependencies = stages_dependencies[stage.name]).empty?
|
123
123
|
|
124
|
-
paths =
|
125
|
-
|
124
|
+
paths = base_paths(stage_dependencies, true)
|
125
|
+
commit = dev_mode? ? nil : latest_commit
|
126
126
|
|
127
|
-
stage_dependencies_key = [stage.name,
|
127
|
+
stage_dependencies_key = [stage.name, commit]
|
128
128
|
@stage_dependencies_checksums ||= {}
|
129
129
|
@stage_dependencies_checksums[stage_dependencies_key] = begin
|
130
130
|
if @stage_dependencies_checksums.key?(stage_dependencies_key)
|
131
131
|
@stage_dependencies_checksums[stage_dependencies_key]
|
132
132
|
else
|
133
|
-
if (
|
133
|
+
if (entries = repo_entries(commit, paths: paths)).empty?
|
134
134
|
repo.dimg.dapp.log_warning(desc: { code: :stage_dependencies_not_found,
|
135
135
|
data: { repo: repo.respond_to?(:url) ? repo.url : 'local',
|
136
136
|
dependencies: stage_dependencies.join(', ') } })
|
137
137
|
end
|
138
138
|
|
139
|
-
|
140
|
-
.
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
139
|
+
entries
|
140
|
+
.sort_by {|root, entry| File.join(root, entry[:name])}
|
141
|
+
.reduce(nil) {|prev_hash, (root, entry)|
|
142
|
+
content = nil
|
143
|
+
content = repo.lookup_object(entry[:oid]).content if entry[:type] == :blob
|
144
|
+
|
145
|
+
Digest::SHA256.hexdigest [
|
146
|
+
prev_hash,
|
147
|
+
File.join(root, entry[:name]),
|
148
|
+
entry[:filemode].to_s,
|
149
|
+
content
|
150
|
+
].compact.join(':::')
|
151
|
+
}
|
148
152
|
end
|
149
153
|
end
|
150
154
|
end
|
@@ -187,7 +191,7 @@ module Dapp
|
|
187
191
|
end
|
188
192
|
|
189
193
|
def archive_any_changes?(stage)
|
190
|
-
|
194
|
+
repo_entries(archive_stage_commit(stage)).any?
|
191
195
|
end
|
192
196
|
|
193
197
|
def patch_any_changes?(stage)
|
@@ -212,18 +216,18 @@ module Dapp
|
|
212
216
|
[:owner, :group].map { |attr| "--#{attr}=#{send(attr)}" unless send(attr).nil? }.compact
|
213
217
|
end
|
214
218
|
|
215
|
-
def archive_file(stage,
|
219
|
+
def archive_file(stage, commit)
|
216
220
|
if repo.dimg.dapp.options[:use_system_tar]
|
217
|
-
archive_file_with_system_tar(stage,
|
221
|
+
archive_file_with_system_tar(stage, commit)
|
218
222
|
else
|
219
|
-
archive_file_with_tar_writer(stage,
|
223
|
+
archive_file_with_tar_writer(stage, commit)
|
220
224
|
end
|
221
|
-
repo.dimg.container_tmp_path('archives', archive_file_name(
|
225
|
+
repo.dimg.container_tmp_path('archives', archive_file_name(commit))
|
222
226
|
end
|
223
227
|
|
224
|
-
def archive_file_with_tar_writer(stage,
|
225
|
-
tar_write(repo.dimg.tmp_path('archives', archive_file_name(
|
226
|
-
|
228
|
+
def archive_file_with_tar_writer(stage, commit)
|
229
|
+
tar_write(repo.dimg.tmp_path('archives', archive_file_name(commit))) do |tar|
|
230
|
+
each_archive_entry(stage, commit) do |path, content, mode|
|
227
231
|
if mode == 40960 # symlink
|
228
232
|
tar.add_symlink path, content, mode
|
229
233
|
else
|
@@ -237,10 +241,10 @@ module Dapp
|
|
237
241
|
raise Error::TarWriter, message: e.message
|
238
242
|
end
|
239
243
|
|
240
|
-
def archive_file_with_system_tar(stage,
|
241
|
-
repo.dimg.tmp_path('archives', archive_file_name(
|
242
|
-
relative_archive_file_path = File.join('archives_files', file_name(
|
243
|
-
|
244
|
+
def archive_file_with_system_tar(stage, commit)
|
245
|
+
repo.dimg.tmp_path('archives', archive_file_name(commit)).tap do |archive_path|
|
246
|
+
relative_archive_file_path = File.join('archives_files', file_name(commit))
|
247
|
+
each_archive_entry(stage, commit) do |path, content, mode|
|
244
248
|
file_path = repo.dimg.tmp_path(relative_archive_file_path, path)
|
245
249
|
|
246
250
|
if mode == 40960 # symlink
|
@@ -255,23 +259,6 @@ module Dapp
|
|
255
259
|
end
|
256
260
|
end
|
257
261
|
|
258
|
-
def archive_diff_pathes(stage, from_commit, to_commit)
|
259
|
-
diff_patches(from_commit, to_commit).each do |patch|
|
260
|
-
entry = patch.delta.new_file
|
261
|
-
raise_if_submodule_patch!(patch)
|
262
|
-
content = begin
|
263
|
-
if to_commit == nil
|
264
|
-
next unless (path = repo.path.dirname.join(entry[:path])).file?
|
265
|
-
File.read(path)
|
266
|
-
else
|
267
|
-
repo.lookup_object(entry[:oid]).content
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
yield slice_cwd(stage, entry[:path]), content, entry[:mode]
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
262
|
def slice_cwd(stage, path)
|
276
263
|
return path if cwd.empty?
|
277
264
|
|
@@ -289,22 +276,21 @@ module Dapp
|
|
289
276
|
end
|
290
277
|
end
|
291
278
|
|
292
|
-
def archive_file_name(
|
293
|
-
file_name(
|
279
|
+
def archive_file_name(commit)
|
280
|
+
file_name(commit, ext: 'tar')
|
294
281
|
end
|
295
282
|
|
296
283
|
def patch_file(stage, from_commit, to_commit)
|
297
284
|
File.open(repo.dimg.tmp_path('patches', patch_file_name(from_commit, to_commit)), File::RDWR | File::CREAT) do |f|
|
298
285
|
diff_patches(from_commit, to_commit).each do |patch|
|
299
|
-
|
286
|
+
raise_if_submodule_entry!(patch.delta.new_file)
|
300
287
|
f.write change_patch_new_file_path(stage, patch)
|
301
288
|
end
|
302
289
|
end
|
303
290
|
repo.dimg.container_tmp_path('patches', patch_file_name(from_commit, to_commit))
|
304
291
|
end
|
305
292
|
|
306
|
-
def
|
307
|
-
entry = patch.delta.new_file
|
293
|
+
def raise_if_submodule_entry!(entry) # FIXME
|
308
294
|
if entry[:mode] == 57344 # submodule
|
309
295
|
raise Error::Rugged, code: :submodule_not_supported, data: { path: repo.path.dirname.join(entry[:path]) }
|
310
296
|
end
|
@@ -371,6 +357,24 @@ module Dapp
|
|
371
357
|
"#{[paramshash, args].flatten.compact.join('_')}#{".#{ext}" unless ext.nil? }"
|
372
358
|
end
|
373
359
|
|
360
|
+
def repo_entries(commit, paths: include_paths_or_cwd)
|
361
|
+
(@repo_entries ||= {})[[commit, paths]] ||= begin
|
362
|
+
repo.entries(commit, paths: paths, exclude_paths: exclude_paths(true))
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
def each_archive_entry(stage, commit, &blk)
|
367
|
+
repo_entries(commit).each do |root, entry|
|
368
|
+
raise_if_submodule_entry!(entry)
|
369
|
+
|
370
|
+
if entry[:type] == :blob
|
371
|
+
content = repo.lookup_object(entry[:oid]).content
|
372
|
+
|
373
|
+
yield slice_cwd(stage, File.join(root, entry[:name])), content, entry[:filemode]
|
374
|
+
end
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
374
378
|
def diff_patches(from_commit, to_commit, paths: include_paths_or_cwd)
|
375
379
|
(@diff_patches ||= {})[[from_commit, to_commit, paths]] ||= begin
|
376
380
|
options = {}.tap do |opts|
|
@@ -414,8 +418,8 @@ module Dapp
|
|
414
418
|
end
|
415
419
|
end
|
416
420
|
|
417
|
-
def
|
418
|
-
|
421
|
+
def archive_stage_commit(stage)
|
422
|
+
stage.layer_commit(self)
|
419
423
|
end
|
420
424
|
|
421
425
|
def patch_stage_commits(stage)
|
@@ -31,6 +31,24 @@ module Dapp
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
def entries(commit, paths: [], exclude_paths: [])
|
35
|
+
[].tap do |entries|
|
36
|
+
lookup_commit(commit).tree.walk(:preorder) do |root, entry|
|
37
|
+
fullpath = File.join(root, entry[:name]).reverse.chomp('/').reverse
|
38
|
+
|
39
|
+
is_exclude_path = exclude_paths.any? { |p| check_path?(fullpath, p) }
|
40
|
+
is_include_path = begin
|
41
|
+
paths.empty? ||
|
42
|
+
paths.any? { |p| check_path?(fullpath, p) || check_subpath?(fullpath, p) }
|
43
|
+
end
|
44
|
+
|
45
|
+
next false if is_exclude_path || !is_include_path
|
46
|
+
|
47
|
+
entries << [root, entry]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
34
52
|
def diff(from, to, **kwargs)
|
35
53
|
if to.nil?
|
36
54
|
raise "Workdir diff not supported for #{self.class}"
|
@@ -89,12 +107,24 @@ module Dapp
|
|
89
107
|
private
|
90
108
|
|
91
109
|
def check_path?(path, format)
|
110
|
+
path_checker(path) do |checking_path|
|
111
|
+
File.fnmatch(format, checking_path)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def check_subpath?(path, format)
|
116
|
+
path_checker(format) do |checking_path|
|
117
|
+
File.fnmatch(checking_path, path)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def path_checker(path)
|
92
122
|
path_parts = path.split('/')
|
93
123
|
checking_path = nil
|
94
124
|
|
95
125
|
until path_parts.empty?
|
96
126
|
checking_path = [checking_path, path_parts.shift].compact.join('/')
|
97
|
-
return true if
|
127
|
+
return true if yield checking_path
|
98
128
|
end
|
99
129
|
false
|
100
130
|
end
|
@@ -144,14 +144,7 @@ module Dapp
|
|
144
144
|
end
|
145
145
|
|
146
146
|
watch_hooks_thr = Thread.new do
|
147
|
-
watch_hooks.each {|job|
|
148
|
-
begin
|
149
|
-
Kubernetes::Manager::Job.new(self, job.name).watch_till_done!
|
150
|
-
rescue ::Exception => e
|
151
|
-
sentry_exception(e, extra: {"job-spec" => job.spec})
|
152
|
-
raise
|
153
|
-
end
|
154
|
-
}
|
147
|
+
watch_hooks.each {|job| Kubernetes::Manager::Job.new(self, job.name).watch_till_done!}
|
155
148
|
end
|
156
149
|
|
157
150
|
deployment_managers = release.deployments.values
|
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.
|
4
|
+
version: 0.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Stolyarov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mixlib-shellout
|
@@ -186,34 +186,6 @@ dependencies:
|
|
186
186
|
- - ">="
|
187
187
|
- !ruby/object:Gem::Version
|
188
188
|
version: 1.0.6
|
189
|
-
- !ruby/object:Gem::Dependency
|
190
|
-
name: sentry-raven
|
191
|
-
requirement: !ruby/object:Gem::Requirement
|
192
|
-
requirements:
|
193
|
-
- - "~>"
|
194
|
-
- !ruby/object:Gem::Version
|
195
|
-
version: 2.7.2
|
196
|
-
type: :runtime
|
197
|
-
prerelease: false
|
198
|
-
version_requirements: !ruby/object:Gem::Requirement
|
199
|
-
requirements:
|
200
|
-
- - "~>"
|
201
|
-
- !ruby/object:Gem::Version
|
202
|
-
version: 2.7.2
|
203
|
-
- !ruby/object:Gem::Dependency
|
204
|
-
name: toml-rb
|
205
|
-
requirement: !ruby/object:Gem::Requirement
|
206
|
-
requirements:
|
207
|
-
- - "~>"
|
208
|
-
- !ruby/object:Gem::Version
|
209
|
-
version: 1.1.1
|
210
|
-
type: :runtime
|
211
|
-
prerelease: false
|
212
|
-
version_requirements: !ruby/object:Gem::Requirement
|
213
|
-
requirements:
|
214
|
-
- - "~>"
|
215
|
-
- !ruby/object:Gem::Version
|
216
|
-
version: 1.1.1
|
217
189
|
- !ruby/object:Gem::Dependency
|
218
190
|
name: bundler
|
219
191
|
requirement: !ruby/object:Gem::Requirement
|
@@ -471,7 +443,6 @@ files:
|
|
471
443
|
- lib/dapp/dapp/logging/i18n.rb
|
472
444
|
- lib/dapp/dapp/logging/paint.rb
|
473
445
|
- lib/dapp/dapp/logging/process.rb
|
474
|
-
- lib/dapp/dapp/sentry.rb
|
475
446
|
- lib/dapp/dapp/shellout/base.rb
|
476
447
|
- lib/dapp/dapp/shellout/streaming.rb
|
477
448
|
- lib/dapp/dapp/ssh_agent.rb
|
@@ -668,7 +639,6 @@ files:
|
|
668
639
|
- lib/dapp/helper/sha256.rb
|
669
640
|
- lib/dapp/helper/tar.rb
|
670
641
|
- lib/dapp/helper/trivia.rb
|
671
|
-
- lib/dapp/helper/url.rb
|
672
642
|
- lib/dapp/helper/yaml.rb
|
673
643
|
- lib/dapp/kube.rb
|
674
644
|
- lib/dapp/kube/cli/cli.rb
|
@@ -736,7 +706,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
736
706
|
version: 2.5.0
|
737
707
|
requirements: []
|
738
708
|
rubyforge_project:
|
739
|
-
rubygems_version: 2.
|
709
|
+
rubygems_version: 2.6.14
|
740
710
|
signing_key:
|
741
711
|
specification_version: 4
|
742
712
|
summary: Build docker packaged apps using chef or shell
|
data/lib/dapp/dapp/sentry.rb
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
module Dapp
|
2
|
-
class Dapp
|
3
|
-
module Sentry
|
4
|
-
def sentry_message(msg, **kwargs)
|
5
|
-
return if not ensure_sentry_configured
|
6
|
-
kwargs[:level] ||= "info"
|
7
|
-
Raven.capture_message(msg, _make_sentry_params(**kwargs))
|
8
|
-
end
|
9
|
-
|
10
|
-
def sentry_exception(exception, **kwargs)
|
11
|
-
return if not ensure_sentry_configured
|
12
|
-
(kwargs[:tags] ||= {})['error-code'] = begin
|
13
|
-
net_status = exception.net_status
|
14
|
-
[net_status[:context], net_status[:code]].compact.join('_')
|
15
|
-
end
|
16
|
-
Raven.capture_exception(exception, _make_sentry_params(**kwargs))
|
17
|
-
end
|
18
|
-
|
19
|
-
def ensure_sentry_configured
|
20
|
-
return false unless sentry_settings = settings["sentry"]
|
21
|
-
|
22
|
-
unless @sentry_settings_configured
|
23
|
-
Raven.configure do |config|
|
24
|
-
logger = ::Logger.new(STDOUT)
|
25
|
-
logger.level = ::Logger::WARN
|
26
|
-
|
27
|
-
config.logger = logger
|
28
|
-
config.dsn = sentry_settings["dsn"]
|
29
|
-
end
|
30
|
-
|
31
|
-
@sentry_settings_configured = true
|
32
|
-
end
|
33
|
-
|
34
|
-
return true
|
35
|
-
end
|
36
|
-
|
37
|
-
def _make_sentry_params(level: nil, tags: {}, extra: {}, user: {})
|
38
|
-
{
|
39
|
-
level: level,
|
40
|
-
tags: _sentry_tags_context.merge(tags),
|
41
|
-
extra: _sentry_extra_context.merge(extra),
|
42
|
-
user: _sentry_user_context.merge(user),
|
43
|
-
}
|
44
|
-
end
|
45
|
-
|
46
|
-
def _sentry_extra_context
|
47
|
-
@_sentry_extra_context ||= {
|
48
|
-
"pwd" => Dir.pwd,
|
49
|
-
"dapp-dir" => self.work_dir,
|
50
|
-
"options" => self.options,
|
51
|
-
"env-options" => {
|
52
|
-
"DAPP_FORCE_SAVE_CACHE" => ENV["DAPP_FORCE_SAVE_CACHE"],
|
53
|
-
"DAPP_BIN_DAPPFILE_YML" => ENV["DAPP_BIN_DAPPFILE_YML"],
|
54
|
-
"ANSIBLE_ARGS" => ENV["ANSIBLE_ARGS"],
|
55
|
-
"DAPP_CHEF_DEBUG" => ENV["DAPP_CHEF_DEBUG"],
|
56
|
-
},
|
57
|
-
}.tap {|extra|
|
58
|
-
extra["ci-env"] = {"CI" => ENV["CI"]}
|
59
|
-
ENV.select {|k, v| k.start_with?("CI_")}.each do |k, v|
|
60
|
-
extra["ci-env"][k] = v
|
61
|
-
end
|
62
|
-
}
|
63
|
-
end
|
64
|
-
|
65
|
-
def _sentry_tags_context
|
66
|
-
name = options[:name] ||
|
67
|
-
@_sentry_tags_context ||= {
|
68
|
-
"dapp-short-version" => ::Dapp::VERSION.split(".")[0..1].join("."),
|
69
|
-
"dapp-version" => ::Dapp::VERSION,
|
70
|
-
"dapp-build-cache-version" => ::Dapp::BUILD_CACHE_VERSION,
|
71
|
-
"dapp-command" => self.options[:dapp_command],
|
72
|
-
}.tap {|tags|
|
73
|
-
git_config_path = File.join(Dir.pwd, ".git/config")
|
74
|
-
|
75
|
-
tags["dapp-name"] = options[:name]
|
76
|
-
|
77
|
-
if File.exists? git_config_path
|
78
|
-
cfg = IniFile.load(File.join(Dir.pwd, ".git/config"))
|
79
|
-
remote_origin_cfg = cfg['remote "origin"']
|
80
|
-
remote_origin_url = remote_origin_cfg["url"]
|
81
|
-
if remote_origin_url
|
82
|
-
tags["dapp-name"] ||= begin
|
83
|
-
repo_name = remote_origin_url.split('/').last
|
84
|
-
repo_name = repo_name[/.*(?=\.git)/] if repo_name.end_with? '.git'
|
85
|
-
repo_name
|
86
|
-
end
|
87
|
-
|
88
|
-
tags["git-host"] = self.get_host_from_git_url(remote_origin_url)
|
89
|
-
|
90
|
-
git_name = self.git_url_to_name(remote_origin_url)
|
91
|
-
|
92
|
-
tags["git-group"] = git_name.partition("/")[0]
|
93
|
-
tags["git-name"] = git_name
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
tags["dapp-name"] ||= File.basename(Dir.pwd)
|
98
|
-
|
99
|
-
begin
|
100
|
-
ver = self.class.host_docker_minor_version
|
101
|
-
tags["docker-minor-version"] = ver.to_s
|
102
|
-
rescue ::Exception
|
103
|
-
end
|
104
|
-
}
|
105
|
-
end
|
106
|
-
|
107
|
-
def _sentry_user_context
|
108
|
-
@_sentry_user_context ||= {}
|
109
|
-
end
|
110
|
-
end # Sentry
|
111
|
-
end # Dapp
|
112
|
-
end # Dapp
|
data/lib/dapp/helper/url.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
module Dapp
|
2
|
-
module Helper
|
3
|
-
module Url
|
4
|
-
def git_url_to_name(url)
|
5
|
-
url_without_scheme = url.split("://", 2).last
|
6
|
-
# This may be broken, because "@" should delimit creds, not a ":"
|
7
|
-
url_without_creds = url_without_scheme.split(":", 2).last
|
8
|
-
url_without_creds.gsub(%r{.*?([^\/ ]+\/[^\/ ]+)\.git}, '\\1')
|
9
|
-
end
|
10
|
-
|
11
|
-
def get_host_from_git_url(url)
|
12
|
-
url_without_scheme = url.split("://", 2).last
|
13
|
-
url_without_creds = url_without_scheme.split("@", 2).last
|
14
|
-
|
15
|
-
# Split out part after ":" in this kind of url: github.com:flant/dapp.git
|
16
|
-
url_part = url_without_creds.split(":", 2).first
|
17
|
-
|
18
|
-
# Split out part after first "/": github.com/flant/dapp.git
|
19
|
-
url_part.split("/", 2).first
|
20
|
-
end
|
21
|
-
end # Url
|
22
|
-
end # Helper
|
23
|
-
end # Dapp
|