capistrano-config 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-config.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Yamashita Yuu
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # capistrano-config
2
+
3
+ a capistrano recipe to manage configurations files.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'capistrano-config'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install capistrano-config
18
+
19
+ ## Usage
20
+
21
+ This recipes will try to update application config during Capistrano `deploy` tasks.
22
+
23
+ To enable this recipe, add following in your `config/deploy.rb`.
24
+ The template of `config/config.yml` will be read from either `./config/templates/config/config.yml` or `./config/templates/config/config.yml.erb` by default.
25
+
26
+ # in "config/deploy.rb"
27
+ require 'capistrano-config'
28
+ set(:config_files, %w(config/config.yml))
29
+
30
+ Following options are available to manage your configuration files.
31
+
32
+ * `:config_update_remotely` - specify whether update config files on remote machines or not. `true` by default.
33
+ * `:config_update_locally` - specify whether update config files on local machines or not. `false` by default.
34
+ * `:config_path` - specify configuration base directory on remote machines. use `release_path` by default.
35
+ * `:config_path_local` - specify configuration base directory on local machine. use `.` by default.
36
+ * `:config_template_path` - specify configuration template directory on local machine. use `./config/templates` by default.
37
+ * `:config_files` - specify list of configuration files in relative path. empty by default.
38
+ * `:config_readable_files` - list of files which should be readable. empty by default.
39
+ * `:config_writable_files` - list of files which should be writable. empty by default.
40
+ * `:config_executable_files` - list of files which should be executable. empty by default.
41
+ * `:config_remove_files` - list of files which should be removed. empty by default.
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create new Pull Request
50
+
51
+ ## Author
52
+
53
+ - YAMASHITA Yuu (https://github.com/yyuu)
54
+ - Geisha Tokyo Entertainment Inc. (http://www.geishatokyo.com/)
55
+
56
+ ## License
57
+
58
+ MIT
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano-config/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "capistrano-config"
8
+ gem.version = Capistrano::Config::VERSION
9
+ gem.authors = ["Yamashita Yuu"]
10
+ gem.email = ["yamashita@geishatokyo.com"]
11
+ gem.description = %q{a capistrano recipe to manage configurations files.}
12
+ gem.summary = %q{a capistrano recipe to manage configurations files.}
13
+ gem.homepage = "https://github.com/yyuu/capistrano-config"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency("capistrano")
21
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module Config
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,113 @@
1
+ require "capistrano-config/version"
2
+ require 'erb'
3
+ require 'tempfile'
4
+
5
+ module Capistrano
6
+ module ConfigRecipe
7
+ def self.extended(configuration)
8
+ configuration.load {
9
+ namespace(:config) {
10
+ _cset(:config_path) { release_path }
11
+ _cset(:config_path_local) { File.expand_path('.') }
12
+ _cset(:config_template_path) { File.join(File.expand_path('.'), 'config', 'templates') }
13
+ _cset(:config_files, [])
14
+ _cset(:config_source_files) {
15
+ config_files.map { |file| File.join(config_template_path, file) }
16
+ }
17
+ _cset(:config_temporary_files) {
18
+ config_files.map { |file|
19
+ f = Tempfile.new('config'); t = f.path
20
+ f.close(true) # remote tempfile immediately
21
+ t
22
+ }
23
+ }
24
+ _cset(:config_readable_mode, "ug+r")
25
+ _cset(:config_readable_files, [])
26
+ _cset(:config_writable_mode, "ug+rw")
27
+ _cset(:config_writable_files, [])
28
+ _cset(:config_executable_mode, "ug+rx")
29
+ _cset(:config_executable_files, [])
30
+ _cset(:config_remove_files, [])
31
+
32
+ desc("Update applicatin config.")
33
+ task(:update, :roles => :app, :except => { :no_release => true }) {
34
+ transaction {
35
+ update_locally if fetch(:config_update_locally, false)
36
+ update_remotely if fetch(:config_update_remotely, true)
37
+ }
38
+ }
39
+ after 'deploy:finalize_update', 'config:update'
40
+
41
+ def _read_config(config)
42
+ if File.file?(config)
43
+ File.read(config)
44
+ elsif File.file?("#{config}.erb")
45
+ ERB.new(File.read("#{config}.erb")).result(binding)
46
+ else
47
+ abort("config: no such template found: #{config} or #{config}.erb")
48
+ end
49
+ end
50
+
51
+ def _do_update(src_tmp_tgt, options={})
52
+ options = {
53
+ :readable_files => [], :writable_files => [], :executable_files => [],
54
+ :remove_files => [],
55
+ }.merge(options)
56
+ dirs = src_tmp_tgt.map { |src, tmp, tgt| File.dirname(tgt) }.uniq
57
+ execute = []
58
+ execute << "mkdir -p #{dirs.join(' ')}" unless dirs.empty?
59
+ src_tmp_tgt.map { |src, tmp, tgt|
60
+ execute << "( diff -u #{tgt} #{tmp} || #{sudo} mv -f #{tmp} #{tgt} )"
61
+ }
62
+ execute << "#{sudo} chmod #{config_readable_mode} #{options[:readable_files].join(' ')}" unless options[:readable_files].empty?
63
+ execute << "#{sudo} chmod #{config_writable_mode} #{options[:writable_files].join(' ')}" unless options[:writable_files].empty?
64
+ execute << "#{sudo} chmod #{config_executable_mode} #{options[:executable_files].join(' ')}" unless options[:executable_files].empty?
65
+ execute << "#{sudo} rm -f #{options[:remove_files].join(' ')}" unless options[:remove_files].empty?
66
+
67
+ execute.join(' && ')
68
+ end
69
+
70
+ task(:update_locally, :roles => :app, :except => { :no_release => true }) {
71
+ begin
72
+ target_files = config_files.map { |f| File.join(config_path_local, f) }
73
+ src_tmp_tgt = config_source_files.zip(config_temporary_files, target_files)
74
+ src_tmp_tgt.each { |src, tmp, tgt|
75
+ File.open(tmp, 'wb') { |fp| fp.write(_read_config(src)) } unless dry_run
76
+ }
77
+ run_locally(_do_update(src_tmp_tgt,
78
+ :readable_files => config_readable_files.map { |f| File.join(config_path_local, f) },
79
+ :writable_files => config_writable_files.map { |f| File.join(config_path_local, f) },
80
+ :executable_files => config_executable_files.map { |f| File.join(config_path_local, f) },
81
+ :remove_files => config_remove_files.map { |f| File.join(config_path_local, f) }))
82
+ ensure
83
+ run_locally("rm -f #{config_temporary_files.join(' ')}") unless config_temporary_files.empty?
84
+ end
85
+ }
86
+
87
+ task(:update_remotely, :roles => :app, :except => { :no_release => true }) {
88
+ begin
89
+ target_files = config_files.map { |f| File.join(config_path, f) }
90
+ src_tmp_tgt = config_source_files.zip(config_temporary_files, target_files)
91
+ src_tmp_tgt.each { |src, tmp, tgt|
92
+ put(_read_config(src), tmp)
93
+ }
94
+ run(_do_update(src_tmp_tgt,
95
+ :readable_files => config_readable_files.map { |f| File.join(config_path, f) },
96
+ :writable_files => config_writable_files.map { |f| File.join(config_path, f) },
97
+ :executable_files => config_executable_files.map { |f| File.join(config_path, f) },
98
+ :remove_files => config_remove_files.map { |f| File.join(config_path, f) }))
99
+ ensure
100
+ run("rm -f #{config_temporary_files.join(' ')}") unless config_temporary_files.empty?
101
+ end
102
+ }
103
+ }
104
+ }
105
+ end
106
+ end
107
+ end
108
+
109
+ if Capistrano::Configuration.instance
110
+ Capistrano::Configuration.instance.extend(Capistrano::ConfigRecipe)
111
+ end
112
+
113
+ # vim:set ft=ruby :
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-config
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yamashita Yuu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: a capistrano recipe to manage configurations files.
31
+ email:
32
+ - yamashita@geishatokyo.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - capistrano-config.gemspec
43
+ - lib/capistrano-config.rb
44
+ - lib/capistrano-config/version.rb
45
+ homepage: https://github.com/yyuu/capistrano-config
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.23
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: a capistrano recipe to manage configurations files.
69
+ test_files: []