luban 0.9.9 → 0.9.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26d8138a13c8141621f6b7e11def00b80b262d3f
4
- data.tar.gz: 7542bad5741e215596f25811d06c0a2266602e58
3
+ metadata.gz: 9d25dda1f3728164c6c4dbba1cbfffc26748f9ce
4
+ data.tar.gz: 2967b210dc597d9293418e9005f90f705fe4e380
5
5
  SHA512:
6
- metadata.gz: ead7b1483ad3cb6362ba67663641ee7102a5977f904eadbe173adae357a614dea2b7905a7cb1a6198a9f381fbc6c3c992d85f5e1fdc0437b15ae9230fcb29b35
7
- data.tar.gz: ecb3abebdf9e8ca78d0b44c0b8534946f2bb98eb59662e59899df5ca27f051db2e56bc32066c0d2a8043f31319d01846ba6ef9f486e7077e1ae7b89433d45c10
6
+ metadata.gz: 812bbd83cc2575d2908fd1241274d069ecb60386fe1f46f07084c604fc3aede2a56d517e20e6497551358cbbc0f1ce2798bd2e0a897cac92b2a744a9f2f02e48
7
+ data.tar.gz: 7bd9bb1d13b426ac1d997d5a2c9f1c3138a2114854ccf24539623bacfc346b988db89dd949d39a391e86b09aed604498fe7a3c32e4f71b9631a64e8910a8471e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Change log
2
2
 
3
+ ## Version 0.9.10 (Oct 24, 2016)
4
+
5
+ Minor enhancements:
6
+ * Refactored and enhanced the design and implementation of parameters in a deployment project
7
+ * Supported default value for a given parameter
8
+ * set method for default value should be in the form of "set_default_for_parameter_name"
9
+ * any methods following the above convention will be called during default value setup
10
+ * Supported parameter validation by convention
11
+ * validation method name should be in the form of "validate_for_parameter_name"
12
+ * any methods following the above convention will be called during parameter validation
13
+ * Injected parameters from service package, if any, into the application
14
+ * Automated default source handling and thus no more manual set_default_source
15
+ * Two default source paths under application base path and stage config path
16
+
17
+
18
+ Bug fixes:
19
+ * Ensured linked dirs to be created in package installer
20
+
3
21
  ## Version 0.9.9 (Oct 20, 2016)
4
22
 
5
23
  Bug fixes:
@@ -80,7 +80,10 @@ module Luban
80
80
  command(name, base: Luban::Deployment::Package::Base.package_class(name))
81
81
  end
82
82
  pkg.update_package_options(version, opts.merge(packages: packages))
83
- services[name] = pkg if pkg.is_a?(Luban::Deployment::Service::Base)
83
+ if pkg.is_a?(Luban::Deployment::Service::Base)
84
+ services[name] = pkg
85
+ add_service_parameters(pkg)
86
+ end
84
87
  packages[name] = pkg
85
88
  end
86
89
  alias_method :require_package, :package
@@ -110,7 +113,11 @@ module Luban
110
113
  end
111
114
 
112
115
  def default_source_path
113
- @default_source_path ||= config_finder[:application].stage_config_path.join('app')
116
+ @default_source_path ||=
117
+ [config_finder[:application].stage_config_path.join('app'),
118
+ config_finder[:application].base_path.join('app')].find do |source_path|
119
+ File.directory?(source_path)
120
+ end
114
121
  end
115
122
 
116
123
  def default_source?
@@ -275,26 +282,19 @@ module Luban
275
282
  @profile_opts = {}
276
283
  end
277
284
 
278
- def validate_parameters
279
- super
280
- validate_project_parameters
281
- validate_application_parameters
282
- end
283
-
284
285
  def set_default_parameters
286
+ set :application, self.class.name.split(':').last.snakecase
285
287
  super
286
- set_default_project_parameters
287
- set_default :application, self.class.name.split(':').last.snakecase
288
- set_default_application_parameters
289
- set_default_profile
290
288
  end
291
289
 
292
- def set_default_source
293
- source(default_source_path, scm: :rsync)
294
- release(stage, current: true)
290
+ def set_default_for_source
291
+ unless default_source_path.nil?
292
+ source(default_source_path, scm: :rsync)
293
+ release(stage, current: true)
294
+ end
295
295
  end
296
296
 
297
- def set_default_profile
297
+ def set_default_for_profile
298
298
  if config_finder[:application].has_profile?
299
299
  profile(config_finder[:application].stage_profile_path, scm: :rsync)
300
300
  profile_release(stage, current: true)
@@ -317,6 +317,12 @@ module Luban
317
317
  setup_crontab_tasks
318
318
  end
319
319
 
320
+ def add_service_parameters(service)
321
+ service.class.parameters.each_pair do |param, default|
322
+ singleton_class.send(:parameter, param, default: default)
323
+ end
324
+ end
325
+
320
326
  def setup_init_profiles
321
327
  _services = services.keys
322
328
  task :init do
@@ -365,13 +365,17 @@ module Luban
365
365
  end
366
366
 
367
367
  def set_default_parameters
368
- set_default_general_parameters
368
+ find_instance_methods(/^set_default_for_/).each { |m| send(m) }
369
+ end
370
+
371
+ def find_instance_methods(pattern)
372
+ singleton_class.instance_methods.select { |m| m.to_s =~ pattern }.reverse
369
373
  end
370
374
 
371
375
  def load_configuration; end
372
376
 
373
377
  def validate_parameters
374
- validate_general_parameters
378
+ find_instance_methods(/^validate_for_/).each { |m| send(m) }
375
379
  end
376
380
 
377
381
  def load_libraries; end
@@ -207,7 +207,7 @@ module Luban
207
207
  end
208
208
 
209
209
  def before_install
210
- bootstrap_install unless installed?
210
+ bootstrap_install
211
211
  install_required_packages(:before_install)
212
212
  end
213
213
 
@@ -98,18 +98,12 @@ module Luban
98
98
 
99
99
  protected
100
100
 
101
- def validate_parameters
102
- super
103
- validate_project_parameters
104
- end
105
-
106
101
  def set_default_parameters
107
- super
108
- set_default :stage, self.class.name.split('::').first.snakecase
109
- set_default :project, self.class.name.split('::').last.snakecase
110
- set_default_project_parameters
102
+ set :stage, self.class.name.split('::').first.snakecase
103
+ set :project, self.class.name.split('::').last.snakecase
111
104
  @passwords = {}
112
105
  @passwords_mutex = Mutex.new
106
+ super
113
107
  end
114
108
 
115
109
  def load_libraries
@@ -5,17 +5,34 @@ module Luban
5
5
  include Luban::Deployment::Command::Tasks::Control
6
6
  include Luban::Deployment::Command::Tasks::Monitor
7
7
 
8
- def self.service_action(action, dispatch_to: nil, as: action, locally: false, &blk)
9
- define_method(action) do |args:, opts:|
10
- if current_version
11
- send("#{__method__}!", args: args, opts: opts.merge(version: current_version))
12
- else
13
- abort "Aborted! No current version of #{display_name} is specified."
14
- end
8
+ class << self
9
+ def inherited(subclass)
10
+ super
11
+ # Ensure parameters from base class
12
+ # got inherited to its subclasses
13
+ params = instance_variable_get('@parameters')
14
+ subclass.instance_variable_set('@parameters', params.nil? ? {} : params.clone)
15
+ end
16
+
17
+ attr_reader :parameters
18
+
19
+ def parameter(param, default: nil)
20
+ super
21
+ parameters[param] = default
15
22
  end
16
- unless dispatch_to.nil?
17
- dispatch_task "#{action}!", to: dispatch_to, as: as, locally: locally, &blk
18
- protected "#{action}!"
23
+
24
+ def service_action(action, dispatch_to: nil, as: action, locally: false, &blk)
25
+ define_method(action) do |args:, opts:|
26
+ if current_version
27
+ send("#{__method__}!", args: args, opts: opts.merge(version: current_version))
28
+ else
29
+ abort "Aborted! No current version of #{display_name} is specified."
30
+ end
31
+ end
32
+ unless dispatch_to.nil?
33
+ dispatch_task "#{action}!", to: dispatch_to, as: as, locally: locally, &blk
34
+ protected "#{action}!"
35
+ end
19
36
  end
20
37
  end
21
38
 
@@ -14,7 +14,7 @@ module Luban
14
14
  end
15
15
 
16
16
  def set_default(key, value)
17
- set(key, value) unless @variables.has_key?(key)
17
+ set(key, value) if @variables[key].nil?
18
18
  end
19
19
 
20
20
  def delete(key)
@@ -37,6 +37,10 @@ module Luban
37
37
  @variables.keys
38
38
  end
39
39
 
40
+ def has_key?(key)
41
+ @variables.has_key?(key)
42
+ end
43
+
40
44
  def role(name, hosts, **properties)
41
45
  if name == :all
42
46
  raise ArgumentError, 'Reserved role name, :all, is NOT allowed to use.'
@@ -157,7 +157,6 @@ module Luban
157
157
  end
158
158
 
159
159
  def load_stage_configuration
160
- target.load_configuration_file(stage_config_file)
161
160
  if File.directory?(stage_config_path)
162
161
  ["*.rb", "{packages}/**/*.rb"].each do |pattern|
163
162
  Dir[stage_config_path.join(pattern)].each do |file|
@@ -165,6 +164,7 @@ module Luban
165
164
  end
166
165
  end
167
166
  end
167
+ target.load_configuration_file(stage_config_file)
168
168
  end
169
169
 
170
170
  def find_template_file(file_name)
@@ -194,9 +194,9 @@ module Luban
194
194
  Time.now().strftime("%d/%m/%Y %H:%M:%S")
195
195
  end
196
196
 
197
- def method_missing(sym, *args, &blk)
198
- backend.respond_to?(sym) ? backend.send(sym, *args, &blk) : super
199
- end
197
+ #def method_missing(sym, *args, &blk)
198
+ # backend.respond_to?(sym) ? backend.send(sym, *args, &blk) : super
199
+ #end
200
200
  end
201
201
  end
202
202
  end
@@ -2,12 +2,12 @@ module Luban
2
2
  module Deployment
3
3
  module Parameters
4
4
  module Base
5
- def parameter(*params)
6
- params.each do |param|
7
- define_method(param) do |value = nil|
8
- value.nil? ? fetch(__method__) : set(__method__, value)
9
- end
5
+ def parameter(param, default: nil)
6
+ define_method(param) do |value = nil|
7
+ value.nil? ? fetch(__method__) : set(__method__, value)
10
8
  end
9
+ define_method("set_default_for_#{param}") { set_default param, default }
10
+ protected "set_default_for_#{param}"
11
11
  end
12
12
  end
13
13
 
@@ -20,37 +20,35 @@ module Luban
20
20
  mod.extend(Base)
21
21
  end
22
22
 
23
- parameter :luban_roles
24
- parameter :luban_root_path
23
+ parameter :luban_roles, default: %i(app)
24
+ parameter :luban_root_path, default: DefaultLubanRootPath
25
25
 
26
26
  parameter :stages
27
27
  parameter :applications
28
- parameter :env_vars
28
+ parameter :env_vars, default: ->{ Hash.new }
29
29
 
30
30
  parameter :work_dir
31
31
  parameter :apps_path
32
32
  parameter :project
33
- parameter :user
34
- parameter :config_finder
33
+ parameter :user, default: ENV['USER']
34
+ parameter :config_finder, default: ->{ Hash.new }
35
35
 
36
36
  protected
37
37
 
38
- def set_default_general_parameters
39
- set_default :luban_roles, %i(app)
40
- set_default :luban_root_path, DefaultLubanRootPath
41
- set_default :env_vars, {}
42
- set_default :user, ENV['USER']
43
- set_default :config_finder, {}
44
- end
45
-
46
- def validate_general_parameters
38
+ def validate_for_user
47
39
  if user != ENV['USER']
48
40
  abort "Aborted! Given deployment user (#{user.inspect}) is NOT the current user #{ENV['USER'].inspect}" +
49
41
  "Please switch to the deployment user before any deployments."
50
42
  end
43
+ end
44
+
45
+ def validate_for_project
51
46
  if project.nil?
52
47
  abort "Aborted! Please specify the project name: project 'project name'"
53
48
  end
49
+ end
50
+
51
+ def validate_for_luban_root_path
54
52
  if luban_root_path.is_a?(String)
55
53
  luban_root_path Pathname.new(luban_root_path)
56
54
  end
@@ -65,14 +63,14 @@ module Luban
65
63
 
66
64
  parameter :stage
67
65
 
68
- parameter :process_monitor
69
- parameter :sshkit_backend
70
- parameter :authen_key_type
71
- parameter :default_env
72
- parameter :pty
73
- parameter :connection_timeout
74
- parameter :ssh_options
75
- parameter :use_sudo
66
+ parameter :process_monitor, default: ->{ Hash.new }
67
+ parameter :sshkit_backend, default: SSHKit::Backend::Netssh
68
+ parameter :authen_key_type, default: 'rsa'
69
+ parameter :default_env, default: ->{ { path: '$PATH:/usr/local/bin' } }
70
+ parameter :pty, default: false
71
+ parameter :connection_timeout, default: 30 # second
72
+ parameter :ssh_options, default: ->{ Hash.new }
73
+ parameter :use_sudo, default: false # Turn off sudo by default
76
74
 
77
75
  def process_monitor_via(monitor, env: "uber/lubmon")
78
76
  monitor = monitor.to_s.downcase
@@ -84,25 +82,12 @@ module Luban
84
82
 
85
83
  protected
86
84
 
87
- def set_default_project_parameters
88
- set_default :process_monitor, {}
89
- set_default :sshkit_backend, SSHKit::Backend::Netssh
90
- set_default :authen_key_type, 'rsa'
91
- set_default :default_env, { path: '$PATH:/usr/local/bin' }
92
- set_default :pty, false
93
- set_default :connection_timeout, 30 # second
94
- set_default :ssh_options, {}
95
- set_default :use_sudo, false # Turn off sudo by default
96
-
97
- setup_default_project_config_finder
98
- end
99
-
100
- def setup_default_project_config_finder
85
+ def set_default_for_project_config_finder
101
86
  config_finder[:project] ||=
102
87
  Luban::Deployment::Helpers::Configuration::Finder.project(self)
103
88
  end
104
89
 
105
- def validate_project_parameters
90
+ def validate_for_process_monitor
106
91
  if monitor_defined?
107
92
  if process_monitor[:name].nil?
108
93
  abort "Aborted! Please specify the process monitor."
@@ -121,10 +106,10 @@ module Luban
121
106
  DefaultLogrotateInterval = 10 # mins
122
107
 
123
108
  parameter :application
124
- parameter :scm_role
125
- parameter :archive_role
126
- parameter :logrotate_max_age
127
- parameter :logrotate_interval
109
+ parameter :scm_role, default: :scm
110
+ parameter :archive_role, default: :archive
111
+ parameter :logrotate_max_age, default: DefaultLogrotateMaxAge
112
+ parameter :logrotate_interval, default: (ENV['LUBAN_LOGROTATE_INTERVAL'] || DefaultLogrotateInterval).to_i
128
113
 
129
114
  def env_name
130
115
  @env_name ||= "#{stage}.#{project}/#{application}"
@@ -144,21 +129,12 @@ module Luban
144
129
 
145
130
  protected
146
131
 
147
- def set_default_application_parameters
148
- set_default :scm_role, :scm
149
- set_default :archive_role, :archive
150
- set_default :logrotate_max_age, DefaultLogrotateMaxAge
151
- set_default :logrotate_interval,
152
- (ENV['LUBAN_LOGROTATE_INTERVAL'] || DefaultLogrotateInterval).to_i
153
- setup_default_application_config_finder
154
- end
155
-
156
- def setup_default_application_config_finder
132
+ def set_default_for_application_config_finder
157
133
  config_finder[:application] ||=
158
134
  Luban::Deployment::Helpers::Configuration::Finder.application(self)
159
135
  end
160
136
 
161
- def validate_application_parameters
137
+ def validate_for_application
162
138
  if application.nil?
163
139
  abort "Aborted! Please specify the application name - application 'app name'"
164
140
  end
@@ -1,5 +1,5 @@
1
1
  module Luban
2
2
  module Deployment
3
- VERSION = "0.9.9"
3
+ VERSION = "0.9.10"
4
4
  end
5
5
  end
@@ -38,6 +38,15 @@ module Luban
38
38
  update_result(__return__: @run_blk ? run_with_block : run_with_command).to_h
39
39
  end
40
40
 
41
+ def method_missing(sym, *args, &blk)
42
+ if args.empty? and blk.nil? and config.has_key?(sym)
43
+ singleton_class.send(:define_method, sym) { config.fetch(__method__) }
44
+ send(sym)
45
+ else
46
+ super
47
+ end
48
+ end
49
+
41
50
  protected
42
51
 
43
52
  def create_task(task)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: luban
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.9
4
+ version: 0.9.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rubyist Lei
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-20 00:00:00.000000000 Z
11
+ date: 2016-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: luban-cli