dapp 0.13.25 → 0.13.26

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: c586f423498eff395bba36feb6f211db72a2ca90
4
- data.tar.gz: 0baa9c3286c378c3dca44947673fd24e0189ef0f
3
+ metadata.gz: 557eecaf7833aafc8165c5a3191b3c4d961044fa
4
+ data.tar.gz: a7d766a573beb19a0cd1c99bfdb9e484e2c344c2
5
5
  SHA512:
6
- metadata.gz: 48ed41945c9ad839c4063b54306a59c031c6f9696ff78c7a5b269b85b0bf3efb39dce55e4fd9adf729e2e532fdf3a01e85684fab21cdcb98b5e10a8f2ad5ecd9
7
- data.tar.gz: b536be5cf458fbf997b7e3a324157461691cc53fdec802dada1c3a9de602304ce45ff029c36a24c54a8140b84b0c18e32b4dadf5b4229e47219ad9169f9aeada
6
+ metadata.gz: 6b396fcf8969353a6a704a09344131d04dfe5c6295c003cc69519086c0f1d25c18ceaf99bab0a5b9f2a09108bb3bd22803b575d5cb9c7962a6ef97df71024196
7
+ data.tar.gz: dacf00d79fa3004474c3ae45dd231d7e608275075f0624bd789796ad798cfa28912aafe29226b5fce3eacfca0c9a607a25fd6d66d6fbfb6c7b1c14545f61c872
data/bin/dapp CHANGED
@@ -14,6 +14,10 @@ begin
14
14
  $stderr.puts(message)
15
15
  end
16
16
 
17
+ if Dapp::CLI.dapp_object
18
+ Dapp::CLI.dapp_object.sentry_exception(e)
19
+ end
20
+
17
21
  raise
18
22
  end
19
23
  rescue ::SystemExit
@@ -23,6 +23,8 @@ require 'yaml'
23
23
  require 'openssl'
24
24
  require 'etc'
25
25
  require 'zlib'
26
+ require 'sentry-raven'
27
+ require 'toml-rb'
26
28
 
27
29
  require 'dapp/version'
28
30
  require 'dapp/core_ext/hash'
@@ -33,6 +35,7 @@ require 'dapp/helper/sha256'
33
35
  require 'dapp/helper/net_status'
34
36
  require 'dapp/helper/tar'
35
37
  require 'dapp/helper/yaml'
38
+ require 'dapp/helper/url'
36
39
  require 'dapp/prctl'
37
40
  require 'dapp/error/base'
38
41
  require 'dapp/error/dapp'
@@ -48,6 +51,7 @@ require 'dapp/config/config'
48
51
  require 'dapp/config/error/config'
49
52
  require 'dapp/dapp/lock'
50
53
  require 'dapp/dapp/ssh_agent'
54
+ require 'dapp/dapp/sentry'
51
55
  require 'dapp/dapp/git_artifact'
52
56
  require 'dapp/dapp/dappfile'
53
57
  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
 
@@ -56,12 +56,16 @@ module Dapp
56
56
  super()
57
57
  end
58
58
 
59
+ def run_method
60
+ class_to_lowercase
61
+ end
62
+
59
63
  def run(_argv = ARGV)
60
64
  raise
61
65
  end
62
66
 
63
67
  def cli_options(**kvargs)
64
- config.merge(**kvargs)
68
+ config.merge(dapp_command: run_method, **kvargs)
65
69
  end
66
70
  end
67
71
  end
@@ -12,9 +12,13 @@ module Dapp
12
12
  include Logging::Paint
13
13
 
14
14
  include SshAgent
15
+ include Sentry
16
+
15
17
  include Helper::Sha256
18
+ extend Helper::Trivia
16
19
  include Helper::Trivia
17
20
  include Helper::Tar
21
+ include Helper::Url
18
22
 
19
23
  include Deps::Gitartifact
20
24
  include Deps::Base
@@ -28,6 +32,21 @@ module Dapp
28
32
  Logging::I18n.initialize
29
33
  validate_config_options!
30
34
  Logging::Paint.initialize(option_color)
35
+
36
+ ::Dapp::CLI.dapp_object = self
37
+ sentry_message("Manual usage: `#{options[:dapp_command]}` command") unless ENV['CI']
38
+ end
39
+
40
+ def settings
41
+ @settings ||= begin
42
+ settings_path = File.join(self.class.home_dir, "settings.toml")
43
+
44
+ if File.exists? settings_path
45
+ TomlRB.load_file(settings_path)
46
+ else
47
+ {}
48
+ end
49
+ end
31
50
  end
32
51
 
33
52
  def name
@@ -70,15 +89,18 @@ module Dapp
70
89
  File.expand_path(options[:tmp_dir_prefix] || '/tmp')
71
90
  end
72
91
 
73
- def build_path(*path)
74
- @build_path ||= begin
92
+ def build_dir
93
+ @build_dir ||= begin
75
94
  if option_build_dir
76
95
  Pathname.new(option_build_dir)
77
96
  else
78
97
  path('.dapp_build')
79
98
  end.expand_path.tap(&:mkpath)
80
99
  end
81
- make_path(@build_path, *path)
100
+ end
101
+
102
+ def build_path(*path)
103
+ make_path(build_dir, *path)
82
104
  end
83
105
 
84
106
  def local_git_artifact_exclude_paths(&blk)
@@ -102,6 +124,10 @@ module Dapp
102
124
  self.class.host_docker_bin
103
125
  end
104
126
 
127
+ def self.home_dir
128
+ File.join(Dir.home, ".dapp")
129
+ end
130
+
105
131
  def self.host_docker_bin
106
132
  @host_docker_bin ||= begin
107
133
  raise Error::Dapp, code: :docker_not_found if (res = shellout('which docker')).exitstatus.nonzero?
@@ -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
@@ -5,10 +5,6 @@ module Dapp::Dimg::CLI
5
5
  self.class.parse_options(self, argv)
6
6
  ::Dapp::Dapp.new(options: cli_options(dimgs_patterns: cli_arguments)).public_send(run_method)
7
7
  end
8
-
9
- def run_method
10
- class_to_lowercase
11
- end
12
8
  end
13
9
  end
14
10
  end
@@ -3,11 +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
- @_name = url.gsub(%r{.*?([^\/ ]+)\.git}, '\\1')
12
+ @_name = git_url_to_name(url)
11
13
 
12
14
  super(**kwargs, &blk)
13
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
@@ -143,7 +143,14 @@ module Dapp
143
143
  end
144
144
 
145
145
  watch_hooks_thr = Thread.new do
146
- watch_hooks.each {|job| Kubernetes::Manager::Job.new(self, job.name).watch_till_done!}
146
+ watch_hooks.each {|job|
147
+ begin
148
+ Kubernetes::Manager::Job.new(self, job.name).watch_till_done!
149
+ rescue ::Exception => e
150
+ sentry_exception(e, extra: {"job-spec" => job.spec})
151
+ raise
152
+ end
153
+ }
147
154
  end
148
155
 
149
156
  deployment_managers = release.deployments.values
@@ -1,4 +1,4 @@
1
1
  module Dapp
2
- VERSION = '0.13.25'.freeze
2
+ VERSION = '0.13.26'.freeze
3
3
  BUILD_CACHE_VERSION = 18
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.13.25
4
+ version: 0.13.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Stolyarov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-17 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
@@ -166,6 +166,34 @@ dependencies:
166
166
  - - "~>"
167
167
  - !ruby/object:Gem::Version
168
168
  version: 0.1.6
169
+ - !ruby/object:Gem::Dependency
170
+ name: sentry-raven
171
+ requirement: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - "~>"
174
+ - !ruby/object:Gem::Version
175
+ version: 2.7.2
176
+ type: :runtime
177
+ prerelease: false
178
+ version_requirements: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - "~>"
181
+ - !ruby/object:Gem::Version
182
+ version: 2.7.2
183
+ - !ruby/object:Gem::Dependency
184
+ name: toml-rb
185
+ requirement: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - "~>"
188
+ - !ruby/object:Gem::Version
189
+ version: 1.1.1
190
+ type: :runtime
191
+ prerelease: false
192
+ version_requirements: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - "~>"
195
+ - !ruby/object:Gem::Version
196
+ version: 1.1.1
169
197
  - !ruby/object:Gem::Dependency
170
198
  name: bundler
171
199
  requirement: !ruby/object:Gem::Requirement
@@ -423,6 +451,7 @@ files:
423
451
  - lib/dapp/dapp/logging/i18n.rb
424
452
  - lib/dapp/dapp/logging/paint.rb
425
453
  - lib/dapp/dapp/logging/process.rb
454
+ - lib/dapp/dapp/sentry.rb
426
455
  - lib/dapp/dapp/shellout/base.rb
427
456
  - lib/dapp/dapp/shellout/streaming.rb
428
457
  - lib/dapp/dapp/ssh_agent.rb
@@ -619,6 +648,7 @@ files:
619
648
  - lib/dapp/helper/sha256.rb
620
649
  - lib/dapp/helper/tar.rb
621
650
  - lib/dapp/helper/trivia.rb
651
+ - lib/dapp/helper/url.rb
622
652
  - lib/dapp/helper/yaml.rb
623
653
  - lib/dapp/kube.rb
624
654
  - lib/dapp/kube/cli/cli.rb
@@ -686,7 +716,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
686
716
  version: 2.5.0
687
717
  requirements: []
688
718
  rubyforge_project:
689
- rubygems_version: 2.6.11
719
+ rubygems_version: 2.5.1
690
720
  signing_key:
691
721
  specification_version: 4
692
722
  summary: Build docker packaged apps using chef or shell