dapp 0.22.16 → 0.22.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 236182f0450745e08a605cd74b57cee3c49216e2
4
- data.tar.gz: c58e45331daec2b1a514094b5dcf5c961020e033
3
+ metadata.gz: 125ccf57682d13035150191173dd8b2f0ad8af3b
4
+ data.tar.gz: a1c74f6511df262e5a3423549c0909ff21110f23
5
5
  SHA512:
6
- metadata.gz: 42186468517a2928235edc3c5de7f77f3b9a6c79cc67eb5d55a8124963af1027ea63e870d3f415aff2c9516c70a159de209fae32a88d73dc901eeeef67a47e36
7
- data.tar.gz: 9dca98eba47c551cd7ab60b12c6dedcb2c72e2e5a77a4984af4b587069f1ca5d4ce9f144d72bc09853553392ed73fff0b8bc6f4e9ebbd5941df463dac4203ee3
6
+ metadata.gz: 60cb923e5e5cf44001c0dabdc04d56a903f7680219492f336900a2e36622da578c77836f77d3fc3c3a0855f5740a8ba82747d46d2c09296373c529118844a730
7
+ data.tar.gz: 47a57d0155fd13388240fdae1b42dc475d8f5ce3b30c051f118afb783b1ef805ad7aeb00a25a38848967c4a60b508ad87d6d508ab724503c52a9ba6b4dd2e2ef
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
@@ -25,6 +25,8 @@ require 'etc'
25
25
  require 'zlib'
26
26
  require 'slugify'
27
27
  require 'base64'
28
+ require 'sentry-raven'
29
+ require 'toml-rb'
28
30
 
29
31
  require 'dapp/version'
30
32
  require 'dapp/core_ext/hash'
@@ -35,6 +37,7 @@ require 'dapp/helper/sha256'
35
37
  require 'dapp/helper/net_status'
36
38
  require 'dapp/helper/tar'
37
39
  require 'dapp/helper/yaml'
40
+ require 'dapp/helper/url'
38
41
  require 'dapp/prctl'
39
42
  require 'dapp/error/mod/user'
40
43
  require 'dapp/error/base'
@@ -55,6 +58,7 @@ require 'dapp/config/directive/base'
55
58
  require 'dapp/config/config'
56
59
  require 'dapp/dapp/lock'
57
60
  require 'dapp/dapp/ssh_agent'
61
+ require 'dapp/dapp/sentry'
58
62
  require 'dapp/dapp/git_artifact'
59
63
  require 'dapp/dapp/dappfile'
60
64
  require 'dapp/dapp/chef'
@@ -38,6 +38,10 @@ BANNER
38
38
  show_options: true,
39
39
  exit: 0
40
40
 
41
+ class << self
42
+ attr_accessor :dapp_object
43
+ end
44
+
41
45
  def initialize(*args)
42
46
  super(*args)
43
47
 
@@ -58,6 +58,8 @@ module Dapp
58
58
 
59
59
  def run_dapp_command(run_method, options: {}, log_running_time: true, try_host_docker_login: false)
60
60
  dapp = ::Dapp::Dapp.new(options: options)
61
+ ::Dapp::CLI.dapp_object = dapp
62
+ dapp.sentry_message("Manual usage: `#{options[:dapp_command]}` command") unless ENV['CI']
61
63
 
62
64
  log_dapp_running_time(dapp, ignore: !log_running_time) do
63
65
  begin
@@ -74,6 +76,10 @@ module Dapp
74
76
  end
75
77
  end
76
78
 
79
+ def run_method
80
+ class_to_lowercase
81
+ end
82
+
77
83
  def log_dapp_running_time(dapp, ignore: false)
78
84
  return yield if ignore
79
85
 
@@ -95,7 +101,7 @@ module Dapp
95
101
  self.class.print_error_with_help_and_die! self, "cannot use alias options --run-dir, --build-dir, --deploy-dir at the same time"
96
102
  end
97
103
 
98
- config.merge(build_dir: dirs.compact.first, **kwargs)
104
+ config.merge(build_dir: dirs.compact.first, dapp_command: run_method, **kwargs)
99
105
  end
100
106
  end
101
107
  end
@@ -17,10 +17,13 @@ module Dapp
17
17
  include Logging::Paint
18
18
 
19
19
  include SshAgent
20
+ include Sentry
21
+
20
22
  include Helper::Sha256
21
- extend Helper::Trivia
23
+ extend Helper::Trivia
22
24
  include Helper::Trivia
23
25
  include Helper::Tar
26
+ include Helper::Url
24
27
 
25
28
  include Deps::Toolchain
26
29
  include Deps::Gitartifact
@@ -41,6 +44,18 @@ module Dapp
41
44
  self.class.options
42
45
  end
43
46
 
47
+ def settings
48
+ @settings ||= begin
49
+ settings_path = File.join(self.class.home_dir, "settings.toml")
50
+
51
+ if File.exists? settings_path
52
+ TomlRB.load_file(settings_path)
53
+ else
54
+ {}
55
+ end
56
+ end
57
+ end
58
+
44
59
  def name
45
60
  @name ||= begin
46
61
  n = begin
@@ -86,8 +101,8 @@ module Dapp
86
101
  self.class.tmp_base_dir
87
102
  end
88
103
 
89
- def build_path(*path)
90
- @build_path ||= begin
104
+ def build_dir
105
+ @build_dir ||= begin
91
106
  if option_build_dir
92
107
  Pathname.new(option_build_dir)
93
108
  else
@@ -95,7 +110,10 @@ module Dapp
95
110
  Pathname.new(dir)
96
111
  end.expand_path.tap(&:mkpath)
97
112
  end
98
- make_path(@build_path, *path)
113
+ end
114
+
115
+ def build_path(*path)
116
+ make_path(build_dir, *path)
99
117
  end
100
118
 
101
119
  def local_git_artifact_exclude_paths(&blk)
@@ -11,6 +11,12 @@ module Dapp
11
11
 
12
12
  def tags_by_scheme
13
13
  @tags_by_scheme_name ||= begin
14
+ if simple_tags[:custom].any?
15
+ if settings.fetch("sentry", {}).fetch("detect-push-tag-usage", false)
16
+ sentry_message("--tag or --tag-slug usage detected", extra: {"slug_tags" => simple_tags})
17
+ end
18
+ end
19
+
14
20
  [simple_tags, branch_tags, commit_tags, build_tags, ci_tags].reduce({}) do |some_tags_by_scheme, tags_by_scheme|
15
21
  tags_by_scheme.in_depth_merge(some_tags_by_scheme)
16
22
  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
@@ -9,10 +9,6 @@ module Dapp::Dimg::CLI
9
9
  self.class.parse_options(self, argv)
10
10
  run_dapp_command(run_method, options: cli_options(dimgs_patterns: cli_arguments))
11
11
  end
12
-
13
- def run_method
14
- class_to_lowercase
15
- end
16
12
  end
17
13
  end
18
14
  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
@@ -71,7 +71,14 @@ module Dapp
71
71
  watch_hooks_thr = nil
72
72
  unless dry_run?
73
73
  watch_hooks_thr = Thread.new do
74
- watch_hooks.each {|job| Kubernetes::Manager::Job.new(self, job.name).watch_till_done!}
74
+ watch_hooks.each {|job|
75
+ begin
76
+ Kubernetes::Manager::Job.new(self, job.name).watch_till_done!
77
+ rescue ::Exception => e
78
+ sentry_exception(e, extra: {"job-spec" => job.spec})
79
+ raise
80
+ end
81
+ }
75
82
  end
76
83
  end
77
84
 
@@ -1,4 +1,4 @@
1
1
  module Dapp
2
- VERSION = '0.22.16'.freeze
2
+ VERSION = '0.22.17'.freeze
3
3
  BUILD_CACHE_VERSION = 26.1
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.22.16
4
+ version: 0.22.17
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
@@ -448,6 +476,7 @@ files:
448
476
  - lib/dapp/dapp/logging/paint.rb
449
477
  - lib/dapp/dapp/logging/process.rb
450
478
  - lib/dapp/dapp/option_tags.rb
479
+ - lib/dapp/dapp/sentry.rb
451
480
  - lib/dapp/dapp/shellout/base.rb
452
481
  - lib/dapp/dapp/shellout/streaming.rb
453
482
  - lib/dapp/dapp/slug.rb
@@ -647,6 +676,7 @@ files:
647
676
  - lib/dapp/helper/sha256.rb
648
677
  - lib/dapp/helper/tar.rb
649
678
  - lib/dapp/helper/trivia.rb
679
+ - lib/dapp/helper/url.rb
650
680
  - lib/dapp/helper/yaml.rb
651
681
  - lib/dapp/kube.rb
652
682
  - lib/dapp/kube/cli/cli.rb