dapp 0.0.1 → 0.0.2

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTQzOThlMTg4MDA3YzQ0MjE4ODgyZjgyMzQ4M2RiMTgzMmRlN2ZjZg==
4
+ NmM2YzExN2Y3YjVlZjQxOTg0MzVmM2QyMzA1YTQxMTQyNmMzZjA2NQ==
5
5
  data.tar.gz: !binary |-
6
- ODQ2ODVjOTY3OTE0M2I1NzQ4MjU1ZDczODE3MTFmNDJmYTI4NDQ2OQ==
6
+ ZjJhNGExOThmZmE5NjU4MTFlNzhlOTkwZTE5OTY4M2NlMDVmMzk4Yw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YzU1NWRjMDAyOWNjMGRiN2RkZGQyMmFhYzhlODQwYTc1ZGJiMzI0MDJkODkw
10
- Zjk5YTA2YTg1MDlmN2M0N2E5MWM1YmVhNmVmZTQ1MTlhMDRkY2IxOGI5OGQ1
11
- NTRkNzU0OTU4ZDM3ZDVlNjE3Y2U1N2VhODk3ODA0NThiYTE2Yzc=
9
+ ZjMzMTA0YWEzYmJjYjZjMDE3NTA3NzMyYmM2NjYzNzYwODlmOTNhNzk4ZWQz
10
+ MTZkYTM0M2ZjYjI4OTlkYTJkMWU2ZTA1NzllNmVhMDcxNGQyMDc0MTY2NDY0
11
+ ZDQ2MjNhM2FiYmY4ODU2OTJiOWQ0ZWY3NjIxMjc2N2NkYjljOWY=
12
12
  data.tar.gz: !binary |-
13
- ZGQ1ZTQ2ZGJmMmEwMWZjYWQ3MDYxMjg5MGNiNGQyNDc5NmQ0YWFmMWU3NmUx
14
- MjkyMjllNjczNDAzMzZkYzNiY2E3YTk5MjVkODMyY2Q2NDZlMTVlMDIxZTI3
15
- Y2U0YzBmNDIxOGQwYzE2N2EyMTY5MjdmZTFlYTI0NjUyZTgxMjU=
13
+ ODJkNjk4N2NmM2Q0ZWM1NTgxNjY1ODVkMzE1MDI1YWU5NWRkMmIyN2JjNDlk
14
+ MjFhOTcxODBjZWVkODQwYzliMDRkZjY5OWUzMTcxNDdmODNiNjU1ZTdmYzRj
15
+ ODI4ODk0OTFkNjNmMGI2NWUxODdiMGQ0N2M3M2EyMmJmNzlkZjc=
data/lib/dapp.rb CHANGED
@@ -8,6 +8,7 @@ require 'mixlib/shellout'
8
8
 
9
9
  require 'dapp/version'
10
10
  require 'dapp/cli'
11
+ require 'dapp/cli/build'
11
12
  require 'dapp/builder/chefify'
12
13
  require 'dapp/builder/centos7'
13
14
  require 'dapp/builder/cascade_tagging'
data/lib/dapp/atomizer.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  module Dapp
2
2
  # "Transaction" journal with rollback (mainly to protect cache fill with unbuildable configuration)
3
3
  class Atomizer
4
- def initialize(builder, file_path)
4
+ def initialize(builder, file_path, lock_timeout: 10)
5
5
  @builder = builder
6
6
  @file_path = file_path
7
+ @lock_timeout = lock_timeout
7
8
  @file = open
8
9
 
9
10
  builder.register_atomizer self
@@ -11,6 +12,7 @@ module Dapp
11
12
 
12
13
  def <<(path)
13
14
  file.puts path
15
+ file.fsync
14
16
  end
15
17
 
16
18
  def commit!
@@ -24,6 +26,7 @@ module Dapp
24
26
  attr_reader :file_path
25
27
  attr_reader :builder
26
28
 
29
+ attr_reader :lock_timeout
27
30
  attr_reader :file
28
31
 
29
32
  def open
@@ -31,7 +34,7 @@ module Dapp
31
34
 
32
35
  file.sync = true
33
36
 
34
- Timeout.timeout(10) do
37
+ Timeout.timeout(lock_timeout) do
35
38
  file.flock(File::LOCK_EX)
36
39
  end
37
40
 
data/lib/dapp/cli.rb CHANGED
@@ -5,13 +5,23 @@ module Dapp
5
5
  class CLI
6
6
  include Mixlib::CLI
7
7
 
8
+ class << self
9
+ def parse_options(cli, argv)
10
+ cli.parse_options(argv)
11
+ rescue OptionParser::InvalidOption => e
12
+ STDERR.puts "Error: #{e.message}"
13
+ puts
14
+ puts cli.opt_parser
15
+ exit 1
16
+ end
17
+ end
18
+
8
19
  banner <<BANNER.freeze
9
- Version: #{Dapp::VERSION}
20
+ Usage: dapp [options] sub-command [sub-command options]
10
21
 
11
- Usage:
12
- dappit [options] [PATTERN ...]
22
+ Available subcommands: (for details, dapp SUB-COMMAND --help)
13
23
 
14
- PATTERN Applications to process [default: *].
24
+ dapp build [options] [PATTERN ...]
15
25
 
16
26
  Options:
17
27
  BANNER
@@ -21,24 +31,9 @@ BANNER
21
31
  description: 'Show version',
22
32
  on: :tail,
23
33
  boolean: true,
24
- proc: proc { puts "Version: #{Dapp::VERSION}" },
34
+ proc: proc { puts "dapp: #{Dapp::VERSION}" },
25
35
  exit: 0
26
36
 
27
- option :quiet,
28
- short: '-q',
29
- long: '--quiet',
30
- description: 'Suppress logging',
31
- on: :tail,
32
- boolean: true,
33
- proc: proc { Dapp::Builder.default_opts[:log_quiet] = true }
34
-
35
- option :verbose,
36
- long: '--verbose',
37
- description: 'Enable verbose output',
38
- on: :tail,
39
- boolean: true,
40
- proc: proc { Dapp::Builder.default_opts[:log_verbose] = true }
41
-
42
37
  option :help,
43
38
  short: '-h',
44
39
  long: '--help',
@@ -48,85 +43,47 @@ BANNER
48
43
  show_options: true,
49
44
  exit: 0
50
45
 
51
- option :build_dir,
52
- long: '--build-dir PATH',
53
- description: 'Build directory',
54
- proc: proc { |p| Dapp::Builder.default_opts[:build_dir] = p }
55
-
56
- option :dir,
57
- long: '--dir PATH',
58
- description: 'Change to directory',
59
- on: :head
60
-
61
- option :dappfile_name,
62
- long: '--dappfile-name NAME',
63
- description: 'Name of Dappfile',
64
- proc: proc { |n| Dapp::Builder.default_opts[:dappfile_name] = n },
65
- on: :head
66
-
67
- option :flush_cache,
68
- long: '--flush-cache',
69
- description: 'Flush cache',
70
- boolean: true,
71
- proc: proc { Dapp::Builder.default_opts[:flush_cache] = true }
72
-
73
- option :docker_registry,
74
- long: '--docker-registry REGISTRY',
75
- description: 'Docker registry',
76
- proc: proc { |r| Dapp::Builder.default_opts[:docker_registry] = r }
77
-
78
- option :cascade_tagging,
79
- long: '--cascade_tagging',
80
- description: 'Use cascade tagging',
81
- boolean: true,
82
- proc: proc { Dapp::Builder.default_opts[:cascade_tagging] = true }
46
+ def initialize(*args)
47
+ super(*args)
83
48
 
84
- option :git_artifact_branch,
85
- long: '--git-artifact-branch BRANCH',
86
- description: 'Default branch to archive artifacts from',
87
- proc: proc { |b| Dapp::Builder.default_opts[:git_artifact_branch] = b }
88
-
89
- def dappfile_path
90
- @dappfile_path ||= File.join [config[:dir], 'Dappfile'].compact
91
- end
92
-
93
- def patterns
94
- @patterns ||= cli_arguments
49
+ opt_parser.program_name = 'dapp'
50
+ opt_parser.version = Dapp::VERSION
95
51
  end
96
52
 
97
- def run(argv = ARGV)
98
- begin
99
- parse_options(argv)
100
- rescue OptionParser::InvalidOption => e
101
- STDERR.puts "Error: #{e.message}"
102
- exit 1
103
- end
53
+ SUBCOMMANDS = %w(build).freeze
104
54
 
105
- patterns << '*' unless patterns.any?
106
-
107
- if File.exist? dappfile_path
108
- process_file
55
+ def parse_subcommand(argv)
56
+ if (index = argv.find_index { |v| SUBCOMMANDS.include? v })
57
+ return [
58
+ argv[0...index],
59
+ argv[index],
60
+ argv[index.next..-1]
61
+ ]
109
62
  else
110
- process_directory
63
+ return [
64
+ argv,
65
+ nil,
66
+ []
67
+ ]
111
68
  end
112
69
  end
113
70
 
114
- def process_file
115
- patterns.each do |pattern|
116
- unless Dapp::Builder.process_file(dappfile_path, app_filter: pattern).builded_apps.any?
117
- STDERR.puts "Error! No such app: '#{pattern}' in #{dappfile_path}"
118
- exit 1
119
- end
120
- end
71
+ def run(argv = ARGV)
72
+ argv, subcommand, subcommand_argv = parse_subcommand(argv)
73
+
74
+ CLI.parse_options(self, argv)
75
+
76
+ run_subcommand subcommand, subcommand_argv
121
77
  end
122
78
 
123
- def process_directory
124
- Dapp::Builder.default_opts[:shared_build_dir] = true
125
- patterns.each do |pattern|
126
- unless Dapp::Builder.process_directory(config[:dir], pattern).any?
127
- STDERR.puts "Error! No such app '#{pattern}'"
128
- exit 1
129
- end
79
+ def run_subcommand(subcommand, subcommand_argv)
80
+ if subcommand
81
+ self.class.const_get(subcommand.capitalize).new.run(subcommand_argv)
82
+ else
83
+ STDERR.puts 'Error: subcommand not passed'
84
+ puts
85
+ puts opt_parser
86
+ exit 1
130
87
  end
131
88
  end
132
89
  end
@@ -0,0 +1,136 @@
1
+ require 'mixlib/cli'
2
+
3
+ module Dapp
4
+ class CLI
5
+ # CLI build subcommand
6
+ class Build
7
+ include Mixlib::CLI
8
+
9
+ banner <<BANNER.freeze
10
+ Version: #{Dapp::VERSION}
11
+
12
+ Usage:
13
+ dapp build [options] [PATTERN ...]
14
+
15
+ PATTERN Applications to process [default: *].
16
+
17
+ Options:
18
+ BANNER
19
+
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
+ option :build_dir,
70
+ long: '--build-dir PATH',
71
+ description: 'Build directory',
72
+ builder_opt: true
73
+
74
+ option :docker_registry,
75
+ long: '--docker-registry REGISTRY',
76
+ description: 'Docker registry',
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 :cascade_tagging,
86
+ long: '--cascade_tagging',
87
+ description: 'Use cascade tagging',
88
+ boolean: true,
89
+ builder_opt: true
90
+
91
+ option :git_artifact_branch,
92
+ long: '--git-artifact-branch BRANCH',
93
+ description: 'Default branch to archive artifacts from',
94
+ builder_opt: true
95
+
96
+ def dappfile_path
97
+ @dappfile_path ||= File.join [config[:dir], config[:dappfile_name] || 'Dappfile'].compact
98
+ end
99
+
100
+ def patterns
101
+ @patterns ||= cli_arguments
102
+ end
103
+
104
+ def run(argv = ARGV)
105
+ CLI.parse_options(self, argv)
106
+
107
+ patterns << '*' unless patterns.any?
108
+
109
+ if File.exist? dappfile_path
110
+ process_file
111
+ else
112
+ process_directory
113
+ end
114
+ end
115
+
116
+ def process_file
117
+ patterns.each do |pattern|
118
+ unless Dapp::Builder.process_file(dappfile_path, app_filter: pattern).builded_apps.any?
119
+ STDERR.puts "Error: No such app: '#{pattern}' in #{dappfile_path}"
120
+ exit 1
121
+ end
122
+ end
123
+ end
124
+
125
+ def process_directory
126
+ Dapp::Builder.default_opts[:shared_build_dir] = true
127
+ patterns.each do |pattern|
128
+ unless Dapp::Builder.process_directory(config[:dir], pattern).any?
129
+ STDERR.puts "Error: No such app '#{pattern}'"
130
+ exit 1
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
data/lib/dapp/filelock.rb CHANGED
@@ -12,13 +12,14 @@ module Dapp
12
12
  end
13
13
  end
14
14
 
15
- def filelock(filelock, error_message: 'Already in use!', timeout: 10, &blk)
15
+ def filelock(filelock, error_message: 'Already in use!', timeout: 10)
16
16
  return yield if self.class.filelocks[filelock]
17
17
 
18
18
  begin
19
19
  self.class.filelocks[filelock] = true
20
- filelock_lockfile(filelock, error_message: error_message, timeout: timeout, &blk)
21
- yield
20
+ filelock_lockfile(filelock, error_message: error_message, timeout: timeout) do
21
+ yield
22
+ end
22
23
  ensure
23
24
  self.class.filelocks[filelock] = false
24
25
  end
data/lib/dapp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dapp
2
- VERSION = '0.0.1'.freeze
2
+ VERSION = '0.0.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Stolyarov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-03-12 00:00:00.000000000 Z
12
+ date: 2016-03-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mixlib-shellout
@@ -99,6 +99,20 @@ dependencies:
99
99
  - - ! '>='
100
100
  - !ruby/object:Gem::Version
101
101
  version: 3.4.0
102
+ - !ruby/object:Gem::Dependency
103
+ name: test_construct
104
+ requirement: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ type: :development
110
+ prerelease: false
111
+ version_requirements: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
102
116
  - !ruby/object:Gem::Dependency
103
117
  name: pry
104
118
  requirement: !ruby/object:Gem::Requirement
@@ -159,6 +173,20 @@ dependencies:
159
173
  - - ! '>='
160
174
  - !ruby/object:Gem::Version
161
175
  version: 1.8.2
176
+ - !ruby/object:Gem::Dependency
177
+ name: codeclimate-test-reporter
178
+ requirement: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ! '>='
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ type: :development
184
+ prerelease: false
185
+ version_requirements: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
162
190
  description: Build docker packaged apps using chef or shell
163
191
  email:
164
192
  - dmitry.stolyarov@flant.com
@@ -176,6 +204,7 @@ files:
176
204
  - lib/dapp/builder/centos7.rb
177
205
  - lib/dapp/builder/chefify.rb
178
206
  - lib/dapp/cli.rb
207
+ - lib/dapp/cli/build.rb
179
208
  - lib/dapp/docker.rb
180
209
  - lib/dapp/filelock.rb
181
210
  - lib/dapp/git_artifact.rb
@@ -195,7 +224,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
195
224
  requirements:
196
225
  - - ! '>='
197
226
  - !ruby/object:Gem::Version
198
- version: '2.2'
227
+ version: '2.1'
199
228
  required_rubygems_version: !ruby/object:Gem::Requirement
200
229
  requirements:
201
230
  - - ! '>='