dapp 0.25.7 → 0.25.8

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: aef8ea2f6a2d8c3d4082b084d4b0233c26ffe33f
4
- data.tar.gz: fd5c263de25eccd3f85276b8bbd333cef39b9857
3
+ metadata.gz: fce0f6b6791bf4fba6bd882e3563b1b57272f452
4
+ data.tar.gz: 344cfd21cf25a679ba1176b785ce2122d4673bcb
5
5
  SHA512:
6
- metadata.gz: 515cfb5a3ea8ab80506bede101b128af04504faa68c9688b876be23f846407dd601dc8505a40ee5fe72e24de88011a16d362347bcd654cd02dd2f8eabd75d2f2
7
- data.tar.gz: df790680c28f11d83cd562f1357fb9e7209c33e6ab58ab5c81c40a1483180b1d86222f4e54016adadac83fa695eb32fe0c491f0620d1bce8490c4fca88ec99d6
6
+ metadata.gz: fb9f90a3add54f6f4ec82490de02f9a47355af1ba91af60b50bc8b67fe9e394ae0a33e5a4e0c88ee08809d6fe56928f266756964097f6957ed964f5476f25ac8
7
+ data.tar.gz: 2901374544207c428ce7dd926cc0760d195784a7a6338c0dbefe5833bd2b758ae1c4904d8c273ca8b14d227054310fdc899c3654a38c0b7f2dc6edf2db0f6874
data/bin/dapp CHANGED
@@ -28,6 +28,10 @@ begin
28
28
  $stderr.puts "\033[1m\033[90mStacktrace dumped to #{filename}\033[0m"
29
29
  end
30
30
 
31
+ if Dapp::CLI.dapp_object
32
+ Dapp::CLI.dapp_object.sentry_exception(e)
33
+ end
34
+
31
35
  raise
32
36
  end
33
37
  rescue Dapp::Error::Shellout => e
@@ -26,6 +26,8 @@ require 'zlib'
26
26
  require 'slugify'
27
27
  require 'base64'
28
28
  require 'io/console'
29
+ require 'sentry-raven'
30
+ require 'toml-rb'
29
31
 
30
32
  require 'dapp/version'
31
33
  require 'dapp/core_ext/hash'
@@ -36,6 +38,7 @@ require 'dapp/helper/sha256'
36
38
  require 'dapp/helper/net_status'
37
39
  require 'dapp/helper/tar'
38
40
  require 'dapp/helper/yaml'
41
+ require 'dapp/helper/url'
39
42
  require 'dapp/prctl'
40
43
  require 'dapp/error/mod/user'
41
44
  require 'dapp/error/base'
@@ -56,6 +59,7 @@ require 'dapp/config/directive/base'
56
59
  require 'dapp/config/config'
57
60
  require 'dapp/dapp/lock'
58
61
  require 'dapp/dapp/ssh_agent'
62
+ require 'dapp/dapp/sentry'
59
63
  require 'dapp/dapp/git_artifact'
60
64
  require 'dapp/dapp/dappfile'
61
65
  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
@@ -43,6 +46,18 @@ module Dapp
43
46
  self.class.options
44
47
  end
45
48
 
49
+ def settings
50
+ @settings ||= begin
51
+ settings_path = File.join(self.class.home_dir, "settings.toml")
52
+
53
+ if File.exists? settings_path
54
+ TomlRB.load_file(settings_path)
55
+ else
56
+ {}
57
+ end
58
+ end
59
+ end
60
+
46
61
  def name
47
62
  @name ||= begin
48
63
  n = begin
@@ -92,8 +107,8 @@ module Dapp
92
107
  self.class.tmp_base_dir
93
108
  end
94
109
 
95
- def build_path(*path)
96
- @build_path ||= begin
110
+ def build_dir
111
+ @build_dir ||= begin
97
112
  if option_build_dir
98
113
  Pathname.new(option_build_dir)
99
114
  else
@@ -101,7 +116,10 @@ module Dapp
101
116
  Pathname.new(dir)
102
117
  end.expand_path.tap(&:mkpath)
103
118
  end
104
- make_path(@build_path, *path)
119
+ end
120
+
121
+ def build_path(*path)
122
+ make_path(build_dir, *path)
105
123
  end
106
124
 
107
125
  def local_git_artifact_exclude_paths(&blk)
@@ -7,6 +7,12 @@ module Dapp
7
7
 
8
8
  def tags_by_scheme
9
9
  @tags_by_scheme_name ||= begin
10
+ if slug_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" => slug_tags})
13
+ end
14
+ end
15
+
10
16
  {}.tap do |tags_by_scheme|
11
17
  [slug_tags, branch_tags, ci_tags].each do |_tags_by_scheme|
12
18
  _tags_by_scheme.each do |scheme, tags|
@@ -89,4 +95,4 @@ module Dapp
89
95
  end
90
96
  end # Tags
91
97
  end # Dapp
92
- end # Dapp
98
+ end # Dapp
@@ -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
@@ -162,6 +162,7 @@ module Dapp
162
162
  # Поэтому перехватываем и просто отображаем произошедшую
163
163
  # ошибку для информации пользователю без завершения работы dapp.
164
164
  $stderr.puts(::Dapp::Dapp.paint_string(::Dapp::Helper::NetStatus.message(e), :warning))
165
+ sentry_exception(e, extra: {"job-spec" => job.spec})
165
166
  end
166
167
 
167
168
  end # Thread
@@ -1,4 +1,4 @@
1
1
  module Dapp
2
- VERSION = "0.25.7"
2
+ VERSION = "0.25.8"
3
3
  BUILD_CACHE_VERSION = 26.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.25.7
4
+ version: 0.25.8
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-03-15 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
@@ -649,6 +678,7 @@ files:
649
678
  - lib/dapp/helper/sha256.rb
650
679
  - lib/dapp/helper/tar.rb
651
680
  - lib/dapp/helper/trivia.rb
681
+ - lib/dapp/helper/url.rb
652
682
  - lib/dapp/helper/yaml.rb
653
683
  - lib/dapp/kube.rb
654
684
  - lib/dapp/kube/cli/cli.rb