dapp 0.30.2 → 0.30.3

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: 85e24f5f787e11e46f34a01a946986396ead3830
4
- data.tar.gz: 075072783e8d9bb26fcf4545901a637bfb1847c0
3
+ metadata.gz: 5d13edf9865121c85fcc72bf4bbcfeb691fb7d08
4
+ data.tar.gz: 7a12de433ca2f9427cd66a916666628925d953e6
5
5
  SHA512:
6
- metadata.gz: 33db546ddeed11f985386d7c55aa48bc3704054745bb83a77e359060eb01d6e7ececf02470933e93776a4b826801fe19702a871d08c7906972ddfa14ae35bcaf
7
- data.tar.gz: 25bbfc1a6f66fa507f344939b2e1584f1938f5ad12d62a95cadfe5d4409e894fbcffa9b1e58bbd719f61e65ec43f6c3b6301d169f322e0ca2e694e6760458a94
6
+ metadata.gz: 1d2988cad1ab659edc3b190425e329a6b3f595d306f4e21a304745505ccf84d1aac52a9d1abf6cbfeade8944731e6dc4f0cd94411ffb25855d84b14ace22f8ea
7
+ data.tar.gz: 72435eac2f93bd12638d2d7b87bc948e165d3a876bf40c1f9b460b66972918353fe53fbb8647b28f650c92cb92cf1be12761724ba2c01386bfbf3b36693a0e97
@@ -47,6 +47,8 @@ en:
47
47
  kube_deploy_timeout: "Deploy timeout!"
48
48
  kube_connect_timeout: "Connect timeout when connecting to kube API."
49
49
  kube_helm_failed: "Helm failed: %{output}"
50
+ samples_directory_not_exist: "Samples directory `%{path}` not exist in repository `%{url}`!"
51
+ sample_not_exist: "Sample `%{name}` not exist in repository `%{url}` (inside samples directory `%{path}`)!"
50
52
  dapp:
51
53
  no_such_dimg: "No such dimg: `%{dimgs_patterns}`!"
52
54
  no_such_app: "No such app: `%{apps_patterns}`!"
data/lib/dapp.rb CHANGED
@@ -56,6 +56,10 @@ require 'dapp/cli/options/tag'
56
56
  require 'dapp/cli/options/ssh'
57
57
  require 'dapp/cli/command/base'
58
58
  require 'dapp/cli/command/update'
59
+ require 'dapp/cli/command/sample'
60
+ require 'dapp/cli/command/sample/base'
61
+ require 'dapp/cli/command/sample/list'
62
+ require 'dapp/cli/command/sample/create'
59
63
  require 'dapp/cli/command/slug'
60
64
  require 'dapp/cli/cli'
61
65
  require 'dapp/config/directive/base'
@@ -80,6 +84,9 @@ require 'dapp/dapp/shellout/streaming'
80
84
  require 'dapp/dapp/shellout/base'
81
85
  require 'dapp/dapp/command/common'
82
86
  require 'dapp/dapp/command/slug'
87
+ require 'dapp/dapp/command/sample/common'
88
+ require 'dapp/dapp/command/sample/create'
89
+ require 'dapp/dapp/command/sample/list'
83
90
  require 'dapp/dapp'
84
91
  require 'dapp/kube'
85
92
  require 'dapp/kube/error/default'
data/lib/dapp/cli.rb CHANGED
@@ -5,7 +5,7 @@ module Dapp
5
5
  extend Helper::Cli
6
6
  include Helper::Trivia
7
7
 
8
- SUBCOMMANDS = ['dimg', 'kube', 'update', 'slug'].freeze
8
+ SUBCOMMANDS = %w(dimg kube update sample slug).freeze
9
9
 
10
10
  banner <<BANNER.freeze
11
11
  Usage: dapp subcommand [subcommand options]
@@ -15,6 +15,7 @@ Available subcommands: (for details, dapp SUB-COMMAND --help)
15
15
  dapp dimg
16
16
  dapp kube
17
17
  dapp update
18
+ dapp sample
18
19
  dapp slug STRING
19
20
 
20
21
  Options:
@@ -0,0 +1,20 @@
1
+ module Dapp
2
+ class CLI
3
+ module Command
4
+ class Sample < ::Dapp::CLI
5
+ SUBCOMMANDS = %w(list create).freeze
6
+
7
+ banner <<BANNER.freeze
8
+ Usage: dapp sample [options] subcommand [subcommand options]
9
+
10
+ Available subcommands: (for details, dapp sample SUB-COMMAND --help)
11
+
12
+ dapp sample list [options]
13
+ dapp sample create SAMPLE_NAME [options]
14
+
15
+ Options:
16
+ BANNER
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+ module Dapp
2
+ class CLI
3
+ module Command
4
+ class Sample < ::Dapp::CLI
5
+ class Base < Base
6
+ option :samples_repo,
7
+ long: '--samples-repo GIT_REPO',
8
+ description: 'Git repository with samples (\'https://github.com/flant/dapp.git\' by default).',
9
+ default: 'https://github.com/flant/dapp.git'
10
+
11
+ option :samples_branch,
12
+ long: '--samples-branch GIT_BRANCH',
13
+ description: 'Specific git branch (\'master\' by default).',
14
+ default: 'master'
15
+
16
+ option :samples_dir,
17
+ long: '--samples-dir DIR',
18
+ description: 'Directory with samples (\'samples\' by default)',
19
+ default: 'samples'
20
+
21
+ def run_method
22
+ "sample_#{super}"
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ module Dapp
2
+ class CLI
3
+ module Command
4
+ class Sample < ::Dapp::CLI
5
+ class Create < Base
6
+ banner <<BANNER.freeze
7
+ Usage:
8
+
9
+ dapp sample create SAMPLE_NAME [options]
10
+
11
+ Options:
12
+ BANNER
13
+ def run(argv = ARGV)
14
+ self.class.parse_options(self, argv)
15
+ sample_name = self.class.required_argument(self, 'sample_name')
16
+ run_dapp_command(nil, options: cli_options) do |dapp|
17
+ dapp.sample_create(sample_name)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,21 @@
1
+ module Dapp
2
+ class CLI
3
+ module Command
4
+ class Sample < ::Dapp::CLI
5
+ class List < Base
6
+ banner <<BANNER.freeze
7
+ Usage:
8
+
9
+ dapp sample list [options]
10
+
11
+ Options:
12
+ BANNER
13
+ def run(argv = ARGV)
14
+ self.class.parse_options(self, argv)
15
+ run_dapp_command(run_method, options: cli_options)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
data/lib/dapp/dapp.rb CHANGED
@@ -10,6 +10,9 @@ module Dapp
10
10
 
11
11
  include Command::Common
12
12
  include Command::Slug
13
+ include Command::Sample::Common
14
+ include Command::Sample::List
15
+ include Command::Sample::Create
13
16
 
14
17
  include Logging::Base
15
18
  include Logging::Process
@@ -0,0 +1,54 @@
1
+ module Dapp
2
+ class Dapp
3
+ module Command
4
+ module Sample
5
+ module Common
6
+ def _sample_list
7
+ @sample_list ||= [].tap do |list|
8
+ tree = begin
9
+ latest_commit = _sample_git_repo.latest_commit(_samples_git_repo_branch)
10
+ latest_commit_tree = _sample_git_repo.lookup_commit(latest_commit).tree
11
+
12
+ if _samples_dir == '.'
13
+ latest_commit_tree
14
+ else
15
+ begin
16
+ oid = latest_commit_tree.path(_samples_dir)[:oid]
17
+ rescue Rugged::TreeError
18
+ raise Error::Command, code: :samples_directory_not_exist, data: { url: _samples_git_repo_url, path: _samples_dir }
19
+ end
20
+
21
+ _sample_git_repo.lookup_object(oid)
22
+ end
23
+ end
24
+
25
+ tree.each_tree { |entry| list << entry[:name] }
26
+ end
27
+ end
28
+
29
+ def _sample_git_repo
30
+ @sample_repo ||= begin
31
+ Dimg::GitRepo::Remote.get_or_create(
32
+ self,
33
+ git_url_to_name(_samples_git_repo_url),
34
+ url: _samples_git_repo_url
35
+ )
36
+ end
37
+ end
38
+
39
+ def _samples_git_repo_url
40
+ options[:samples_repo]
41
+ end
42
+
43
+ def _samples_git_repo_branch
44
+ options[:samples_branch]
45
+ end
46
+
47
+ def _samples_dir
48
+ options[:samples_dir]
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,57 @@
1
+ module Dapp
2
+ class Dapp
3
+ module Command
4
+ module Sample
5
+ module Create
6
+ def sample_create(sample_name)
7
+ sample_exist!(sample_name)
8
+
9
+ _sample_repo_blobs_entries(sample_name).each do |root, entry|
10
+ file_path = _sample_slice_cwd(sample_name, File.join(root, entry[:name]))
11
+ content = _sample_git_repo.lookup_object(entry[:oid]).content
12
+
13
+ begin
14
+ FileUtils.mkdir_p(File.dirname(file_path))
15
+ if entry[:filemode] == 0o120000 # symlink
16
+ FileUtils.symlink(content, file_path)
17
+ else
18
+ IO.write(file_path, content)
19
+ FileUtils.chmod(entry[:filemode], file_path)
20
+ end
21
+ rescue Errno::EEXIST => e
22
+ log_warning("File `#{file_path}` skipped: `#{e.message}`")
23
+ end
24
+ end
25
+ end
26
+
27
+ def sample_exist!(sample_name)
28
+ return if sample_exist?(sample_name)
29
+ raise Error::Command, code: :sample_not_exist, data: { name: sample_name, url: _samples_git_repo_url, path: _samples_dir }
30
+ end
31
+
32
+ def sample_exist?(sample_name)
33
+ _sample_list.include?(sample_name)
34
+ end
35
+
36
+ def _sample_repo_blobs_entries(sample_name)
37
+ _sample_git_repo
38
+ .blobs_entries(_sample_git_repo.latest_commit(_samples_git_repo_branch), paths: [_sample_directory(sample_name)])
39
+ .reject { |_, entry| entry[:filemode] == 0o160000 }
40
+ end
41
+
42
+ def _sample_directory(sample_name)
43
+ File.expand_path(File.join('/', _samples_dir, sample_name))[1..-1]
44
+ end
45
+
46
+ def _sample_slice_cwd(sample_name, path)
47
+ path
48
+ .reverse
49
+ .chomp(_sample_directory(sample_name).reverse)
50
+ .chomp('/')
51
+ .reverse
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,13 @@
1
+ module Dapp
2
+ class Dapp
3
+ module Command
4
+ module Sample
5
+ module List
6
+ def sample_list
7
+ _sample_list.each(&method(:puts))
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -137,7 +137,11 @@ module Dapp
137
137
  }
138
138
 
139
139
  define_method("#{stage}_checksum") do
140
- dimg.hashsum [JSON.dump(stage_config(stage)['tasks'])]
140
+ dimg.hashsum [
141
+ JSON.dump(stage_config(stage)['tasks']),
142
+ dimg.config._ansible["#{stage}_version"],
143
+ dimg.config._ansible["version"]
144
+ ]
141
145
  end
142
146
 
143
147
  define_method(stage.to_s) do |image|
@@ -4,7 +4,8 @@ module Dapp
4
4
  [:before_install, :before_setup, :install, :setup, :build_artifact].each do |stage|
5
5
  define_method("#{stage}_checksum") do
6
6
  [dimg.config._shell.public_send("_#{stage}_command"),
7
- dimg.config._shell.public_send("_#{stage}_version")].flatten
7
+ dimg.config._shell.public_send("_#{stage}_version"),
8
+ dimg.config._shell._version].flatten
8
9
  end
9
10
  define_method("#{stage}?") { !stage_empty?(stage) }
10
11
  define_method(stage.to_s) do |image|
@@ -15,6 +15,11 @@ BANNER
15
15
  description: 'Redefine resource locking timeout (in seconds)',
16
16
  proc: ->(v) { v.to_i }
17
17
 
18
+ option :kubernetes_timeout,
19
+ long: '--kubernetes-timeout TIMEOUT',
20
+ description: 'Kubernetes api-server tcp connection, read and write timeout (in seconds)',
21
+ proc: ->(v) { v.to_i }
22
+
18
23
  option :with_stages,
19
24
  long: '--with-stages',
20
25
  boolean: true
@@ -137,7 +137,12 @@ module Dapp
137
137
 
138
138
  config.context_names.
139
139
  map {|context_name|
140
- client = ::Dapp::Kube::Kubernetes::Client.new(config, context_name, "default")
140
+ client = ::Dapp::Kube::Kubernetes::Client.new(
141
+ config,
142
+ context_name,
143
+ "default",
144
+ timeout: options[:kubernetes_timeout],
145
+ )
141
146
  search_deployed_docker_images_from_kube(client)
142
147
  }.flatten.sort.uniq
143
148
  end
@@ -158,11 +163,12 @@ module Dapp
158
163
  [].tap do |arr|
159
164
  client.with_namespace(ns) do
160
165
  arr << pod_images(client)
161
- arr << cronjob_images(client)
162
- arr << daemonset_images(client)
163
166
  arr << deployment_images(client)
164
- arr << job_images(client)
165
167
  arr << replicaset_images(client)
168
+ arr << statefulset_images(client)
169
+ arr << daemonset_images(client)
170
+ arr << job_images(client)
171
+ arr << cronjob_images(client)
166
172
  arr << replicationcontroller_images(client)
167
173
  end
168
174
  end
@@ -213,6 +219,13 @@ module Dapp
213
219
  end
214
220
  end
215
221
 
222
+ # replicasets items[] spec template spec containers[] image
223
+ def statefulset_images(client)
224
+ client.statefulset_list['items'].map do |item|
225
+ item['spec']['template']['spec']['containers'].map{ |cont| cont['image'] }
226
+ end
227
+ end
228
+
216
229
  # replicationcontroller items[] spec template spec containers[] image
217
230
  def replicationcontroller_images(client)
218
231
  client.replicationcontroller_list['items'].map do |item|
@@ -488,7 +488,7 @@ module Dapp
488
488
  def repo_entries(commit, paths: include_paths_or_cwd)
489
489
  (@repo_entries ||= {})[[commit, paths]] ||= begin
490
490
  repo
491
- .entries(commit, paths: paths, exclude_paths: exclude_paths(true))
491
+ .blobs_entries(commit, paths: paths, exclude_paths: exclude_paths(true))
492
492
  .select { |_, entry| !submodule_mode?(entry[:filemode]) }
493
493
  end
494
494
  end
@@ -110,11 +110,11 @@ module Dapp
110
110
  ignore_path?(patch.delta.new_file[:path], paths: paths, exclude_paths: exclude_paths)
111
111
  end
112
112
 
113
- def entries(commit, paths: [], exclude_paths: [])
113
+ def blobs_entries(commit, paths: [], exclude_paths: [])
114
114
  [].tap do |entries|
115
- lookup_commit(commit).tree.walk(:preorder) do |root, entry|
115
+ lookup_commit(commit).tree.walk_blobs(:preorder) do |root, entry|
116
116
  fullpath = File.join(root, entry[:name]).reverse.chomp('/').reverse
117
- next if entry[:type] == :tree || ignore_path?(fullpath, paths: paths, exclude_paths: exclude_paths)
117
+ next if ignore_path?(fullpath, paths: paths, exclude_paths: exclude_paths)
118
118
  entries << [root, entry]
119
119
  end
120
120
  end
@@ -80,7 +80,7 @@ module Dapp
80
80
  dapp.log_secondary_process(dapp.t(code: 'process.git_artifact_fetch', data: { url: url }), short: true) do
81
81
  begin
82
82
  git.remotes.each { |remote| remote.fetch(credentials: _rugged_credentials) }
83
- rescue Rugged::SshError => e
83
+ rescue Rugged::SshError, Rugged::NetworkError => e
84
84
  raise Error::Rugged, code: :rugged_remote_error, data: { url: url, message: e.message.strip }
85
85
  end
86
86
  end
@@ -50,6 +50,11 @@ BANNER
50
50
  description: 'Default timeout to wait for resources to become ready, 300 seconds by default.',
51
51
  proc: proc {|v| Integer(v)}
52
52
 
53
+ option :kubernetes_timeout,
54
+ long: '--kubernetes-timeout TIMEOUT',
55
+ description: 'Kubernetes api-server tcp connection, read and write timeout (in seconds)',
56
+ proc: ->(v) { v.to_i }
57
+
53
58
  option :registry_username,
54
59
  long: '--registry-username USERNAME'
55
60
 
@@ -20,6 +20,12 @@ BANNER
20
20
  option :with_namespace,
21
21
  long: '--with-namespace',
22
22
  default: false
23
+
24
+ option :kubernetes_timeout,
25
+ long: '--kubernetes-timeout TIMEOUT',
26
+ description: 'Kubernetes api-server tcp connection, read and write timeout (in seconds)',
27
+ proc: ->(v) { v.to_i }
28
+
23
29
  end
24
30
  end
25
31
  end
@@ -8,6 +8,12 @@ Usage:
8
8
 
9
9
  Options:
10
10
  BANNER
11
+
12
+ option :kubernetes_timeout,
13
+ long: '--kubernetes-timeout TIMEOUT',
14
+ description: 'Kubernetes api-server tcp connection, read and write timeout (in seconds)',
15
+ proc: ->(v) { v.to_i }
16
+
11
17
  end
12
18
  end
13
19
  end
@@ -366,6 +366,7 @@ image: {{ tuple $name $context | include "_dimg2" }}
366
366
  kubernetes_config,
367
367
  kube_context,
368
368
  kube_namespace,
369
+ timeout: options[:kubernetes_timeout],
369
370
  )
370
371
  end
371
372
  end
@@ -217,7 +217,11 @@ module Dapp
217
217
  unless dry_run?
218
218
  begin
219
219
  ::Timeout::timeout(self.options[:timeout] || 300) do
220
- deployment_managers.each {|deployment_manager| deployment_manager.watch_till_ready!}
220
+ deployment_managers.each {|deployment_manager|
221
+ if deployment_manager.should_watch?
222
+ deployment_manager.watch_till_ready!
223
+ end
224
+ }
221
225
  end
222
226
  rescue ::Timeout::Error
223
227
  raise ::Dapp::Error::Command, code: :kube_deploy_timeout
@@ -254,7 +254,8 @@ module Dapp
254
254
  @_minikube_kubernetes ||= Kubernetes::Client.new(
255
255
  kubernetes_config,
256
256
  kubernetes_config.current_context_name,
257
- 'kube-system'
257
+ 'kube-system',
258
+ timeout: options[:kubernetes_timeout],
258
259
  )
259
260
  end
260
261
 
@@ -50,11 +50,13 @@ module Dapp
50
50
  attr_reader :config
51
51
  attr_reader :context
52
52
  attr_reader :namespace
53
+ attr_reader :timeout
53
54
 
54
- def initialize(config, context, namespace)
55
+ def initialize(config, context, namespace, timeout: nil)
55
56
  @config = config
56
57
  @context = context
57
58
  @namespace = namespace
59
+ @timeout = timeout
58
60
  @query_parameters = {}
59
61
  @cluster_version
60
62
  end
@@ -203,6 +205,16 @@ module Dapp
203
205
  # excon_parameters — соответствует connection-опциям Excon
204
206
  # body — hash для http-body, соответствует 'Body Parameters' в документации kubernetes, опционален
205
207
  def request!(method, path, body: nil, excon_parameters: {}, response_body_parameters: {}, **query_parameters)
208
+ if method == :get
209
+ excon_parameters[:idempotent] = true
210
+ excon_parameters[:retry_limit] = 6
211
+ excon_parameters[:retry_interval] = 5
212
+ end
213
+
214
+ excon_parameters[:connect_timeout] ||= timeout
215
+ excon_parameters[:read_timeout] ||= timeout
216
+ excon_parameters[:write_timeout] ||= timeout
217
+
206
218
  with_connection(excon_parameters: excon_parameters) do |conn|
207
219
  request_parameters = {method: method, path: path, query: @query_parameters.merge(query_parameters)}
208
220
  request_parameters[:body] = JSON.dump(body) if body
@@ -30,6 +30,14 @@ module Dapp
30
30
  @deployed_at = Time.now
31
31
  end
32
32
 
33
+ def should_watch?
34
+ d = Kubernetes::Client::Resource::Deployment.new(dapp.kubernetes.deployment(name))
35
+
36
+ ["dapp/watch", "dapp/watch-logs"].all? do |anno|
37
+ d.annotations[anno] != "false"
38
+ end
39
+ end
40
+
33
41
  def watch_till_ready!
34
42
  dapp.log_process("Watch deployment '#{name}' till ready") do
35
43
  known_events_by_pod = {}
data/lib/dapp/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Dapp
2
- VERSION = "0.30.2"
2
+ VERSION = "0.30.3"
3
3
  BUILD_CACHE_VERSION = 30
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.30.2
4
+ version: 0.30.3
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-06-27 00:00:00.000000000 Z
11
+ date: 2018-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-shellout
@@ -467,6 +467,10 @@ files:
467
467
  - lib/dapp/cli.rb
468
468
  - lib/dapp/cli/cli.rb
469
469
  - lib/dapp/cli/command/base.rb
470
+ - lib/dapp/cli/command/sample.rb
471
+ - lib/dapp/cli/command/sample/base.rb
472
+ - lib/dapp/cli/command/sample/create.rb
473
+ - lib/dapp/cli/command/sample/list.rb
470
474
  - lib/dapp/cli/command/slug.rb
471
475
  - lib/dapp/cli/command/update.rb
472
476
  - lib/dapp/cli/options/ssh.rb
@@ -478,6 +482,9 @@ files:
478
482
  - lib/dapp/dapp.rb
479
483
  - lib/dapp/dapp/chef.rb
480
484
  - lib/dapp/dapp/command/common.rb
485
+ - lib/dapp/dapp/command/sample/common.rb
486
+ - lib/dapp/dapp/command/sample/create.rb
487
+ - lib/dapp/dapp/command/sample/list.rb
481
488
  - lib/dapp/dapp/command/slug.rb
482
489
  - lib/dapp/dapp/dapp_config.rb
483
490
  - lib/dapp/dapp/dappfile.rb