dapp 0.0.24 → 0.1.0
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 +13 -5
- data/bin/dapp +17 -1
- data/config/en/common.yml +23 -0
- data/config/en/net_status.yml +24 -0
- data/lib/dapp.rb +68 -12
- data/lib/dapp/application.rb +57 -0
- data/lib/dapp/application/git_artifact.rb +26 -0
- data/lib/dapp/application/logging.rb +120 -0
- data/lib/dapp/application/path.rb +31 -0
- data/lib/dapp/application/tags.rb +65 -0
- data/lib/dapp/build/stage/app_install.rb +19 -0
- data/lib/dapp/build/stage/app_setup.rb +19 -0
- data/lib/dapp/build/stage/base.rb +106 -0
- data/lib/dapp/build/stage/from.rb +40 -0
- data/lib/dapp/build/stage/infra_install.rb +23 -0
- data/lib/dapp/build/stage/infra_setup.rb +19 -0
- data/lib/dapp/build/stage/source_1.rb +31 -0
- data/lib/dapp/build/stage/source_1_archive.rb +31 -0
- data/lib/dapp/build/stage/source_2.rb +20 -0
- data/lib/dapp/build/stage/source_3.rb +27 -0
- data/lib/dapp/build/stage/source_4.rb +31 -0
- data/lib/dapp/build/stage/source_5.rb +51 -0
- data/lib/dapp/build/stage/source_base.rb +109 -0
- data/lib/dapp/builder/base.rb +44 -0
- data/lib/dapp/builder/chef.rb +242 -0
- data/lib/dapp/builder/chef/berksfile.rb +54 -0
- data/lib/dapp/builder/shell.rb +16 -0
- data/lib/dapp/cli.rb +10 -44
- data/lib/dapp/cli/base.rb +55 -0
- data/lib/dapp/cli/build.rb +6 -140
- data/lib/dapp/cli/flush.rb +19 -0
- data/lib/dapp/cli/flush/build_cache.rb +26 -0
- data/lib/dapp/cli/flush/stage_cache.rb +23 -0
- data/lib/dapp/cli/list.rb +19 -0
- data/lib/dapp/cli/push.rb +59 -0
- data/lib/dapp/cli/smartpush.rb +19 -0
- data/lib/dapp/config/application.rb +98 -0
- data/lib/dapp/config/chef.rb +20 -0
- data/lib/dapp/config/docker.rb +39 -0
- data/lib/dapp/config/git_artifact.rb +78 -0
- data/lib/dapp/config/main.rb +23 -0
- data/lib/dapp/config/shell.rb +40 -0
- data/lib/dapp/controller.rb +103 -0
- data/lib/dapp/docker_image.rb +51 -0
- data/lib/dapp/error/application.rb +6 -0
- data/lib/dapp/error/base.rb +10 -0
- data/lib/dapp/error/build.rb +6 -0
- data/lib/dapp/error/config.rb +6 -0
- data/lib/dapp/error/controller.rb +6 -0
- data/lib/dapp/error/shellout.rb +6 -0
- data/lib/dapp/filelock.rb +1 -1
- data/lib/dapp/git_artifact.rb +43 -272
- data/lib/dapp/git_repo/base.rb +10 -12
- data/lib/dapp/git_repo/own.rb +7 -3
- data/lib/dapp/git_repo/remote.rb +14 -20
- data/lib/dapp/helper/cli.rb +66 -0
- data/lib/dapp/helper/i18n.rb +20 -0
- data/lib/dapp/helper/log.rb +72 -0
- data/lib/dapp/helper/paint.rb +27 -0
- data/lib/dapp/helper/sha256.rb +14 -0
- data/lib/dapp/helper/shellout.rb +41 -0
- data/lib/dapp/helper/streaming.rb +49 -0
- data/lib/dapp/helper/trivia.rb +27 -0
- data/lib/dapp/stage_image.rb +98 -0
- data/lib/dapp/version.rb +3 -1
- metadata +207 -51
- data/lib/dapp/atomizer.rb +0 -56
- data/lib/dapp/builder.rb +0 -230
- data/lib/dapp/builder/cascade_tagging.rb +0 -48
- data/lib/dapp/builder/centos7.rb +0 -47
- data/lib/dapp/builder/chefify.rb +0 -107
- data/lib/dapp/builder/ci_tagging.rb +0 -53
- data/lib/dapp/builder/git_tagging.rb +0 -21
- data/lib/dapp/builder/manual_tagging.rb +0 -22
- data/lib/dapp/builder/ubuntu1404.rb +0 -20
- data/lib/dapp/builder/ubuntu1604.rb +0 -20
- data/lib/dapp/docker.rb +0 -207
- data/lib/dapp/git_repo/chronicler.rb +0 -44
data/lib/dapp/git_repo/base.rb
CHANGED
@@ -2,22 +2,20 @@ module Dapp
|
|
2
2
|
module GitRepo
|
3
3
|
# Base class for any Git repo (remote, gitkeeper, etc)
|
4
4
|
class Base
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :application
|
6
6
|
attr_reader :name
|
7
|
-
attr_reader :su
|
8
7
|
|
9
|
-
def initialize(
|
10
|
-
@
|
8
|
+
def initialize(application, name)
|
9
|
+
@application = application
|
11
10
|
@name = name
|
12
|
-
@build_path = build_path || []
|
13
11
|
end
|
14
12
|
|
15
|
-
def
|
16
|
-
|
13
|
+
def container_build_dir_path
|
14
|
+
application.container_build_path "#{name}.git"
|
17
15
|
end
|
18
16
|
|
19
17
|
def dir_path
|
20
|
-
build_path "#{name}.git"
|
18
|
+
application.build_path "#{name}.git"
|
21
19
|
end
|
22
20
|
|
23
21
|
def git_bare(command, **kwargs)
|
@@ -28,7 +26,7 @@ module Dapp
|
|
28
26
|
Time.at Integer git_bare("show -s --format=%ct #{commit}").stdout.strip
|
29
27
|
end
|
30
28
|
|
31
|
-
def latest_commit(branch
|
29
|
+
def latest_commit(branch)
|
32
30
|
git_bare("rev-parse #{branch}").stdout.strip
|
33
31
|
end
|
34
32
|
|
@@ -39,14 +37,14 @@ module Dapp
|
|
39
37
|
def cleanup!
|
40
38
|
end
|
41
39
|
|
42
|
-
def
|
43
|
-
|
40
|
+
def branch
|
41
|
+
git_bare('rev-parse --abbrev-ref HEAD').stdout.strip
|
44
42
|
end
|
45
43
|
|
46
44
|
protected
|
47
45
|
|
48
46
|
def git(command, **kwargs)
|
49
|
-
|
47
|
+
application.shellout!("git #{command}", **kwargs)
|
50
48
|
end
|
51
49
|
end
|
52
50
|
end
|
data/lib/dapp/git_repo/own.rb
CHANGED
@@ -2,12 +2,16 @@ module Dapp
|
|
2
2
|
module GitRepo
|
3
3
|
# Own Git repo
|
4
4
|
class Own < Base
|
5
|
-
def initialize(
|
6
|
-
super(
|
5
|
+
def initialize(application)
|
6
|
+
super(application, 'own')
|
7
7
|
end
|
8
8
|
|
9
9
|
def dir_path
|
10
|
-
@dir_path ||= git("-C #{
|
10
|
+
@dir_path ||= Pathname(git("-C #{application.home_path} rev-parse --git-dir").stdout.strip).expand_path
|
11
|
+
end
|
12
|
+
|
13
|
+
def latest_commit(branch = nil)
|
14
|
+
super(branch || 'HEAD')
|
11
15
|
end
|
12
16
|
end
|
13
17
|
end
|
data/lib/dapp/git_repo/remote.rb
CHANGED
@@ -2,37 +2,31 @@ module Dapp
|
|
2
2
|
module GitRepo
|
3
3
|
# Normal Git repo
|
4
4
|
class Remote < Base
|
5
|
-
def initialize(
|
6
|
-
super(
|
5
|
+
def initialize(application, name, url:, ssh_key_path: nil)
|
6
|
+
super(application, name)
|
7
7
|
|
8
8
|
@url = url
|
9
|
-
@ssh_key_path = File.expand_path(ssh_key_path,
|
9
|
+
@ssh_key_path = File.expand_path(ssh_key_path, application.home_path) if ssh_key_path
|
10
10
|
|
11
11
|
@use_ssh_key = false
|
12
|
-
File.chmod(
|
12
|
+
File.chmod(0o600, @ssh_key_path) if @ssh_key_path
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
git "clone --bare --depth 1 #{url} #{dir_path}", log_verbose: true
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
14
|
+
with_ssh_key do
|
15
|
+
git "clone --bare --depth 1 #{url} #{dir_path}"
|
16
|
+
end unless File.directory? dir_path
|
21
17
|
end
|
22
18
|
|
23
19
|
def fetch!(branch = 'master')
|
24
|
-
|
25
|
-
|
26
|
-
git_bare "fetch origin #{branch}:#{branch}"
|
20
|
+
with_ssh_key do
|
21
|
+
application.log_secondary_process(application.t(code: 'process.git_artifact_fetch', data: { name: name }), short: true) do
|
22
|
+
git_bare "fetch origin #{branch}:#{branch}"
|
27
23
|
end
|
28
|
-
end
|
24
|
+
end unless application.ignore_git_fetch || application.dry_run?
|
29
25
|
end
|
30
26
|
|
31
27
|
def cleanup!
|
32
|
-
|
33
|
-
|
34
|
-
FileUtils.rm_rf dir_path
|
35
|
-
end
|
28
|
+
super
|
29
|
+
FileUtils.rm_rf dir_path
|
36
30
|
end
|
37
31
|
|
38
32
|
protected
|
@@ -56,7 +50,7 @@ module Dapp
|
|
56
50
|
|
57
51
|
def git(command, **kwargs)
|
58
52
|
if use_ssh_key && ssh_key_path
|
59
|
-
|
53
|
+
application.shellout!("ssh-agent bash -ec 'ssh-add #{ssh_key_path}; git #{command}'", **kwargs)
|
60
54
|
else
|
61
55
|
super
|
62
56
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Dapp
|
2
|
+
module Helper
|
3
|
+
# Cli
|
4
|
+
module Cli
|
5
|
+
def parse_options(cli, argv)
|
6
|
+
cli.parse_options(argv)
|
7
|
+
rescue OptionParser::MissingArgument, OptionParser::InvalidOption, OptionParser::InvalidArgument => e
|
8
|
+
STDERR.puts "Error: #{e.message}"
|
9
|
+
puts cli.opt_parser
|
10
|
+
exit 1
|
11
|
+
end
|
12
|
+
|
13
|
+
def required_argument(cli)
|
14
|
+
unless (arg = cli.cli_arguments.pop)
|
15
|
+
puts cli.opt_parser
|
16
|
+
exit 1
|
17
|
+
end
|
18
|
+
arg
|
19
|
+
end
|
20
|
+
|
21
|
+
# rubocop:disable Metrics/MethodLength
|
22
|
+
def parse_subcommand(cli, args)
|
23
|
+
argv = args
|
24
|
+
divided_subcommand = []
|
25
|
+
subcommand_argv = []
|
26
|
+
|
27
|
+
cmd_arr = args.dup
|
28
|
+
loop do
|
29
|
+
if cli.class::SUBCOMMANDS.include? cmd_arr.join(' ')
|
30
|
+
argv = args[0...args.index(cmd_arr.first)]
|
31
|
+
divided_subcommand = cmd_arr
|
32
|
+
index = cmd_arr.one? ? args.index(cmd_arr.first).next : args.index(cmd_arr.last).next
|
33
|
+
subcommand_argv = args[index..-1]
|
34
|
+
elsif !cmd_arr.empty?
|
35
|
+
cmd_arr.pop
|
36
|
+
next
|
37
|
+
end
|
38
|
+
break
|
39
|
+
end
|
40
|
+
|
41
|
+
[argv, divided_subcommand, subcommand_argv]
|
42
|
+
end
|
43
|
+
# rubocop:enable Metrics/MethodLength
|
44
|
+
|
45
|
+
def run_subcommand(cli, divided_subcommand, subcommand_argv)
|
46
|
+
if !divided_subcommand.empty?
|
47
|
+
cli.class.const_get(prepare_subcommand(divided_subcommand)).new.run(subcommand_argv)
|
48
|
+
else
|
49
|
+
STDERR.puts 'Error: subcommand not passed'
|
50
|
+
puts
|
51
|
+
puts cli.opt_parser
|
52
|
+
exit 1
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def prepare_subcommand(divided_subcommand)
|
57
|
+
Array(divided_subcommand).map(&:capitalize).join
|
58
|
+
end
|
59
|
+
|
60
|
+
def composite_options(opt)
|
61
|
+
@composite_options ||= {}
|
62
|
+
@composite_options[opt] ||= []
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end # Helper
|
66
|
+
end # Dapp
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Dapp
|
2
|
+
module Helper
|
3
|
+
# I18n
|
4
|
+
module I18n
|
5
|
+
def self.initialize
|
6
|
+
::I18n.load_path << Dir[File.join(Dapp.root, 'config', '**', '*')].select { |path| File.file?(path) }
|
7
|
+
::I18n.reload!
|
8
|
+
::I18n.locale = :en
|
9
|
+
end
|
10
|
+
|
11
|
+
def t(context: nil, **desc)
|
12
|
+
code = desc[:code]
|
13
|
+
data = desc[:data] || {}
|
14
|
+
::I18n.t [:common, context, code].join('.'), [:common, code].join('.'), **data, raise: true
|
15
|
+
rescue ::I18n::MissingTranslationData => _e
|
16
|
+
raise NetStatus::Exception, code: :missing_translation, data: { code: code }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end # Helper
|
20
|
+
end # Dapp
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Dapp
|
2
|
+
module Helper
|
3
|
+
# Log
|
4
|
+
module Log
|
5
|
+
def log_info(message, *args)
|
6
|
+
log(message, *args, style: :info)
|
7
|
+
end
|
8
|
+
|
9
|
+
def log_step(message, *args)
|
10
|
+
log(message, *args, style: :step)
|
11
|
+
end
|
12
|
+
|
13
|
+
def log_secondary(message, *args)
|
14
|
+
log(message, *args, style: :secondary)
|
15
|
+
end
|
16
|
+
|
17
|
+
def log(message = '', desc: nil, inline: false, **kwargs)
|
18
|
+
return unless defined?(cli_options) && !cli_options[:log_quiet]
|
19
|
+
unless desc.nil?
|
20
|
+
(desc[:data] ||= {})[:msg] = message
|
21
|
+
message = t(desc: desc)
|
22
|
+
end
|
23
|
+
print "#{log_format_string(message, **kwargs)}#{"\n" unless inline}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def log_time
|
27
|
+
"#{DateTime.now.strftime('%Y-%m-%dT%T%z')} "
|
28
|
+
end
|
29
|
+
|
30
|
+
def log_format_string(str, time: true, indent: true, style: nil)
|
31
|
+
str.to_s.lines.map do |line|
|
32
|
+
line = paint_string(line, style) if style
|
33
|
+
"#{log_time if time && cli_options[:log_time]}#{indent ? (log_indent + line) : line}"
|
34
|
+
end.join
|
35
|
+
end
|
36
|
+
|
37
|
+
def log_with_indent(message = '', **kvargs)
|
38
|
+
with_log_indent do
|
39
|
+
log(message, **kvargs)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def with_log_indent(with = true)
|
44
|
+
log_indent_next if with
|
45
|
+
yield
|
46
|
+
log_indent_prev if with
|
47
|
+
end
|
48
|
+
|
49
|
+
def log_indent
|
50
|
+
' ' * 2 * cli_options[:log_indent].to_i
|
51
|
+
end
|
52
|
+
|
53
|
+
def log_indent_next
|
54
|
+
return unless defined? cli_options
|
55
|
+
cli_options[:log_indent] += 1
|
56
|
+
end
|
57
|
+
|
58
|
+
def log_indent_prev
|
59
|
+
return unless defined? cli_options
|
60
|
+
if cli_options[:log_indent] <= 0
|
61
|
+
cli_options[:log_indent] = 0
|
62
|
+
else
|
63
|
+
cli_options[:log_indent] -= 1
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.included(base)
|
68
|
+
base.include(Paint)
|
69
|
+
end
|
70
|
+
end # Log
|
71
|
+
end # Helper
|
72
|
+
end # Dapp
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Dapp
|
2
|
+
module Helper
|
3
|
+
# Paint
|
4
|
+
module Paint
|
5
|
+
FORMAT = {
|
6
|
+
step: [:yellow, :bold],
|
7
|
+
info: [:blue],
|
8
|
+
success: [:green, :bold],
|
9
|
+
warning: [:red, :bold],
|
10
|
+
secondary: [:white, :bold],
|
11
|
+
default: [:white]
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
def paint_style(name)
|
15
|
+
FORMAT[name].tap do |format|
|
16
|
+
fail if format.nil?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def paint_string(object, style_name)
|
21
|
+
::Paint[::Paint.unpaint(object.to_s), *paint_style(style_name)]
|
22
|
+
end
|
23
|
+
end # Paint
|
24
|
+
end # Helper
|
25
|
+
end # Dapp
|
26
|
+
|
27
|
+
Dapp::Helper::Paint.extend Dapp::Helper::Paint
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Dapp
|
2
|
+
module Helper
|
3
|
+
# Shellout
|
4
|
+
module Shellout
|
5
|
+
include Streaming
|
6
|
+
|
7
|
+
def shellout(*args, log_verbose: false, **kwargs)
|
8
|
+
do_shellout = proc do
|
9
|
+
log_verbose = (log_verbose && cli_options[:log_verbose]) if defined? cli_options
|
10
|
+
kwargs[:live_stream] ||= STDOUT if log_verbose
|
11
|
+
::Mixlib::ShellOut.new(*args, timeout: 3600, **kwargs).run_command
|
12
|
+
end
|
13
|
+
|
14
|
+
if defined? ::Bundler
|
15
|
+
::Bundler.with_clean_env { do_shellout.call }
|
16
|
+
else
|
17
|
+
do_shellout.call
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def shellout!(*args, log_verbose: false, log_time: false, **kwargs)
|
22
|
+
stream = Stream.new
|
23
|
+
log_time = defined?(cli_options) ? cli_options[:log_time] : log_time
|
24
|
+
if log_verbose
|
25
|
+
kwargs[:live_stream] = Proxy::Base.new(stream, STDOUT, with_time: log_time)
|
26
|
+
else
|
27
|
+
kwargs[:live_stdout] = Proxy::Base.new(stream, with_time: log_time)
|
28
|
+
end
|
29
|
+
kwargs[:live_stderr] = Proxy::Error.new(stream, with_time: log_time)
|
30
|
+
shellout(*args, **kwargs).tap(&:error!)
|
31
|
+
rescue ::Mixlib::ShellOut::ShellCommandFailed => e
|
32
|
+
raise Error::Shellout, code: Trivia.class_to_lowercase(e.class),
|
33
|
+
data: { stream: stream.inspect }
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.included(base)
|
37
|
+
base.extend(self)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end # Helper
|
41
|
+
end # Dapp
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Dapp
|
2
|
+
module Helper
|
3
|
+
# Streaming
|
4
|
+
module Streaming
|
5
|
+
# Stream
|
6
|
+
class Stream
|
7
|
+
def buffer
|
8
|
+
@buffer ||= []
|
9
|
+
end
|
10
|
+
|
11
|
+
def <<(string)
|
12
|
+
buffer << string
|
13
|
+
end
|
14
|
+
|
15
|
+
def inspect
|
16
|
+
buffer.join
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Proxy
|
21
|
+
module Proxy
|
22
|
+
# Base
|
23
|
+
class Base
|
24
|
+
include Helper::Log
|
25
|
+
|
26
|
+
def initialize(*streams, with_time: false)
|
27
|
+
@streams = streams
|
28
|
+
@with_time = with_time
|
29
|
+
end
|
30
|
+
|
31
|
+
def <<(str)
|
32
|
+
@streams.each { |s| s << format_string(str) }
|
33
|
+
end
|
34
|
+
|
35
|
+
def format_string(str)
|
36
|
+
str.lines.map { |l| "#{log_time if @with_time}#{l.strip}\n" }.join
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Error
|
41
|
+
class Error < Base
|
42
|
+
def format_string(str)
|
43
|
+
Paint.paint_string(super, :warning)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end # Helper
|
49
|
+
end # Dapp
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Dapp
|
2
|
+
module Helper
|
3
|
+
# Trivia
|
4
|
+
module Trivia
|
5
|
+
def kwargs(args)
|
6
|
+
args.last.is_a?(Hash) ? args.pop : {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def class_to_lowercase(class_name = self.class)
|
10
|
+
Trivia.class_to_lowercase(class_name)
|
11
|
+
end
|
12
|
+
|
13
|
+
def delete_file(path)
|
14
|
+
path = Pathname(path)
|
15
|
+
path.delete if path.exist?
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_mb(bytes)
|
19
|
+
(bytes / 1024.0 / 1024.0).round(2)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.class_to_lowercase(class_name = self.class)
|
23
|
+
class_name.to_s.split('::').last.split(/(?=[[:upper:]]|[0-9])/).join('_').downcase.to_s
|
24
|
+
end
|
25
|
+
end # Trivia
|
26
|
+
end # Helper
|
27
|
+
end # Dapp
|