dapp 0.23.9 → 0.23.10

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: 2e1a4d9df02d7503f13c90e0d0a7c822430d868a
4
- data.tar.gz: 6f9009a613d5f3472cdf5f113c8b51966bf89937
3
+ metadata.gz: 949df785aff321e34eb685421d3c7c0b396bc62b
4
+ data.tar.gz: 85336f30a665901ee3c716a9d53512112e58426e
5
5
  SHA512:
6
- metadata.gz: 446853c002ce18de52381df1be3c55539bdb7dc9836269a124aed216cc308b175e5a3fd44ca2e5d5c2cca158ede4fe6a397614aecacb4b092c0089c4219f4a6f
7
- data.tar.gz: 187eeb1ce2018264a7b56e6cf48c3143b6e11c7d88f5d5926804f0837ba2995bb4be241e876b61f471bd115efe8cadd640fae7af0e8504da0ccf2856704e0003
6
+ metadata.gz: bcb935ad210325c03aa642906adbd970beef82a2e30c3e0d3ccf14e7a60e0b219fe98e141fa28204421b26fafe270dd16ba207073d60fdff5f4cf6fe1a30b437
7
+ data.tar.gz: 7f199a77a71b6096989ad44431c1e1e900f7155d1a3840f0fc39eb781b3a2e8cc3e0300c12878efb2df04a42b284b8150daabfdebb28c739a7e49370928dcedf
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
@@ -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
@@ -116,6 +116,7 @@ module Dapp
116
116
  # Поэтому перехватываем и просто отображаем произошедшую
117
117
  # ошибку для информации пользователю без завершения работы dapp.
118
118
  $stderr.puts(::Dapp::Dapp.paint_string(::Dapp::Helper::NetStatus.message(e), :warning))
119
+ sentry_exception(e, extra: {"job-spec" => job.spec})
119
120
  end
120
121
 
121
122
  end # Thread
@@ -1,4 +1,4 @@
1
1
  module Dapp
2
- VERSION = "0.23.9"
2
+ VERSION = "0.23.10"
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.23.9
4
+ version: 0.23.10
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