dapp 0.22.1 → 0.22.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dapp.rb +3 -0
- data/lib/dapp/cli.rb +2 -1
- data/lib/dapp/cli/command/base.rb +13 -4
- data/lib/dapp/cli/command/slug.rb +22 -0
- data/lib/dapp/cli/command/update.rb +11 -1
- data/lib/dapp/dapp.rb +15 -10
- data/lib/dapp/dapp/command/slug.rb +11 -0
- data/lib/dapp/dapp/option_tags.rb +3 -0
- data/lib/dapp/dapp/slug.rb +25 -0
- data/lib/dapp/dimg/build/stage/base.rb +1 -1
- data/lib/dapp/dimg/cli/command/dimg/cleanup_repo.rb +4 -0
- data/lib/dapp/dimg/dapp/command/cleanup_repo.rb +24 -2
- data/lib/dapp/dimg/image/argument.rb +7 -2
- data/lib/dapp/dimg/image/stage.rb +0 -6
- data/lib/dapp/helper/cli.rb +9 -8
- data/lib/dapp/kube/dapp/command/common.rb +5 -1
- data/lib/dapp/kube/dapp/command/deploy.rb +10 -2
- data/lib/dapp/kube/dapp/command/dismiss.rb +7 -5
- data/lib/dapp/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6772c46b21f3e433f04fb8c2c1d3ebc12cd48d41783c70751ba2eb90ae8dc0d5
|
4
|
+
data.tar.gz: f4a098cc19c7357ec473d3167b6b793d1e6197a6592e4abdca449a6d78674273
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10534955c4393d6241001a96d90e20bc667f6ae09a5d4a1a2f4a15caced9b928646d53aa53598ac0c5132559305546a7f802548e30156a7ad5a24f967d70f111
|
7
|
+
data.tar.gz: 01cf0cbf46224eb0c5b95269e681fe5e73703a0a216f3f898faaa5d5471bc6c536fd396caa1fbee873d81f9e606679028849fc3b01e290dcb6ca9094e20ca219
|
data/lib/dapp.rb
CHANGED
@@ -43,6 +43,7 @@ require 'dapp/exception/base'
|
|
43
43
|
require 'dapp/cli'
|
44
44
|
require 'dapp/cli/command/base'
|
45
45
|
require 'dapp/cli/command/update'
|
46
|
+
require 'dapp/cli/command/slug'
|
46
47
|
require 'dapp/cli/cli'
|
47
48
|
require 'dapp/config/directive/base'
|
48
49
|
require 'dapp/config/config'
|
@@ -54,6 +55,7 @@ require 'dapp/dapp/dappfile'
|
|
54
55
|
require 'dapp/dapp/chef'
|
55
56
|
require 'dapp/dapp/dapp_config'
|
56
57
|
require 'dapp/dapp/option_tags'
|
58
|
+
require 'dapp/dapp/slug'
|
57
59
|
require 'dapp/dapp/logging/base'
|
58
60
|
require 'dapp/dapp/logging/process'
|
59
61
|
require 'dapp/dapp/logging/paint'
|
@@ -64,6 +66,7 @@ require 'dapp/dapp/deps/gitartifact'
|
|
64
66
|
require 'dapp/dapp/shellout/streaming'
|
65
67
|
require 'dapp/dapp/shellout/base'
|
66
68
|
require 'dapp/dapp/command/common'
|
69
|
+
require 'dapp/dapp/command/slug'
|
67
70
|
require 'dapp/dapp'
|
68
71
|
require 'dapp/deployment'
|
69
72
|
require 'dapp/deployment/config/directive/mod/group'
|
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', 'deployment', 'kube', 'update'].freeze
|
8
|
+
SUBCOMMANDS = ['dimg', 'deployment', 'kube', 'update', 'slug'].freeze
|
9
9
|
|
10
10
|
banner <<BANNER.freeze
|
11
11
|
Usage: dapp subcommand [subcommand options]
|
@@ -16,6 +16,7 @@ Available subcommands: (for details, dapp SUB-COMMAND --help)
|
|
16
16
|
dapp deployment
|
17
17
|
dapp kube
|
18
18
|
dapp update
|
19
|
+
dapp slug STRING
|
19
20
|
|
20
21
|
Options:
|
21
22
|
BANNER
|
@@ -7,9 +7,13 @@ module Dapp
|
|
7
7
|
description: 'Change to directory',
|
8
8
|
on: :head
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
%w(run_dir build_dir deploy_dir).tap do |dirs|
|
11
|
+
dirs.each do |dir|
|
12
|
+
option dir.to_sym,
|
13
|
+
long: "--#{dir.gsub("_", "-")} PATH",
|
14
|
+
description: "Directory where reside: build cache, lock files for concurrent dapp operations (DIR/.dapp_build by default). Alias for #{(dirs - [dir]).map{|d| "--" + d.gsub("_", "-")}.join(", ")}."
|
15
|
+
end
|
16
|
+
end
|
13
17
|
|
14
18
|
option :name,
|
15
19
|
long: "--name NAME",
|
@@ -88,7 +92,12 @@ module Dapp
|
|
88
92
|
end
|
89
93
|
|
90
94
|
def cli_options(**kwargs)
|
91
|
-
config
|
95
|
+
dirs = [config[:build_dir], config[:run_dir], config[:deploy_dir]]
|
96
|
+
if dirs.compact.size > 1
|
97
|
+
self.class.print_error_with_help_and_die! self, "cannot use alias options --run-dir, --build-dir, --deploy-dir at the same time"
|
98
|
+
end
|
99
|
+
|
100
|
+
config.merge(build_dir: dirs.compact.first, **kwargs)
|
92
101
|
end
|
93
102
|
end
|
94
103
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Dapp
|
2
|
+
class CLI
|
3
|
+
module Command
|
4
|
+
class Slug < Base
|
5
|
+
banner <<BANNER.freeze
|
6
|
+
Usage:
|
7
|
+
|
8
|
+
dapp slug STRING
|
9
|
+
|
10
|
+
Options:
|
11
|
+
BANNER
|
12
|
+
def run(argv = ARGV)
|
13
|
+
self.class.parse_options(self, argv)
|
14
|
+
str = self.class.required_argument(self, 'string')
|
15
|
+
run_dapp_command(nil, options: cli_options, log_running_time: false) do |dapp|
|
16
|
+
dapp.slug([cli_arguments, str].flatten.join(' '))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -2,7 +2,17 @@ module Dapp
|
|
2
2
|
class CLI
|
3
3
|
module Command
|
4
4
|
class Update < ::Dapp::CLI
|
5
|
-
|
5
|
+
banner <<BANNER.freeze
|
6
|
+
Usage:
|
7
|
+
|
8
|
+
dapp update
|
9
|
+
|
10
|
+
Options:
|
11
|
+
BANNER
|
12
|
+
|
13
|
+
def run(argv = ARGV)
|
14
|
+
self.class.parse_options(self, argv)
|
15
|
+
|
6
16
|
spec = Gem::Specification.find do |s|
|
7
17
|
File.fnmatch?(File.join(s.full_gem_path, '**', '*'), __FILE__, File::FNM_PATHNAME)
|
8
18
|
end
|
data/lib/dapp/dapp.rb
CHANGED
@@ -6,8 +6,10 @@ module Dapp
|
|
6
6
|
include Chef
|
7
7
|
include DappConfig
|
8
8
|
include OptionTags
|
9
|
+
include Slug
|
9
10
|
|
10
11
|
include Command::Common
|
12
|
+
include Command::Slug
|
11
13
|
|
12
14
|
include Logging::Base
|
13
15
|
include Logging::Process
|
@@ -41,17 +43,20 @@ module Dapp
|
|
41
43
|
|
42
44
|
def name
|
43
45
|
@name ||= begin
|
44
|
-
|
45
|
-
name
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
46
|
+
n = begin
|
47
|
+
if (name = options[:name])
|
48
|
+
name
|
49
|
+
elsif git_url
|
50
|
+
repo_name = git_url.split('/').last
|
51
|
+
repo_name = repo_name[/.*(?=\.git)/] if repo_name.end_with? '.git'
|
52
|
+
repo_name
|
53
|
+
elsif git_path
|
54
|
+
File.basename(File.dirname(git_path)).to_s
|
55
|
+
else
|
56
|
+
path.basename.to_s
|
57
|
+
end
|
54
58
|
end
|
59
|
+
consistent_uniq_slugify(n)
|
55
60
|
end
|
56
61
|
end
|
57
62
|
|
@@ -14,6 +14,9 @@ module Dapp
|
|
14
14
|
[simple_tags, branch_tags, commit_tags, build_tags, ci_tags].reduce({}) do |some_tags_by_scheme, tags_by_scheme|
|
15
15
|
tags_by_scheme.in_depth_merge(some_tags_by_scheme)
|
16
16
|
end.tap do |tags_by_scheme|
|
17
|
+
[:git_branch, :git_tag].each do |scheme|
|
18
|
+
tags_by_scheme[scheme].map!(&method(:consistent_uniq_slugify)) unless tags_by_scheme[scheme].nil?
|
19
|
+
end
|
17
20
|
tags_by_scheme[:custom] = [:latest] if tags_by_scheme.values.flatten.empty?
|
18
21
|
end
|
19
22
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Dapp
|
2
|
+
class Dapp
|
3
|
+
module Slug
|
4
|
+
def consistent_uniq_slugify(s)
|
5
|
+
if should_be_slugged?(s)
|
6
|
+
consistent_uniq_slug_reg =~ s.slugify.squeeze('--')
|
7
|
+
[].tap do |slug|
|
8
|
+
slug << Regexp.last_match(1) unless Regexp.last_match(1).nil?
|
9
|
+
slug << MurmurHash3::V32.str_hexdigest(s)
|
10
|
+
end.compact.join('-')
|
11
|
+
else
|
12
|
+
s
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def should_be_slugged?(s)
|
17
|
+
!(/^#{consistent_uniq_slug_reg}$/ =~ s)
|
18
|
+
end
|
19
|
+
|
20
|
+
def consistent_uniq_slug_reg
|
21
|
+
/(?!-)((-?[a-z0-9]+)+)(?<!-)/
|
22
|
+
end
|
23
|
+
end # Slug
|
24
|
+
end # Dapp
|
25
|
+
end # Dapp
|
@@ -247,7 +247,7 @@ module Dapp
|
|
247
247
|
end
|
248
248
|
|
249
249
|
def image_should_be_prepared?
|
250
|
-
(!image.built? && !should_be_not_present? || image_should_be_introspected?) && !dimg.dapp.dry_run?
|
250
|
+
(!image.built? && !should_be_not_present? || image_should_be_introspected? && image.tagged?) && !dimg.dapp.dry_run?
|
251
251
|
end
|
252
252
|
|
253
253
|
def should_be_renewed?
|
@@ -42,8 +42,8 @@ module Dapp
|
|
42
42
|
cleanup_repo_by_nonexistent_git_base(detailed_dimgs_images_by_scheme, scheme) do |detailed_dimg_image|
|
43
43
|
delete_repo_image(registry, detailed_dimg_image) unless begin
|
44
44
|
case scheme
|
45
|
-
when 'git_tag' then
|
46
|
-
when 'git_branch' then
|
45
|
+
when 'git_tag' then consistent_git_tags.include?(detailed_dimg_image[:tag])
|
46
|
+
when 'git_branch' then consistent_git_remote_branches.include?(detailed_dimg_image[:tag])
|
47
47
|
when 'git_commit' then git_local_repo.commit_exists?(detailed_dimg_image[:tag])
|
48
48
|
else
|
49
49
|
raise
|
@@ -53,6 +53,14 @@ module Dapp
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
+
def consistent_git_tags
|
57
|
+
git_tag_by_consistent_tag_name.keys
|
58
|
+
end
|
59
|
+
|
60
|
+
def consistent_git_remote_branches
|
61
|
+
@consistent_git_remote_branches ||= git_local_repo.remote_branches.map(&method(:consistent_uniq_slugify))
|
62
|
+
end
|
63
|
+
|
56
64
|
def cleanup_repo_by_nonexistent_git_base(repo_dimgs_images_by_scheme, dapp_tag_scheme)
|
57
65
|
return if repo_dimgs_images_by_scheme[dapp_tag_scheme].empty?
|
58
66
|
log_step_with_indent(:"nonexistent #{dapp_tag_scheme.split('_').join(' ')}") do
|
@@ -98,6 +106,14 @@ module Dapp
|
|
98
106
|
end
|
99
107
|
end
|
100
108
|
|
109
|
+
def git_tag_by_consistent_git_tag(consistent_git_tag)
|
110
|
+
git_tag_by_consistent_tag_name[consistent_git_tag]
|
111
|
+
end
|
112
|
+
|
113
|
+
def git_tag_by_consistent_tag_name
|
114
|
+
@git_consistent_tags ||= git_local_repo.tags.map { |t| [consistent_uniq_slugify(t), t] }.to_h
|
115
|
+
end
|
116
|
+
|
101
117
|
def repo_detailed_dimgs_images(registry)
|
102
118
|
repo_dimgs_images(registry).each do |dimg|
|
103
119
|
image_history = registry.image_history(dimg[:tag], dimg[:dimg])
|
@@ -107,6 +123,8 @@ module Dapp
|
|
107
123
|
end
|
108
124
|
|
109
125
|
def deployed_docker_images
|
126
|
+
return [] if without_kube?
|
127
|
+
|
110
128
|
# open kube client, get all pods and select containers' images
|
111
129
|
::Dapp::Kube::Kubernetes::Client.tap do |kube|
|
112
130
|
config_file = kube.kube_config_path
|
@@ -138,6 +156,10 @@ module Dapp
|
|
138
156
|
image.start_with?(option_repo)
|
139
157
|
end
|
140
158
|
end
|
159
|
+
|
160
|
+
def without_kube?
|
161
|
+
!!options[:without_kube]
|
162
|
+
end
|
141
163
|
end
|
142
164
|
end
|
143
165
|
end
|
@@ -110,7 +110,7 @@ module Dapp
|
|
110
110
|
end
|
111
111
|
|
112
112
|
def all_options
|
113
|
-
service_options.
|
113
|
+
service_options.in_depth_merge(options)
|
114
114
|
end
|
115
115
|
|
116
116
|
def all_bash_commands
|
@@ -118,7 +118,12 @@ module Dapp
|
|
118
118
|
end
|
119
119
|
|
120
120
|
def service_options
|
121
|
-
{
|
121
|
+
{
|
122
|
+
entrypoint: dapp.bash_bin,
|
123
|
+
name: container_name,
|
124
|
+
user: '0:0',
|
125
|
+
:'volumes-from' => [dapp.base_container, dapp.toolchain_container]
|
126
|
+
}
|
122
127
|
end
|
123
128
|
|
124
129
|
def prepared_change
|
@@ -22,18 +22,12 @@ module Dapp
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def build!
|
25
|
-
add_build_service_volumes
|
26
25
|
run!
|
27
26
|
@built_id = commit!
|
28
27
|
ensure
|
29
28
|
dapp.shellout("#{dapp.host_docker} rm #{container_name}")
|
30
29
|
end
|
31
30
|
|
32
|
-
def add_build_service_volumes
|
33
|
-
add_volumes_from dapp.toolchain_container
|
34
|
-
add_volumes_from dapp.base_container
|
35
|
-
end
|
36
|
-
|
37
31
|
def built?
|
38
32
|
!built_id.nil?
|
39
33
|
end
|
data/lib/dapp/helper/cli.rb
CHANGED
@@ -10,22 +10,23 @@ module Dapp
|
|
10
10
|
def cli_wrapper(cli)
|
11
11
|
yield
|
12
12
|
rescue OptionParser::MissingArgument, OptionParser::InvalidOption, OptionParser::InvalidArgument, OptionParser::AmbiguousOption => e
|
13
|
-
|
14
|
-
puts
|
15
|
-
puts cli.opt_parser
|
16
|
-
exit 1
|
13
|
+
print_error_with_help_and_die!(cli, e.message)
|
17
14
|
end
|
18
15
|
|
19
16
|
def required_argument(cli, argument)
|
20
17
|
unless (arg = cli.cli_arguments.pop)
|
21
|
-
|
22
|
-
puts
|
23
|
-
puts cli.opt_parser
|
24
|
-
exit 1
|
18
|
+
print_error_with_help_and_die!(cli, "required argument `#{argument.upcase}`")
|
25
19
|
end
|
26
20
|
arg
|
27
21
|
end
|
28
22
|
|
23
|
+
def print_error_with_help_and_die!(cli, error_message)
|
24
|
+
STDERR.puts "Error: #{error_message}"
|
25
|
+
puts
|
26
|
+
puts cli.opt_parser
|
27
|
+
exit 1
|
28
|
+
end
|
29
|
+
|
29
30
|
def parse_subcommand(cli, args)
|
30
31
|
argv = args
|
31
32
|
divided_subcommand = []
|
@@ -3,6 +3,10 @@ module Dapp
|
|
3
3
|
module Dapp
|
4
4
|
module Command
|
5
5
|
module Common
|
6
|
+
def lock_helm_release(&blk)
|
7
|
+
lock("helm_release.#{kube_release_name}", &blk)
|
8
|
+
end
|
9
|
+
|
6
10
|
def helm_release
|
7
11
|
kube_check_helm!
|
8
12
|
kube_check_helm_template_plugin!
|
@@ -260,7 +264,7 @@ image: {{ tuple $name $context | include "_dimg2" }}
|
|
260
264
|
end
|
261
265
|
|
262
266
|
def kube_release_name
|
263
|
-
"#{name}-#{kube_namespace}"
|
267
|
+
consistent_uniq_slugify("#{name}-#{kube_namespace}")
|
264
268
|
end
|
265
269
|
|
266
270
|
{ encode: :generate, decode: :extract }.each do |type, secret_method|
|
@@ -5,8 +5,16 @@ module Dapp
|
|
5
5
|
module Deploy
|
6
6
|
def kube_deploy
|
7
7
|
helm_release do |release|
|
8
|
-
|
9
|
-
|
8
|
+
do_deploy = proc do
|
9
|
+
kube_flush_hooks_jobs(release)
|
10
|
+
kube_run_deploy(release)
|
11
|
+
end
|
12
|
+
|
13
|
+
if dry_run?
|
14
|
+
do_deploy.call
|
15
|
+
else
|
16
|
+
lock_helm_release &do_deploy
|
17
|
+
end
|
10
18
|
end
|
11
19
|
end
|
12
20
|
|
@@ -4,11 +4,13 @@ module Dapp
|
|
4
4
|
module Command
|
5
5
|
module Dismiss
|
6
6
|
def kube_dismiss
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
lock_helm_release do
|
8
|
+
kube_check_helm!
|
9
|
+
kube_check_helm_release!
|
10
|
+
log_process("Delete release #{kube_release_name}") do
|
11
|
+
shellout! "helm delete #{kube_release_name} --purge"
|
12
|
+
kubernetes.delete_namespace!(kube_namespace) if options[:with_namespace]
|
13
|
+
end
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
data/lib/dapp/version.rb
CHANGED
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.
|
4
|
+
version: 0.22.2
|
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-12-
|
11
|
+
date: 2017-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mixlib-shellout
|
@@ -425,6 +425,7 @@ files:
|
|
425
425
|
- lib/dapp/cli.rb
|
426
426
|
- lib/dapp/cli/cli.rb
|
427
427
|
- lib/dapp/cli/command/base.rb
|
428
|
+
- lib/dapp/cli/command/slug.rb
|
428
429
|
- lib/dapp/cli/command/update.rb
|
429
430
|
- lib/dapp/config/config.rb
|
430
431
|
- lib/dapp/config/directive/base.rb
|
@@ -434,6 +435,7 @@ files:
|
|
434
435
|
- lib/dapp/dapp.rb
|
435
436
|
- lib/dapp/dapp/chef.rb
|
436
437
|
- lib/dapp/dapp/command/common.rb
|
438
|
+
- lib/dapp/dapp/command/slug.rb
|
437
439
|
- lib/dapp/dapp/dapp_config.rb
|
438
440
|
- lib/dapp/dapp/dappfile.rb
|
439
441
|
- lib/dapp/dapp/deps/base.rb
|
@@ -448,6 +450,7 @@ files:
|
|
448
450
|
- lib/dapp/dapp/option_tags.rb
|
449
451
|
- lib/dapp/dapp/shellout/base.rb
|
450
452
|
- lib/dapp/dapp/shellout/streaming.rb
|
453
|
+
- lib/dapp/dapp/slug.rb
|
451
454
|
- lib/dapp/dapp/ssh_agent.rb
|
452
455
|
- lib/dapp/deployment.rb
|
453
456
|
- lib/dapp/deployment/app.rb
|