dapp 0.0.24 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +13 -5
  2. data/bin/dapp +17 -1
  3. data/config/en/common.yml +23 -0
  4. data/config/en/net_status.yml +24 -0
  5. data/lib/dapp.rb +68 -12
  6. data/lib/dapp/application.rb +57 -0
  7. data/lib/dapp/application/git_artifact.rb +26 -0
  8. data/lib/dapp/application/logging.rb +120 -0
  9. data/lib/dapp/application/path.rb +31 -0
  10. data/lib/dapp/application/tags.rb +65 -0
  11. data/lib/dapp/build/stage/app_install.rb +19 -0
  12. data/lib/dapp/build/stage/app_setup.rb +19 -0
  13. data/lib/dapp/build/stage/base.rb +106 -0
  14. data/lib/dapp/build/stage/from.rb +40 -0
  15. data/lib/dapp/build/stage/infra_install.rb +23 -0
  16. data/lib/dapp/build/stage/infra_setup.rb +19 -0
  17. data/lib/dapp/build/stage/source_1.rb +31 -0
  18. data/lib/dapp/build/stage/source_1_archive.rb +31 -0
  19. data/lib/dapp/build/stage/source_2.rb +20 -0
  20. data/lib/dapp/build/stage/source_3.rb +27 -0
  21. data/lib/dapp/build/stage/source_4.rb +31 -0
  22. data/lib/dapp/build/stage/source_5.rb +51 -0
  23. data/lib/dapp/build/stage/source_base.rb +109 -0
  24. data/lib/dapp/builder/base.rb +44 -0
  25. data/lib/dapp/builder/chef.rb +242 -0
  26. data/lib/dapp/builder/chef/berksfile.rb +54 -0
  27. data/lib/dapp/builder/shell.rb +16 -0
  28. data/lib/dapp/cli.rb +10 -44
  29. data/lib/dapp/cli/base.rb +55 -0
  30. data/lib/dapp/cli/build.rb +6 -140
  31. data/lib/dapp/cli/flush.rb +19 -0
  32. data/lib/dapp/cli/flush/build_cache.rb +26 -0
  33. data/lib/dapp/cli/flush/stage_cache.rb +23 -0
  34. data/lib/dapp/cli/list.rb +19 -0
  35. data/lib/dapp/cli/push.rb +59 -0
  36. data/lib/dapp/cli/smartpush.rb +19 -0
  37. data/lib/dapp/config/application.rb +98 -0
  38. data/lib/dapp/config/chef.rb +20 -0
  39. data/lib/dapp/config/docker.rb +39 -0
  40. data/lib/dapp/config/git_artifact.rb +78 -0
  41. data/lib/dapp/config/main.rb +23 -0
  42. data/lib/dapp/config/shell.rb +40 -0
  43. data/lib/dapp/controller.rb +103 -0
  44. data/lib/dapp/docker_image.rb +51 -0
  45. data/lib/dapp/error/application.rb +6 -0
  46. data/lib/dapp/error/base.rb +10 -0
  47. data/lib/dapp/error/build.rb +6 -0
  48. data/lib/dapp/error/config.rb +6 -0
  49. data/lib/dapp/error/controller.rb +6 -0
  50. data/lib/dapp/error/shellout.rb +6 -0
  51. data/lib/dapp/filelock.rb +1 -1
  52. data/lib/dapp/git_artifact.rb +43 -272
  53. data/lib/dapp/git_repo/base.rb +10 -12
  54. data/lib/dapp/git_repo/own.rb +7 -3
  55. data/lib/dapp/git_repo/remote.rb +14 -20
  56. data/lib/dapp/helper/cli.rb +66 -0
  57. data/lib/dapp/helper/i18n.rb +20 -0
  58. data/lib/dapp/helper/log.rb +72 -0
  59. data/lib/dapp/helper/paint.rb +27 -0
  60. data/lib/dapp/helper/sha256.rb +14 -0
  61. data/lib/dapp/helper/shellout.rb +41 -0
  62. data/lib/dapp/helper/streaming.rb +49 -0
  63. data/lib/dapp/helper/trivia.rb +27 -0
  64. data/lib/dapp/stage_image.rb +98 -0
  65. data/lib/dapp/version.rb +3 -1
  66. metadata +207 -51
  67. data/lib/dapp/atomizer.rb +0 -56
  68. data/lib/dapp/builder.rb +0 -230
  69. data/lib/dapp/builder/cascade_tagging.rb +0 -48
  70. data/lib/dapp/builder/centos7.rb +0 -47
  71. data/lib/dapp/builder/chefify.rb +0 -107
  72. data/lib/dapp/builder/ci_tagging.rb +0 -53
  73. data/lib/dapp/builder/git_tagging.rb +0 -21
  74. data/lib/dapp/builder/manual_tagging.rb +0 -22
  75. data/lib/dapp/builder/ubuntu1404.rb +0 -20
  76. data/lib/dapp/builder/ubuntu1604.rb +0 -20
  77. data/lib/dapp/docker.rb +0 -207
  78. data/lib/dapp/git_repo/chronicler.rb +0 -44
@@ -3,9 +3,7 @@ require 'mixlib/cli'
3
3
  module Dapp
4
4
  class CLI
5
5
  # CLI build subcommand
6
- class Build
7
- include Mixlib::CLI
8
-
6
+ class Build < Base
9
7
  banner <<BANNER.freeze
10
8
  Version: #{Dapp::VERSION}
11
9
 
@@ -17,149 +15,17 @@ Usage:
17
15
  Options:
18
16
  BANNER
19
17
 
20
- class << self
21
- def option(name, args)
22
- if args.delete :builder_opt
23
- args[:proc] = if args[:boolean]
24
- proc { Dapp::Builder.default_opts[name] = true }
25
- else
26
- proc { |v| Dapp::Builder.default_opts[name] = v }
27
- end
28
- end
29
-
30
- super(name, args)
31
- end
32
- end
33
-
34
- option :log_quiet,
35
- short: '-q',
36
- long: '--quiet',
37
- description: 'Suppress logging',
38
- on: :tail,
39
- boolean: true,
40
- builder_opt: true
41
-
42
- option :log_verbose,
43
- long: '--verbose',
44
- description: 'Enable verbose output',
45
- on: :tail,
46
- boolean: true,
47
- builder_opt: true
48
-
49
- option :help,
50
- short: '-h',
51
- long: '--help',
52
- description: 'Show this message',
53
- on: :tail,
54
- boolean: true,
55
- show_options: true,
56
- exit: 0
57
-
58
- option :dir,
59
- long: '--dir PATH',
60
- description: 'Change to directory',
61
- on: :head
62
-
63
- option :dappfile_name,
64
- long: '--dappfile-name NAME',
65
- description: 'Name of Dappfile',
66
- builder_opt: true,
67
- on: :head
68
-
69
18
  option :build_dir,
70
19
  long: '--build-dir PATH',
71
- description: 'Build directory',
72
- builder_opt: true
73
-
74
- option :docker_repo,
75
- long: '--docker-repo REPO',
76
- description: 'Docker repo',
77
- builder_opt: true
78
-
79
- option :flush_cache,
80
- long: '--flush-cache',
81
- description: 'Flush cache',
82
- boolean: true,
83
- builder_opt: true
84
-
85
- option :tag_cascade,
86
- long: '--tag-cascade',
87
- description: 'Use cascade tagging',
88
- boolean: true,
89
- builder_opt: true
20
+ description: 'Build directory'
90
21
 
91
- option :tag_ci,
92
- long: '--tag-ci',
93
- description: 'Tag by CI branch and tag',
94
- boolean: true,
95
- builder_opt: true
96
-
97
- option :tag_build_id,
98
- long: '--tag-build-id',
99
- description: 'Tag by CI build id',
100
- boolean: true,
101
- builder_opt: true
102
-
103
- option :tag,
104
- long: '--tag TAG',
105
- description: 'Add tag (can be used one or more times)',
106
- proc: proc { |v| (Dapp::Builder.default_opts[:tags] ||= []) << v }
107
-
108
- option :tag_commit,
109
- long: '--tag-commit',
110
- description: 'Tag by git commit',
111
- boolean: true,
112
- builder_opt: true
113
-
114
- option :tag_branch,
115
- long: '--tag-branch',
116
- description: 'Tag by git branch',
117
- boolean: true,
118
- builder_opt: true
22
+ option :build_cache_dir,
23
+ long: '--build-cache-dir PATH',
24
+ description: 'Build cache directory'
119
25
 
120
26
  option :git_artifact_branch,
121
27
  long: '--git-artifact-branch BRANCH',
122
- description: 'Default branch to archive artifacts from',
123
- builder_opt: true
124
-
125
- def dappfile_path
126
- @dappfile_path ||= File.join [config[:dir], config[:dappfile_name] || 'Dappfile'].compact
127
- end
128
-
129
- def patterns
130
- @patterns ||= cli_arguments
131
- end
132
-
133
- def run(argv = ARGV)
134
- CLI.parse_options(self, argv)
135
-
136
- patterns << '*' unless patterns.any?
137
-
138
- if File.exist? dappfile_path
139
- process_file
140
- else
141
- process_directory
142
- end
143
- end
144
-
145
- def process_file
146
- patterns.each do |pattern|
147
- unless Dapp::Builder.process_file(dappfile_path, app_filter: pattern).builded_apps.any?
148
- STDERR.puts "Error: No such app: '#{pattern}' in #{dappfile_path}"
149
- exit 1
150
- end
151
- end
152
- end
153
-
154
- def process_directory
155
- Dapp::Builder.default_opts[:shared_build_dir] = true
156
- patterns.each do |pattern|
157
- unless Dapp::Builder.process_directory(config[:dir], pattern).any?
158
- STDERR.puts "Error: No such app '#{pattern}'"
159
- exit 1
160
- end
161
- end
162
- end
28
+ description: 'Default branch to archive artifacts from'
163
29
  end
164
30
  end
165
31
  end
@@ -0,0 +1,19 @@
1
+ require 'mixlib/cli'
2
+
3
+ module Dapp
4
+ class CLI
5
+ # CLI flush subcommand
6
+ class Flush < CLI
7
+ SUBCOMMANDS = ['stage cache', 'build cache'].freeze
8
+
9
+ banner <<BANNER.freeze
10
+ Version: #{Dapp::VERSION}
11
+
12
+ Available subcommands: (for details, dapp SUB-COMMAND --help)
13
+
14
+ dapp flush stage cache
15
+ dapp flush build cache
16
+ BANNER
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ require 'mixlib/cli'
2
+
3
+ module Dapp
4
+ class CLI
5
+ class Flush
6
+ # Flush build cache subcommand
7
+ class BuildCache < Base
8
+ banner <<BANNER.freeze
9
+ Version: #{Dapp::VERSION}
10
+
11
+ Usage:
12
+ dapp flush build cache
13
+ Options:
14
+ BANNER
15
+ option :build_cache_dir,
16
+ long: '--build-cache-dir PATH',
17
+ description: 'Build cache directory'
18
+
19
+ def run(argv = ARGV)
20
+ self.class.parse_options(self, argv)
21
+ Controller.new(cli_options: config, patterns: cli_arguments).flush_build_cache
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ require 'mixlib/cli'
2
+
3
+ module Dapp
4
+ class CLI
5
+ class Flush
6
+ # Flush stage cache subcommand
7
+ class StageCache < Flush
8
+ banner <<BANNER.freeze
9
+ Version: #{Dapp::VERSION}
10
+
11
+ Usage:
12
+ dapp flush stage cache
13
+ Options:
14
+ BANNER
15
+
16
+ def run(argv = ARGV)
17
+ self.class.parse_options(self, argv)
18
+ Controller.flush_stage_cache
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ require 'mixlib/cli'
2
+
3
+ module Dapp
4
+ class CLI
5
+ # CLI list subcommand
6
+ class List < Base
7
+ banner <<BANNER.freeze
8
+ Version: #{Dapp::VERSION}
9
+
10
+ Usage:
11
+ dapp list [options] [PATTERN ...]
12
+
13
+ PATTERN Applications to process [default: *].
14
+
15
+ Options:
16
+ BANNER
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,59 @@
1
+ require 'mixlib/cli'
2
+
3
+ module Dapp
4
+ class CLI
5
+ # CLI push subcommand
6
+ class Push < Base
7
+ banner <<BANNER.freeze
8
+ Version: #{Dapp::VERSION}
9
+
10
+ Usage:
11
+ dapp push [options] [PATTERN ...] REPO
12
+
13
+ PATTERN Applications to process [default: *].
14
+
15
+ Options:
16
+ BANNER
17
+
18
+ option :build_dir,
19
+ long: '--build-dir PATH',
20
+ description: 'Build directory'
21
+
22
+ option :git_artifact_branch,
23
+ long: '--git-artifact-branch BRANCH',
24
+ description: 'Default branch to archive artifacts from'
25
+
26
+ option :tag,
27
+ long: '--tag TAG',
28
+ description: 'Add tag (can be used one or more times)',
29
+ default: [],
30
+ proc: proc { |v| composite_options(:tags) << v }
31
+
32
+ option :tag_branch,
33
+ long: '--tag-branch',
34
+ description: 'Tag by git branch',
35
+ boolean: true
36
+
37
+ option :tag_build_id,
38
+ long: '--tag-build-id',
39
+ description: 'Tag by CI build id',
40
+ boolean: true
41
+
42
+ option :tag_ci,
43
+ long: '--tag-ci',
44
+ description: 'Tag by CI branch and tag',
45
+ boolean: true
46
+
47
+ option :tag_commit,
48
+ long: '--tag-commit',
49
+ description: 'Tag by git commit',
50
+ boolean: true
51
+
52
+ def run(argv = ARGV)
53
+ self.class.parse_options(self, argv)
54
+ repo = self.class.required_argument(self)
55
+ Controller.new(cli_options: config, patterns: cli_arguments).public_send(class_to_lowercase, repo)
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,19 @@
1
+ require 'mixlib/cli'
2
+
3
+ module Dapp
4
+ class CLI
5
+ # CLI smartpush subcommand
6
+ class Smartpush < Push
7
+ banner <<BANNER.freeze
8
+ Version: #{Dapp::VERSION}
9
+
10
+ Usage:
11
+ dapp smartpush [options] [PATTERN ...] REPOPREFIX
12
+
13
+ PATTERN Applications to process [default: *].
14
+
15
+ Options:
16
+ BANNER
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,98 @@
1
+ module Dapp
2
+ module Config
3
+ # Application
4
+ class Application
5
+ attr_reader :_name
6
+ attr_reader :_builder
7
+ attr_reader :_home_path
8
+ attr_reader :_docker
9
+ attr_reader :_git_artifact
10
+ attr_reader :_chef
11
+ attr_reader :_shell
12
+ attr_reader :_parent
13
+ attr_reader :_app_install_dependencies
14
+ attr_reader :_app_setup_dependencies
15
+ attr_reader :_parent
16
+
17
+ def initialize(parent)
18
+ @_apps = []
19
+ @_parent = parent
20
+
21
+ @_app_install_dependencies = []
22
+ @_app_setup_dependencies = []
23
+
24
+ yield self if block_given?
25
+ end
26
+
27
+ def app_install_depends_on(*args)
28
+ @_app_install_dependencies.concat(args)
29
+ end
30
+
31
+ def app_setup_depends_on(*args)
32
+ @_app_setup_dependencies.concat(args)
33
+ end
34
+
35
+ def chef
36
+ fail Error::Config, code: :builder_type_conflict unless _builder == :chef
37
+ @_chef ||= Chef.new
38
+ end
39
+
40
+ def shell
41
+ fail Error::Config, code: :builder_type_conflict unless _builder == :shell
42
+ @_shell ||= Shell.new
43
+ end
44
+
45
+ def git_artifact
46
+ @_git_artifact ||= GitArtifact.new
47
+ end
48
+
49
+ def docker
50
+ @_docker ||= Docker.new
51
+ end
52
+
53
+ def builder(type)
54
+ fail Error::Config, code: :builder_type_unsupported, data: { type: type } unless [:chef, :shell].include?((type = type.to_sym))
55
+ another_builder = [:chef, :shell].find { |t| t != type }
56
+ instance_variable_set(:"@_#{another_builder}", Config.const_get(another_builder.capitalize).new)
57
+ @_builder = type
58
+ end
59
+
60
+ def _apps
61
+ @_apps.empty? ? [self] : @_apps.flatten
62
+ end
63
+
64
+ def _app_runlist
65
+ @_app_runlist ||= (_parent ? _parent._app_runlist : []) + [self]
66
+ end
67
+
68
+ def _root_app
69
+ _app_runlist.first
70
+ end
71
+
72
+ private
73
+
74
+ # rubocop:disable Metrics/AbcSize
75
+ def clone
76
+ Application.new(self).tap do |app|
77
+ app.instance_variable_set(:'@_builder', _builder)
78
+ app.instance_variable_set(:'@_home_path', _home_path)
79
+ app.instance_variable_set(:'@_app_install_dependencies', _app_install_dependencies)
80
+ app.instance_variable_set(:'@_app_setup_dependencies', _app_setup_dependencies)
81
+ app.instance_variable_set(:'@_docker', _docker.clone) unless @_docker.nil?
82
+ app.instance_variable_set(:'@_git_artifact', _git_artifact.clone) unless @_git_artifact.nil?
83
+ app.instance_variable_set(:'@_chef', _chef.clone) unless @_chef.nil?
84
+ app.instance_variable_set(:'@_shell', _shell.clone) unless @_shell.nil?
85
+ end
86
+ end
87
+ # rubocop:enable Metrics/AbcSize
88
+
89
+ def app(sub_name, &blk)
90
+ clone.tap do |app|
91
+ app.instance_variable_set(:'@_name', [_name, sub_name].compact.join('-'))
92
+ app.instance_eval(&blk) if block_given?
93
+ @_apps += app._apps
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,20 @@
1
+ module Dapp
2
+ module Config
3
+ # Chef
4
+ class Chef
5
+ attr_reader :_modules
6
+
7
+ def initialize
8
+ @_modules = []
9
+ end
10
+
11
+ def module(*args)
12
+ @_modules.concat(args)
13
+ end
14
+
15
+ def clone
16
+ Marshal.load(Marshal.dump(self))
17
+ end
18
+ end
19
+ end
20
+ end