dapp 0.2.8 → 0.3.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.
Files changed (49) hide show
  1. checksums.yaml +8 -8
  2. data/config/en/common.yml +3 -1
  3. data/config/en/net_status.yml +5 -2
  4. data/lib/dapp.rb +9 -6
  5. data/lib/dapp/application.rb +30 -5
  6. data/lib/dapp/application/logging.rb +2 -2
  7. data/lib/dapp/application/path.rb +10 -6
  8. data/lib/dapp/build/stage/base.rb +77 -9
  9. data/lib/dapp/build/stage/chef_cookbooks.rb +1 -1
  10. data/lib/dapp/build/stage/from.rb +2 -1
  11. data/lib/dapp/build/stage/infra_install.rb +1 -1
  12. data/lib/dapp/build/stage/source_1.rb +1 -1
  13. data/lib/dapp/build/stage/source_1_archive.rb +0 -4
  14. data/lib/dapp/build/stage/source_2.rb +1 -1
  15. data/lib/dapp/build/stage/source_3.rb +1 -1
  16. data/lib/dapp/build/stage/source_base.rb +3 -3
  17. data/lib/dapp/builder/chef.rb +160 -140
  18. data/lib/dapp/cli.rb +2 -1
  19. data/lib/dapp/cli/base.rb +1 -1
  20. data/lib/dapp/cli/build.rb +7 -7
  21. data/lib/dapp/cli/flush.rb +3 -3
  22. data/lib/dapp/cli/flush/{build_cache.rb → metadata.rb} +7 -7
  23. data/lib/dapp/cli/flush/{stage_cache.rb → stages.rb} +4 -4
  24. data/lib/dapp/cli/push.rb +3 -3
  25. data/lib/dapp/cli/run.rb +59 -0
  26. data/lib/dapp/config/application.rb +20 -2
  27. data/lib/dapp/config/artifact.rb +69 -0
  28. data/lib/dapp/config/chef.rb +27 -0
  29. data/lib/dapp/config/docker.rb +1 -1
  30. data/lib/dapp/config/git_artifact.rb +3 -29
  31. data/lib/dapp/config/shell.rb +20 -0
  32. data/lib/dapp/controller.rb +21 -22
  33. data/lib/dapp/exception/base.rb +1 -5
  34. data/lib/dapp/filelock.rb +1 -1
  35. data/lib/dapp/git_artifact.rb +2 -2
  36. data/lib/dapp/git_repo/base.rb +5 -5
  37. data/lib/dapp/git_repo/own.rb +6 -2
  38. data/lib/dapp/git_repo/remote.rb +5 -3
  39. data/lib/dapp/helper/cli.rb +7 -1
  40. data/lib/dapp/helper/log.rb +2 -2
  41. data/lib/dapp/helper/shellout.rb +1 -1
  42. data/lib/dapp/helper/trivia.rb +0 -4
  43. data/lib/dapp/image/arguments.rb +115 -0
  44. data/lib/dapp/image/docker.rb +76 -0
  45. data/lib/dapp/image/stage.rb +74 -0
  46. data/lib/dapp/version.rb +1 -1
  47. metadata +9 -6
  48. data/lib/dapp/docker_image.rb +0 -51
  49. data/lib/dapp/stage_image.rb +0 -160
@@ -7,7 +7,7 @@ module Dapp
7
7
  include Mixlib::CLI
8
8
  include Helper::Trivia
9
9
 
10
- SUBCOMMANDS = %w(build smartpush push list flush).freeze
10
+ SUBCOMMANDS = %w(build smartpush push list run flush).freeze
11
11
 
12
12
  banner <<BANNER.freeze
13
13
  Usage: dapp [options] sub-command [sub-command options]
@@ -18,6 +18,7 @@ dapp build [options] [PATTERN ...]
18
18
  dapp push [options] [PATTERN] REPO
19
19
  dapp smartpush [options] [PATTERN ...] REPOPREFIX
20
20
  dapp list [options] [PATTERN ...]
21
+ dapp run [options] [PATTERN] [DOCKER ARGS]
21
22
  dapp flush
22
23
 
23
24
  Options:
@@ -25,7 +25,7 @@ module Dapp
25
25
  boolean: true
26
26
 
27
27
  option :log_time,
28
- long: '--log-time',
28
+ long: '--time',
29
29
  description: 'Enable output with time',
30
30
  default: false,
31
31
  boolean: true
@@ -17,13 +17,13 @@ Usage:
17
17
  Options:
18
18
  BANNER
19
19
 
20
- option :build_dir,
21
- long: '--build-dir PATH',
22
- description: 'Build directory'
20
+ option :tmp_dir_prefix,
21
+ long: '--tmp-dir-prefix PREFIX',
22
+ description: 'Tmp directory prefix'
23
23
 
24
- option :build_cache_dir,
25
- long: '--build-cache-dir PATH',
26
- description: 'Build cache directory'
24
+ option :metadata_dir,
25
+ long: '--metadata-dir PATH',
26
+ description: 'Metadata directory'
27
27
 
28
28
  option :git_artifact_branch,
29
29
  long: '--git-artifact-branch BRANCH',
@@ -50,7 +50,7 @@ BANNER
50
50
  rescue Exception::IntrospectImage => e
51
51
  $stderr.puts(e.net_status[:message])
52
52
  data = e.net_status[:data]
53
- system("docker run -ti --rm #{data[:options]} #{data[:built_id]} bash")
53
+ system("docker run -ti --rm #{data[:options]} #{data[:built_id]} bash") || raise(RuntimeError)
54
54
  shellout("docker rmi #{data[:built_id]}") if data[:rmi]
55
55
  end
56
56
  end
@@ -4,15 +4,15 @@ module Dapp
4
4
  class CLI
5
5
  # CLI flush subcommand
6
6
  class Flush < CLI
7
- SUBCOMMANDS = ['stage cache', 'build cache'].freeze
7
+ SUBCOMMANDS = %w(metadata stages).freeze
8
8
 
9
9
  banner <<BANNER.freeze
10
10
  Version: #{Dapp::VERSION}
11
11
 
12
12
  Available subcommands: (for details, dapp SUB-COMMAND --help)
13
13
 
14
- dapp flush stage cache
15
- dapp flush build cache
14
+ dapp flush metadata
15
+ dapp flush stages
16
16
  BANNER
17
17
  end
18
18
  end
@@ -3,22 +3,22 @@ require 'mixlib/cli'
3
3
  module Dapp
4
4
  class CLI
5
5
  class Flush
6
- # Flush build cache subcommand
7
- class BuildCache < Base
6
+ # Flush metadata subcommand
7
+ class Metadata < Base
8
8
  banner <<BANNER.freeze
9
9
  Version: #{Dapp::VERSION}
10
10
 
11
11
  Usage:
12
- dapp flush build cache
12
+ dapp flush metadata
13
13
  Options:
14
14
  BANNER
15
- option :build_cache_dir,
16
- long: '--build-cache-dir PATH',
17
- description: 'Build cache directory'
15
+ option :metadata_dir,
16
+ long: '--metadata-dir PATH',
17
+ description: 'Metadata directory'
18
18
 
19
19
  def run(argv = ARGV)
20
20
  self.class.parse_options(self, argv)
21
- Controller.new(cli_options: config, patterns: cli_arguments).flush_build_cache
21
+ Controller.new(cli_options: config, patterns: cli_arguments).flush_metadata
22
22
  end
23
23
  end
24
24
  end
@@ -3,19 +3,19 @@ require 'mixlib/cli'
3
3
  module Dapp
4
4
  class CLI
5
5
  class Flush
6
- # Flush stage cache subcommand
7
- class StageCache < Flush
6
+ # Flush stages subcommand
7
+ class Stages < Flush
8
8
  banner <<BANNER.freeze
9
9
  Version: #{Dapp::VERSION}
10
10
 
11
11
  Usage:
12
- dapp flush stage cache
12
+ dapp flush stages
13
13
  Options:
14
14
  BANNER
15
15
 
16
16
  def run(argv = ARGV)
17
17
  self.class.parse_options(self, argv)
18
- Controller.flush_stage_cache
18
+ Controller.flush_stages
19
19
  end
20
20
  end
21
21
  end
@@ -15,9 +15,9 @@ Usage:
15
15
  Options:
16
16
  BANNER
17
17
 
18
- option :build_dir,
19
- long: '--build-dir PATH',
20
- description: 'Build directory'
18
+ option :metadata_dir,
19
+ long: '--metadata-dir PATH',
20
+ description: 'Metadata directory'
21
21
 
22
22
  option :git_artifact_branch,
23
23
  long: '--git-artifact-branch BRANCH',
@@ -0,0 +1,59 @@
1
+ require 'mixlib/cli'
2
+
3
+ module Dapp
4
+ class CLI
5
+ # CLI run subcommand
6
+ class Run < Base
7
+ banner <<BANNER.freeze
8
+ Version: #{Dapp::VERSION}
9
+
10
+ Usage:
11
+ dapp run [options] [PATTERN] [DOCKER ARGS]
12
+
13
+ PATTERN Applications to process [default: *].
14
+ DOCKER ARGS Docker run options and command separated by '--'
15
+
16
+
17
+ Options:
18
+ BANNER
19
+ option :metadata_dir,
20
+ long: '--metadata-dir PATH',
21
+ description: 'Metadata directory'
22
+
23
+ def read_cli_options(args)
24
+ self.class.cli_wrapper(self) do
25
+ args.each_with_index do |arg, i|
26
+ next if arg == '--'
27
+ next if (key = find_option(arg)).nil?
28
+ cli_option = []
29
+ cli_option << args.slice!(i)
30
+ if key[:with_arg]
31
+ raise OptionParser::InvalidOption if args.count < i + 1
32
+ cli_option << args.slice!(i)
33
+ end
34
+ parse_options(cli_option)
35
+ return read_cli_options(args)
36
+ end
37
+ end
38
+ end
39
+
40
+ def find_option(arg)
41
+ expected_options.each { |hash| return hash if hash[:formats].any? { |f| f.start_with? arg } }
42
+ nil
43
+ end
44
+
45
+ def expected_options
46
+ @expected_options ||= options.values.map { |opt| { formats: [opt[:long], opt[:short]].compact, with_arg: !opt[:long].split.one? } }
47
+ end
48
+
49
+ def run(argv = ARGV)
50
+ filtered_args = read_cli_options(argv)
51
+ pattern = filtered_args.any? && !filtered_args.first.start_with?('-') ? [filtered_args.shift] : []
52
+ index = filtered_args.index('--') || filtered_args.count
53
+ docker_options = index.nonzero? ? filtered_args.slice(0..index - 1) : []
54
+ command = filtered_args.slice(index + 1..-1) || []
55
+ Controller.new(cli_options: config, patterns: pattern).run(docker_options, command)
56
+ end
57
+ end
58
+ end
59
+ end
@@ -7,6 +7,7 @@ module Dapp
7
7
  attr_reader :_home_path
8
8
  attr_reader :_docker
9
9
  attr_reader :_git_artifact
10
+ attr_reader :_artifact
10
11
  attr_reader :_chef
11
12
  attr_reader :_shell
12
13
  attr_reader :_parent
@@ -18,6 +19,7 @@ module Dapp
18
19
  @_apps = []
19
20
  @_parent = parent
20
21
 
22
+ @_artifact = []
21
23
  @_app_install_dependencies = []
22
24
  @_app_setup_dependencies = []
23
25
 
@@ -42,6 +44,17 @@ module Dapp
42
44
  @_shell ||= Shell.new
43
45
  end
44
46
 
47
+ def artifact(where_to_add, **options, &blk)
48
+ @_artifact << begin
49
+ config = clone.tap do |app|
50
+ app.instance_variable_set(:'@_artifact', [])
51
+ app.instance_variable_set(:'@_name', app_name("artifact-#{SecureRandom.hex(2)}"))
52
+ app.instance_eval(&blk) if block_given?
53
+ end
54
+ Artifact::Stage.new(where_to_add, config: config, **options)
55
+ end
56
+ end
57
+
45
58
  def git_artifact
46
59
  @_git_artifact ||= GitArtifact.new
47
60
  end
@@ -67,7 +80,7 @@ module Dapp
67
80
 
68
81
  def _app_runlist
69
82
  _app_chain.map(&:_name).map do |name|
70
- if subname = name.split("#{_root_app._name}-", 2)[1]
83
+ if (subname = name.split("#{_root_app._name}-", 2)[1])
71
84
  subname_parts = subname.split('-')
72
85
  subname_parts.join('_') if subname_parts.any?
73
86
  end
@@ -87,6 +100,7 @@ module Dapp
87
100
  app.instance_variable_set(:'@_home_path', _home_path)
88
101
  app.instance_variable_set(:'@_app_install_dependencies', _app_install_dependencies)
89
102
  app.instance_variable_set(:'@_app_setup_dependencies', _app_setup_dependencies)
103
+ app.instance_variable_set(:'@_artifact', Marshal.load(Marshal.dump(_artifact)))
90
104
  app.instance_variable_set(:'@_docker', _docker.clone) unless @_docker.nil?
91
105
  app.instance_variable_set(:'@_git_artifact', _git_artifact.clone) unless @_git_artifact.nil?
92
106
  app.instance_variable_set(:'@_chef', _chef.clone) unless @_chef.nil?
@@ -97,11 +111,15 @@ module Dapp
97
111
 
98
112
  def app(sub_name, &blk)
99
113
  clone.tap do |app|
100
- app.instance_variable_set(:'@_name', [_name, sub_name].compact.join('-'))
114
+ app.instance_variable_set(:'@_name', app_name(sub_name))
101
115
  app.instance_eval(&blk) if block_given?
102
116
  @_apps += app._apps
103
117
  end
104
118
  end
119
+
120
+ def app_name(sub_name)
121
+ [_name, sub_name].compact.join('-')
122
+ end
105
123
  end
106
124
  end
107
125
  end
@@ -0,0 +1,69 @@
1
+ module Dapp
2
+ module Config
3
+ # Artifact
4
+ module Artifact
5
+ # Base
6
+ class Base
7
+ attr_accessor :_where_to_add, :_cwd, :_paths, :_owner, :_group
8
+
9
+ def initialize(where_to_add, **options)
10
+ @_cwd = ''
11
+ @_where_to_add = where_to_add
12
+
13
+ options.each do |k, v|
14
+ respond_to?("_#{k}=") ? send(:"_#{k}=", v) : raise(Error::Config, code: code,
15
+ data: { type: object_name, attr: k })
16
+ end
17
+ end
18
+
19
+ def _paths
20
+ Array(@_paths)
21
+ end
22
+
23
+ def _artifact_options
24
+ {
25
+ where_to_add: _where_to_add,
26
+ cwd: _cwd,
27
+ paths: _paths,
28
+ owner: _owner,
29
+ group: _group
30
+ }
31
+ end
32
+
33
+ def clone
34
+ Marshal.load(Marshal.dump(self))
35
+ end
36
+
37
+ protected
38
+
39
+ def code
40
+ raise
41
+ end
42
+
43
+ def object_name
44
+ self.class.to_s.split('::').last
45
+ end
46
+ end
47
+
48
+ # Stage
49
+ class Stage < Base
50
+ attr_accessor :_config
51
+ attr_accessor :_before, :_after
52
+
53
+ def _before=(stage)
54
+ @_before = stage.to_sym
55
+ end
56
+
57
+ def _after=(stage)
58
+ @_after = stage.to_sym
59
+ end
60
+
61
+ protected
62
+
63
+ def code
64
+ :artifact_unexpected_attribute
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -3,15 +3,42 @@ module Dapp
3
3
  # Chef
4
4
  class Chef
5
5
  attr_reader :_modules
6
+ attr_reader :_recipes
6
7
 
7
8
  def initialize
8
9
  @_modules = []
10
+ @_recipes = []
9
11
  end
10
12
 
11
13
  def module(*args)
12
14
  @_modules.concat(args)
13
15
  end
14
16
 
17
+ def reset_modules
18
+ @_modules.clear
19
+ end
20
+
21
+ def skip_module(*args)
22
+ @_modules.reject! { |mod| args.include? mod }
23
+ end
24
+
25
+ def recipe(*args)
26
+ @_recipes.concat(args)
27
+ end
28
+
29
+ def remove_recipe(*args)
30
+ @_recipes.reject! { |recipe| args.include? recipe }
31
+ end
32
+
33
+ def reset_recipes
34
+ @_recipes.clear
35
+ end
36
+
37
+ def reset_all
38
+ reset_modules
39
+ reset_recipes
40
+ end
41
+
15
42
  def clone
16
43
  Marshal.load(Marshal.dump(self))
17
44
  end
@@ -80,7 +80,7 @@ module Dapp
80
80
  private
81
81
 
82
82
  def options_to_args(options)
83
- options.map {|key, value| "#{key.upcase}=#{value}" }
83
+ options.map { |key, value| "#{key.upcase}=#{value}" }
84
84
  end
85
85
  end
86
86
  end
@@ -23,37 +23,11 @@ module Dapp
23
23
  end
24
24
 
25
25
  # Local
26
- class Local
27
- attr_accessor :_where_to_add, :_cwd, :_paths, :_owner, :_group
28
-
29
- def initialize(where_to_add, **options)
30
- @_cwd = ''
31
- @_where_to_add = where_to_add
32
-
33
- options.each do |k, v|
34
- respond_to?("_#{k}=") ? send(:"_#{k}=", v) : raise(Error::Config, code: :git_artifact_unexpected_attribute,
35
- data: { type: object_name, attr: k })
36
- end
37
- end
38
-
39
- def _artifact_options
40
- {
41
- where_to_add: _where_to_add,
42
- cwd: _cwd,
43
- paths: _paths,
44
- owner: _owner,
45
- group: _group
46
- }
47
- end
48
-
49
- def clone
50
- Marshal.load(Marshal.dump(self))
51
- end
52
-
26
+ class Local < Artifact::Base
53
27
  protected
54
28
 
55
- def object_name
56
- self.class.to_s.split('::').last
29
+ def code
30
+ :git_artifact_unexpected_attribute
57
31
  end
58
32
  end
59
33
 
@@ -32,6 +32,26 @@ module Dapp
32
32
  @_app_setup_cache_version = cache_version
33
33
  end
34
34
 
35
+ def reset_infra_install
36
+ @_infra_install = []
37
+ end
38
+
39
+ def reset_infra_setup
40
+ @_infra_setup = []
41
+ end
42
+
43
+ def reset_app_install
44
+ @_app_install = []
45
+ end
46
+
47
+ def reset_app_setup
48
+ @_app_setup = []
49
+ end
50
+
51
+ def reset_all
52
+ methods.tap { |arr| arr.delete(__method__) }.grep(/^reset_/).each(&method(:send))
53
+ end
54
+
35
55
  def clone
36
56
  Marshal.load(Marshal.dump(self))
37
57
  end