capistrano-config 0.0.4 → 0.0.5

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.
@@ -18,4 +18,6 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.add_dependency("capistrano")
21
+ gem.add_dependency("capistrano-file-resources")
22
+ gem.add_dependency("capistrano-file-transfer-ext", "~> 0.0.3")
21
23
  end
@@ -1,6 +1,7 @@
1
1
  require "capistrano-config/version"
2
- require 'erb'
3
- require 'tempfile'
2
+ require "capistrano/configuration/actions/file_transfer_ext"
3
+ require "capistrano/configuration/resources/file_resources"
4
+ require "erb"
4
5
 
5
6
  module Capistrano
6
7
  module ConfigRecipe
@@ -15,97 +16,26 @@ module Capistrano
15
16
  _cset(:config_use_shared, false)
16
17
  _cset(:config_shared_path) { File.join(shared_path, 'config') }
17
18
 
18
- _cset(:config_readable_mode, "ug+r")
19
+ _cset(:config_readable_mode, "a+r")
19
20
  _cset(:config_readable_files, [])
20
- _cset(:config_writable_mode, "ug+rw")
21
+ _cset(:config_writable_mode, "a+rw")
21
22
  _cset(:config_writable_files, [])
22
- _cset(:config_executable_mode, "ug+rx")
23
+ _cset(:config_executable_mode, "a+rx")
23
24
  _cset(:config_executable_files, [])
24
25
  _cset(:config_remove_files, [])
25
26
 
26
- def tempfile(name)
27
- f = Tempfile.new(name)
28
- path = f.path
29
- f.close(true) # close and remove tempfile immediately
30
- path
31
- end
32
-
33
- def template(config)
34
- if File.file?(config)
35
- File.read(config)
36
- elsif File.file?("#{config}.erb")
37
- ERB.new(File.read("#{config}.erb")).result(binding)
38
- else
39
- abort("config: no such template found: #{config} or #{config}.erb")
40
- end
41
- end
42
-
43
- def update_one(source, target, options={})
44
- try_sudo = options[:use_sudo] ? sudo : ""
45
- execute = []
46
- dirs = [ File.dirname(source), File.dirname(target) ].uniq
47
- execute << "#{try_sudo} mkdir -p #{dirs.map { |d| d.dump }.join(' ')}"
48
- execute << "( #{try_sudo} diff -u #{target.dump} #{source.dump} || #{try_sudo} mv -f #{source.dump} #{target.dump} )"
49
-
50
- execute << "#{try_sudo} chmod #{config_readable_mode} #{target.dump}" if options[:readable_files].include?(target)
51
- execute << "#{try_sudo} chmod #{config_writable_mode} #{target.dump}" if options[:writable_files].include?(target)
52
- execute << "#{try_sudo} chmod #{config_executable_mode} #{target.dump}" if options[:executable_files].include?(target)
53
- execute << "#{try_sudo} rm -f #{config_remove_files.map { |f| f.dump }.join(' ')}" if options[:remove_files].include?(target)
54
-
55
- execute.join(' && ')
56
- end
57
-
58
- def update_all(files={}, options={})
59
- srcs = files.map { |src, dst| src }
60
- tmps = files.map { tempfile("capistrano-config") }
61
- dsts = files.map { |src, dst| dst }
62
- begin
63
- srcs.zip(tmps).each do |src, tmp|
64
- put(template(src), tmp)
65
- end
66
- tmps.zip(dsts).each do |tmp, dst|
67
- run(update_one(tmp, dst, options.merge(:use_sudo => fetch(:config_use_sudo_remotely, false))))
68
- end
69
- ensure
70
- run("rm -f #{tmps.map { |f| f.dump }.join(' ')}") unless tmps.empty?
71
- end
72
- end
73
-
74
- def update_all_locally(files={}, options={})
75
- srcs = files.map { |src, dst| src }
76
- tmps = files.map { tempfile("capistrano-config") }
77
- dsts = files.map { |src, dst| dst }
78
- begin
79
- srcs.zip(tmps).each do |src, tmp|
80
- File.open(tmp, 'wb') { |fp| fp.write(template(src)) } unless dry_run
81
- end
82
- tmps.zip(dsts).each do |tmp, dst|
83
- run_locally(update_one(tmp, dst, options.merge(:use_sudo => fetch(:config_use_sudo_locally, false))))
84
- end
85
- ensure
86
- run_locally("rm -f #{tmps.map { |f| f.dump }.join(' ')}") unless tmps.empty?
87
- end
88
- end
89
-
90
- def symlink_all(files={}, options={})
91
- execute = []
92
- files.each do |src, dst|
93
- execute << "( rm -f #{dst.dump} && ln -s #{src.dump} #{dst.dump} )"
94
- end
95
- run(execute.join(' && '))
96
- end
97
-
98
27
  desc("Setup shared application config.")
99
28
  task(:setup, :roles => :app, :except => { :no_release => true }) {
100
29
  if config_use_shared
101
- srcs = config_files.map { |f| File.join(config_template_path, f) }
102
- dsts = config_files.map { |f| File.join(config_shared_path, f) }
103
- update_all(srcs.zip(dsts),
104
- :readable_files => config_readable_files.map { |f| File.join(config_shared_path, f) },
105
- :writable_files => config_writable_files.map { |f| File.join(config_shared_path, f) },
106
- :executable_files => config_executable_files.map { |f| File.join(config_shared_path, f) },
107
- :remove_files => config_remove_files.map { |f| File.join(config_shared_path, f) }
108
- )
30
+ config_files.each do |f|
31
+ safe_put(template(f, :path => config_template_path), File.join(config_shared_path, f), :place => :if_modified)
32
+ end
33
+ execute = []
34
+ execute << "#{try_sudo} chmod #{config_readable_mode} #{config_readable_files.map { |f| File.join(config_shared_path, f).dump }.join(' ')}" unless config_readable_files.empty?
35
+ execute << "#{try_sudo} chmod #{config_writable_mode} #{config_writable_files.map { |f| File.join(config_shared_path, f).dump }.join(' ')}" unless config_writable_files.empty?
36
+ execute << "#{try_sudo} chmod #{config_executable_mode} #{config_executable_files.map { |f| File.join(config_shared_path, f).dump }.join(' ')}" unless config_executable_files.empty?
37
+ execute << "#{try_sudo} rm -f #{config_remove_files.map { |f| File.join(config_shared_path, f).dump }.join(' ')}" unless config_remove_files.empty?
38
+ run(execute.join(" && ")) unless execute.empty?
109
39
  end
110
40
  }
111
41
  after 'deploy:setup', 'config:setup'
@@ -121,30 +51,35 @@ module Capistrano
121
51
 
122
52
  task(:update_remotely, :roles => :app, :except => { :no_release => true }) {
123
53
  if config_use_shared
124
- srcs = config_files.map { |f| File.join(config_shared_path, f) }
125
- dsts = config_files.map { |f| File.join(config_path, f) }
126
- symlink_all(srcs.zip(dsts))
54
+ execute = []
55
+ config_files.each do |f|
56
+ execute << "( rm -f #{File.join(config_path, f).dump}; " +
57
+ "ln -sf #{File.join(config_shared_path, f).dump} #{File.join(config_path, f).dump} )"
58
+ end
59
+ run(execute.join(" && ")) unless execute.empty?
127
60
  else
128
- srcs = config_files.map { |f| File.join(config_template_path, f) }
129
- dsts = config_files.map { |f| File.join(config_path, f) }
130
- update_all(srcs.zip(dsts),
131
- :readable_files => config_readable_files.map { |f| File.join(config_path, f) },
132
- :writable_files => config_writable_files.map { |f| File.join(config_path, f) },
133
- :executable_files => config_executable_files.map { |f| File.join(config_path, f) },
134
- :remove_files => config_remove_files.map { |f| File.join(config_path, f) }
135
- )
61
+ config_files.each do |f|
62
+ safe_put(template(f, :path => config_template_path), File.join(config_path, f), :place => :if_modified)
63
+ end
64
+ execute = []
65
+ execute << "#{try_sudo} chmod #{config_readable_mode} #{config_readable_files.map { |f| File.join(config_path, f).dump }.join(' ')}" unless config_readable_files.empty?
66
+ execute << "#{try_sudo} chmod #{config_writable_mode} #{config_writable_files.map { |f| File.join(config_path, f).dump }.join(' ')}" unless config_writable_files.empty?
67
+ execute << "#{try_sudo} chmod #{config_executable_mode} #{config_executable_files.map { |f| File.join(config_path, f).dump }.join(' ')}" unless config_executable_files.empty?
68
+ execute << "#{try_sudo} rm -f #{config_remove_files.map { |f| File.join(config_path, f).dump }.join(' ')}" unless config_remove_files.empty?
69
+ run(execute.join(" && ")) unless execute.empty?
136
70
  end
137
71
  }
138
72
 
139
73
  task(:update_locally, :roles => :app, :except => { :no_release => true }) {
140
- srcs = config_files.map { |f| File.join(config_template_path, f) }
141
- dsts = config_files.map { |f| File.join(config_path_local, f) }
142
- update_all_locally(srcs.zip(dsts),
143
- :readable_files => config_readable_files.map { |f| File.join(config_path_local, f) },
144
- :writable_files => config_writable_files.map { |f| File.join(config_path_local, f) },
145
- :executable_files => config_executable_files.map { |f| File.join(config_path_local, f) },
146
- :remove_files => config_remove_files.map { |f| File.join(config_path_local, f) }
147
- )
74
+ config_files.each do |f|
75
+ File.write(File.join(config_path_local, f), template(f, :path => config_template_path))
76
+ end
77
+ execute = []
78
+ execute << "#{try_sudo} chmod #{config_readable_mode} #{config_readable_files.map { |f| File.join(config_path_local, f).dump }.join(' ')}" unless config_readable_files.empty?
79
+ execute << "#{try_sudo} chmod #{config_writable_mode} #{config_writable_files.map { |f| File.join(config_path_local, f).dump }.join(' ')}" unless config_writable_files.empty?
80
+ execute << "#{try_sudo} chmod #{config_executable_mode} #{config_executable_files.map { |f| File.join(config_path_local, f).dump }.join(' ')}" unless config_executable_files.empty?
81
+ execute << "#{try_sudo} rm -f #{config_remove_files.map { |f| File.join(config_path_local, f).dump }.join(' ')}" unless config_remove_files.empty?
82
+ run(execute.join(" && ")) unless execute.empty?
148
83
  }
149
84
  }
150
85
  }
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module ConfigRecipe
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-18 00:00:00.000000000 Z
12
+ date: 2013-02-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
@@ -27,6 +27,38 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: capistrano-file-resources
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: capistrano-file-transfer-ext
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.0.3
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.0.3
30
62
  description: a capistrano recipe to manage configurations files.
31
63
  email:
32
64
  - yamashita@geishatokyo.com