lib/application.rb in docman-0.0.16 vs lib/application.rb in docman-0.0.17
- old
+ new
@@ -44,49 +44,58 @@
@config = Docman::Config.new(File.join(Pathname(__FILE__).dirname.parent, 'config', 'config.yaml'))
@force = false
end
def init(name, repo)
- `mkdir #{name} && cd #{name} && git clone #{repo} config`
+ `mkdir #{name} && cd #{name} && git clone --depth 1 #{repo} config`
end
+ def with_rescue
+ failed_filepath = File.join(@workspace_dir, 'failed')
+ if File.file?(failed_filepath)
+ log 'Last operation failed, forced rebuild mode'
+ FileUtils.rm_f failed_filepath
+ @force = true
+ end
+ yield
+ rescue Exception => e
+ log "Operation failed: #{e.message}", 'error'
+ File.open(failed_filepath, 'w') {|f| f.write('Failed!') }
+ raise e
+ end
+
def build(deploy_target_name, state, options = false)
- @options = options
- @deploy_target = @config['deploy_targets'][deploy_target_name]
- @deploy_target['name'] = deploy_target_name
- @docroot_config = DocrootConfig.new(@workspace_dir, deploy_target)
- execute('build', state, nil, options['tag'])
+ with_rescue do
+ @options = options
+ @deploy_target = @config['deploy_targets'][deploy_target_name]
+ @deploy_target['name'] = deploy_target_name
+ @docroot_config = DocrootConfig.new(@workspace_dir, deploy_target)
+ execute('build', state, nil, options['tag'])
+ end
end
def deploy(deploy_target_name, name, type, version, options = false)
- @options = options
- @deploy_target = @config['deploy_targets'][deploy_target_name]
- raise "Wrong deploy target: #{deploy_target_name}" if @deploy_target.nil?
- @deploy_target['name'] = deploy_target_name
- @docroot_config = DocrootConfig.new(@workspace_dir, deploy_target)
- @docroot_config.states_dependin_on(name, version).keys.each do |state|
- execute('deploy', state, name)
+ with_rescue do
+ @options = options
+ @deploy_target = @config['deploy_targets'][deploy_target_name]
+ raise "Wrong deploy target: #{deploy_target_name}" if @deploy_target.nil?
+ @deploy_target['name'] = deploy_target_name
+ @docroot_config = DocrootConfig.new(@workspace_dir, deploy_target)
+ @docroot_config.states_dependin_on(name, version).keys.each do |state|
+ execute('deploy', state, name)
+ end
end
end
def execute(action, state, name = nil, tag = nil)
params = Marshal.load(Marshal.dump(@deploy_target))
- failed_filepath = File.join(@workspace_dir, 'failed')
- if File.file?(failed_filepath)
- log 'Last operation failed, forced rebuild mode'
- FileUtils.rm_f failed_filepath
- @force = true
- end
params['state'] = state
params['action'] = action
params['name'] = name
- params['tag'] = tag
+ params['tag'] = tag ? tag : state + '-' + Time.now.strftime("%Y-%m-%d-%H-%M-%S")
params['environment'] = @config['environments'][@deploy_target['states'][state]]
params['environment_name'] = @deploy_target['states'][state]
Docman::Deployers::Deployer.create(params, nil, self).perform
- rescue Exception => e
- log "Operation failed: #{e.message}", 'error'
- File.open(failed_filepath, 'w') {|f| f.write('Failed!') }
end
def force?
@force or @options[:force]
end