dapp 0.21.15 → 0.21.16

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 132060a25af513df95b63a00263cefa2e3899c45
4
- data.tar.gz: 411ba94d239bf1ebba8f86e713efa1fa22a3e7dd
3
+ metadata.gz: 50ec328ea740514c549d2366d96d8889f3e29940
4
+ data.tar.gz: 3f1af717f6dbb3813cf8d0be4bdcc2940027859c
5
5
  SHA512:
6
- metadata.gz: 16922c0cc3c925c3151f3db2491025d5d7476a2fff75d024a78802e2a3287da36374d173558fb9ce41aadfc9408ff7d99fd87cbfa5762ddd89c267df5f8d3de8
7
- data.tar.gz: 9488c12c445c1ebee75fd20203c822a64bcb9bd5fd970af45bfad989ccb6291e6d07f2cafce35d7d462f436bea5a54630b3c9622a8c1e7267a5e37dc4ea8e731
6
+ metadata.gz: 9eaa078ee0428cf2463326539e06038ac9defcac0e688e700167257b6c9d3e1db1b75a08ca6f7bdffbc4dd5fd92e77b9e66838347cc92940ae625fe21a91b958
7
+ data.tar.gz: 2a9fd62aeafd9d26218dd5013f45d9fc6f46d100cf3dd53e22140be42275761468061e5cc5c5ae19139761a95a63fc77dd446c5db47e4c1083f4c3127117092e
data/bin/dapp CHANGED
@@ -26,6 +26,10 @@ begin
26
26
  $stderr.puts "\033[1m\033[90mStacktrace dumped to #{filename}\033[0m"
27
27
  end
28
28
 
29
+ if Dapp::CLI.dapp_object
30
+ Dapp::CLI.dapp_object.sentry_exception(e)
31
+ end
32
+
29
33
  raise
30
34
  end
31
35
  rescue Dapp::Error::Shellout => e
@@ -24,6 +24,8 @@ require 'openssl'
24
24
  require 'etc'
25
25
  require 'zlib'
26
26
  require 'slugify'
27
+ require 'sentry-raven'
28
+ require 'toml-rb'
27
29
 
28
30
  require 'dapp/version'
29
31
  require 'dapp/core_ext/hash'
@@ -34,6 +36,7 @@ require 'dapp/helper/sha256'
34
36
  require 'dapp/helper/net_status'
35
37
  require 'dapp/helper/tar'
36
38
  require 'dapp/helper/yaml'
39
+ require 'dapp/helper/url'
37
40
  require 'dapp/prctl'
38
41
  require 'dapp/error/base'
39
42
  require 'dapp/error/dapp'
@@ -49,6 +52,7 @@ require 'dapp/config/config'
49
52
  require 'dapp/config/error/config'
50
53
  require 'dapp/dapp/lock'
51
54
  require 'dapp/dapp/ssh_agent'
55
+ require 'dapp/dapp/sentry'
52
56
  require 'dapp/dapp/git_artifact'
53
57
  require 'dapp/dapp/dappfile'
54
58
  require 'dapp/dapp/chef'
@@ -37,6 +37,10 @@ BANNER
37
37
  show_options: true,
38
38
  exit: 0
39
39
 
40
+ class << self
41
+ attr_accessor :dapp_object
42
+ end
43
+
40
44
  def initialize(*args)
41
45
  super(*args)
42
46
 
@@ -62,6 +62,8 @@ module Dapp
62
62
 
63
63
  def run_dapp_command(run_method, options: {}, log_running_time: true)
64
64
  dapp = ::Dapp::Dapp.new(options: options)
65
+ ::Dapp::CLI.dapp_object = dapp
66
+ dapp.sentry_message("Manual usage: `#{options[:dapp_command]}` command") unless ENV['CI']
65
67
 
66
68
  log_dapp_running_time(dapp, ignore: !log_running_time) do
67
69
  if block_given?
@@ -72,6 +74,10 @@ module Dapp
72
74
  end
73
75
  end
74
76
 
77
+ def run_method
78
+ class_to_lowercase
79
+ end
80
+
75
81
  def log_dapp_running_time(dapp, ignore: false)
76
82
  return yield if ignore
77
83
 
@@ -88,7 +94,7 @@ module Dapp
88
94
  end
89
95
 
90
96
  def cli_options(**kwargs)
91
- config.merge(**kwargs)
97
+ config.merge(dapp_command: run_method, **kwargs)
92
98
  end
93
99
  end
94
100
  end
@@ -13,10 +13,13 @@ module Dapp
13
13
  include Logging::Paint
14
14
 
15
15
  include SshAgent
16
+ include Sentry
17
+
16
18
  include Helper::Sha256
17
- extend Helper::Trivia
19
+ extend Helper::Trivia
18
20
  include Helper::Trivia
19
21
  include Helper::Tar
22
+ include Helper::Url
20
23
 
21
24
  include Deps::Toolchain
22
25
  include Deps::Gitartifact
@@ -37,6 +40,18 @@ module Dapp
37
40
  self.class.options
38
41
  end
39
42
 
43
+ def settings
44
+ @settings ||= begin
45
+ settings_path = File.join(self.class.home_dir, "settings.toml")
46
+
47
+ if File.exists? settings_path
48
+ TomlRB.load_file(settings_path)
49
+ else
50
+ {}
51
+ end
52
+ end
53
+ end
54
+
40
55
  def name
41
56
  @name ||= begin
42
57
  if name = options[:name]
@@ -79,15 +94,18 @@ module Dapp
79
94
  self.class.tmp_base_dir
80
95
  end
81
96
 
82
- def build_path(*path)
83
- @build_path ||= begin
97
+ def build_dir
98
+ @build_dir ||= begin
84
99
  if option_build_dir
85
100
  Pathname.new(option_build_dir)
86
101
  else
87
102
  path('.dapp_build')
88
103
  end.expand_path.tap(&:mkpath)
89
104
  end
90
- make_path(@build_path, *path)
105
+ end
106
+
107
+ def build_path(*path)
108
+ make_path(build_dir, *path)
91
109
  end
92
110
 
93
111
  def local_git_artifact_exclude_paths(&blk)
@@ -133,6 +151,10 @@ module Dapp
133
151
  end
134
152
 
135
153
  class << self
154
+ def home_dir
155
+ File.join(Dir.home, ".dapp")
156
+ end
157
+
136
158
  def options
137
159
  @options ||= {}
138
160
  end
@@ -7,6 +7,12 @@ module Dapp
7
7
 
8
8
  def tags_by_scheme
9
9
  @tags_by_scheme_name ||= begin
10
+ if simple_tags[:custom].any?
11
+ if settings.fetch("sentry", {}).fetch("detect-push-tag-usage", false)
12
+ sentry_message("--tag or --tag-slug usage detected", extra: {"slug_tags" => simple_tags})
13
+ end
14
+ end
15
+
10
16
  [simple_tags, branch_tags, commit_tags, build_tags, ci_tags].reduce({}) do |some_tags_by_scheme, tags_by_scheme|
11
17
  tags_by_scheme.in_depth_merge(some_tags_by_scheme)
12
18
  end.tap do |tags_by_scheme|
@@ -0,0 +1,112 @@
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
@@ -20,10 +20,6 @@ module Dapp::Dimg::CLI
20
20
  end
21
21
  end
22
22
  end
23
-
24
- def run_method
25
- class_to_lowercase
26
- end
27
23
  end
28
24
  end
29
25
  end
@@ -3,14 +3,13 @@ module Dapp
3
3
  module Config
4
4
  module Directive
5
5
  class GitArtifactRemote < GitArtifactLocal
6
+ include ::Dapp::Helper::Url
7
+
6
8
  attr_reader :_url, :_name, :_branch, :_commit
7
9
 
8
10
  def initialize(url, **kwargs, &blk)
9
11
  @_url = url
10
-
11
- url_without_scheme = url.split("://", 2).last
12
- url_without_creds = url_without_scheme.split(":", 2).last
13
- @_name = url_without_creds.gsub(%r{.*?([^\/ ]+\/[^\/ ]+)\.git}, '\\1')
12
+ @_name = git_url_to_name(url)
14
13
 
15
14
  super(**kwargs, &blk)
16
15
  end
@@ -0,0 +1,23 @@
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
@@ -59,7 +59,14 @@ module Dapp
59
59
  end
60
60
 
61
61
  watch_hooks_thr = Thread.new do
62
- watch_hooks.each {|job| Kubernetes::Manager::Job.new(self, job.name).watch_till_done!}
62
+ watch_hooks.each {|job|
63
+ begin
64
+ Kubernetes::Manager::Job.new(self, job.name).watch_till_done!
65
+ rescue ::Exception => e
66
+ sentry_exception(e, extra: {"job-spec" => job.spec})
67
+ raise
68
+ end
69
+ }
63
70
  end
64
71
 
65
72
  deployment_managers = release.deployments.values
@@ -1,4 +1,4 @@
1
1
  module Dapp
2
- VERSION = '0.21.15'.freeze
2
+ VERSION = '0.21.16'.freeze
3
3
  BUILD_CACHE_VERSION = 24.2
4
4
  end
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.21.15
4
+ version: 0.21.16
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-02-22 00:00:00.000000000 Z
11
+ date: 2018-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-shellout
@@ -186,6 +186,34 @@ 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
189
217
  - !ruby/object:Gem::Dependency
190
218
  name: bundler
191
219
  requirement: !ruby/object:Gem::Requirement
@@ -445,6 +473,7 @@ files:
445
473
  - lib/dapp/dapp/logging/paint.rb
446
474
  - lib/dapp/dapp/logging/process.rb
447
475
  - lib/dapp/dapp/option_tags.rb
476
+ - lib/dapp/dapp/sentry.rb
448
477
  - lib/dapp/dapp/shellout/base.rb
449
478
  - lib/dapp/dapp/shellout/streaming.rb
450
479
  - lib/dapp/dapp/ssh_agent.rb
@@ -640,6 +669,7 @@ files:
640
669
  - lib/dapp/helper/sha256.rb
641
670
  - lib/dapp/helper/tar.rb
642
671
  - lib/dapp/helper/trivia.rb
672
+ - lib/dapp/helper/url.rb
643
673
  - lib/dapp/helper/yaml.rb
644
674
  - lib/dapp/kube.rb
645
675
  - lib/dapp/kube/cli/cli.rb