capifig 0.0.1
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.
- data/.gitignore +22 -0
- data/.travis.yml +12 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/capifig.gemspec +21 -0
- data/lib/capifig.rb +5 -0
- data/lib/capifig/capistrano.rb +30 -0
- data/lib/capifig/configuration.rb +46 -0
- data/lib/capifig/version.rb +3 -0
- data/sample/.env +1 -0
- data/sample/Procfile +1 -0
- data/sample/config/database.yml +3 -0
- data/spec/capistrano_spec.rb +37 -0
- data/spec/configuration_spec.rb +50 -0
- data/spec/spec_helper.rb +10 -0
- metadata +83 -0
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
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
|
18
|
+
*.iml
|
19
|
+
*.ipr
|
20
|
+
*.iws
|
21
|
+
.rakeTasks
|
22
|
+
*.log
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Ralf Kistner
|
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,31 @@
|
|
1
|
+
# Capifig
|
2
|
+
|
3
|
+
Deploy different configuration per stage with Capistrano (with the multi-stage extension).
|
4
|
+
|
5
|
+
The 0.0.x releases of this gem are unstable, and the API/usage may change significantly, even in minor version
|
6
|
+
increments.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'capifig'
|
13
|
+
|
14
|
+
Add the following line to your Capistrano deploy.rb:
|
15
|
+
|
16
|
+
require 'capifig/capistrano'
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
For each stage, create a folder in `config/deploy/stages/<stage>`, containing all the config files specific to that
|
21
|
+
stage. On deployment (after deploy:update_code), these files will be copied to your app's root. Subfolders may be used,
|
22
|
+
but must already exist on the server. For example, if you have a folder `config/deploy/stages/production/dbconfig`, you
|
23
|
+
also need a folder `dbconfig` in the root of your app.
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/capifig.gemspec
ADDED
@@ -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 'capifig/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "capifig"
|
8
|
+
gem.version = Capifig::VERSION
|
9
|
+
gem.authors = ["Ralf Kistner"]
|
10
|
+
gem.email = ["ralf@embarkmobile.com"]
|
11
|
+
gem.description = %q{Deploy different configuration per stage with Capistrano (with the multi-stage extension).}
|
12
|
+
gem.summary = %q{Deploy different configuration per stage with Capistrano.}
|
13
|
+
gem.homepage = ""
|
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', '>= 2.0.0'
|
21
|
+
end
|
data/lib/capifig.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Defines capifig:deploy which deploys configuration
|
2
|
+
require 'capistrano'
|
3
|
+
require 'capifig/configuration'
|
4
|
+
|
5
|
+
module Capifig
|
6
|
+
module Capistrano
|
7
|
+
def self.load_into(configuration)
|
8
|
+
configuration.load do
|
9
|
+
after "deploy:update_code", "capifig:deploy"
|
10
|
+
|
11
|
+
namespace :capifig do
|
12
|
+
desc <<-DESC
|
13
|
+
Deploy configuration files.
|
14
|
+
DESC
|
15
|
+
task :deploy do
|
16
|
+
stage = fetch(:stage, 'production')
|
17
|
+
config_path = fetch(:config_path, "config/deploy/stages/#{stage}")
|
18
|
+
Capifig::Configuration.deploy(configuration, config_path)
|
19
|
+
logger.info "Configuration deployment complete."
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
if Capistrano::Configuration.instance
|
28
|
+
# Automatically load configuration into capistrano, if capistrano is being configured
|
29
|
+
Capifig::Capistrano.load_into(Capistrano::Configuration.instance)
|
30
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module Capifig
|
4
|
+
class Configuration
|
5
|
+
def self.deploy configuration, path
|
6
|
+
Configuration.new(configuration, path).deploy
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_accessor :path
|
10
|
+
attr_accessor :cap
|
11
|
+
|
12
|
+
def initialize(configuration, path)
|
13
|
+
@cap = configuration
|
14
|
+
@path = path
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returns an array of local paths of files to upload
|
18
|
+
def files
|
19
|
+
# Alternative: this glob also works, but may include temporary files:
|
20
|
+
#files = Dir.glob("#@path/**/*", File::FNM_DOTMATCH).select { |f| File.file?(f) }
|
21
|
+
files = `git ls-files #@path`.split($/)
|
22
|
+
files.sort
|
23
|
+
end
|
24
|
+
|
25
|
+
# Given a local path, returns the remote path for the file
|
26
|
+
def remote_path(file)
|
27
|
+
path = Pathname.new(cap.fetch(:release_path)) + relative_path(file)
|
28
|
+
path.to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
# Given a local path, returns the relative path to the file
|
32
|
+
def relative_path(file)
|
33
|
+
path = Pathname.new(file).relative_path_from(Pathname.new(@path)).to_s
|
34
|
+
# For security reasons, we check that the path does not contain any ..'s
|
35
|
+
raise ArgumentError, "File '#{file}' is not in '#@path'" if path.include? '..'
|
36
|
+
path
|
37
|
+
end
|
38
|
+
|
39
|
+
def deploy
|
40
|
+
files.each do |f|
|
41
|
+
cap.upload(f, remote_path(f))
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/sample/.env
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
RAILS_ENV=production
|
data/sample/Procfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
worker: echo "working"
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'capifig/capistrano'
|
3
|
+
require 'capifig/configuration'
|
4
|
+
|
5
|
+
describe Capifig::Capistrano do
|
6
|
+
let(:cap) do
|
7
|
+
cap = Capistrano::Configuration.new
|
8
|
+
Capifig::Capistrano.load_into cap
|
9
|
+
cap.dry_run = true
|
10
|
+
cap
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should define capifig:deploy" do
|
14
|
+
cap.find_task('capifig:deploy').should be
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should deploy config files on capifig:deploy" do
|
18
|
+
Capifig::Configuration.should_receive(:deploy).with(cap, 'config/deploy/stages/production')
|
19
|
+
|
20
|
+
cap.find_and_execute_task('capifig:deploy')
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should should get config path from the current stage" do
|
24
|
+
cap.set(:stage, 'test-stage')
|
25
|
+
Capifig::Configuration.should_receive(:deploy).with(cap, 'config/deploy/stages/test-stage')
|
26
|
+
|
27
|
+
cap.find_and_execute_task('capifig:deploy')
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should should allow overriding of the config path" do
|
31
|
+
cap.set(:stage, 'test-stage')
|
32
|
+
cap.set(:config_path, 'my/config/path')
|
33
|
+
Capifig::Configuration.should_receive(:deploy).with(cap, 'my/config/path')
|
34
|
+
|
35
|
+
cap.find_and_execute_task('capifig:deploy')
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'capifig/configuration'
|
3
|
+
|
4
|
+
describe Capifig::Configuration do
|
5
|
+
let(:cap) do
|
6
|
+
cap = Capistrano::Configuration.new
|
7
|
+
cap.dry_run = true
|
8
|
+
cap.set(:release_path, '/tmp/the/release')
|
9
|
+
cap
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:config) do
|
13
|
+
Capifig::Configuration.new(cap, 'sample')
|
14
|
+
end
|
15
|
+
|
16
|
+
context "list files" do
|
17
|
+
let(:expected) { %w(sample/.env sample/Procfile sample/config/database.yml) }
|
18
|
+
|
19
|
+
after do
|
20
|
+
FileUtils.rm_f 'sample/temp-file~'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should list files" do
|
24
|
+
config.files.should == expected
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should not list temporary files" do
|
28
|
+
File.open('sample/temp-file~', 'w').close
|
29
|
+
config.files.should == expected
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should make remote path" do
|
34
|
+
config.relative_path('sample/config/database.yml').should == 'config/database.yml'
|
35
|
+
config.remote_path('sample/config/database.yml').should == '/tmp/the/release/config/database.yml'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should not allow .. in paths" do
|
39
|
+
-> { config.relative_path('config/database.yml') }.should raise_error(ArgumentError)
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
it "should deploy" do
|
44
|
+
cap.should_receive(:upload).with('sample/.env', '/tmp/the/release/.env')
|
45
|
+
cap.should_receive(:upload).with('sample/Procfile', '/tmp/the/release/Procfile')
|
46
|
+
cap.should_receive(:upload).with('sample/config/database.yml', '/tmp/the/release/config/database.yml')
|
47
|
+
Capifig::Configuration.deploy cap, 'sample'
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capifig
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ralf Kistner
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-21 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: 2.0.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: 2.0.0
|
30
|
+
description: Deploy different configuration per stage with Capistrano (with the multi-stage
|
31
|
+
extension).
|
32
|
+
email:
|
33
|
+
- ralf@embarkmobile.com
|
34
|
+
executables: []
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- .gitignore
|
39
|
+
- .travis.yml
|
40
|
+
- Gemfile
|
41
|
+
- LICENSE.txt
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- capifig.gemspec
|
45
|
+
- lib/capifig.rb
|
46
|
+
- lib/capifig/capistrano.rb
|
47
|
+
- lib/capifig/configuration.rb
|
48
|
+
- lib/capifig/version.rb
|
49
|
+
- sample/.env
|
50
|
+
- sample/Procfile
|
51
|
+
- sample/config/database.yml
|
52
|
+
- spec/capistrano_spec.rb
|
53
|
+
- spec/configuration_spec.rb
|
54
|
+
- spec/spec_helper.rb
|
55
|
+
homepage: ''
|
56
|
+
licenses: []
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.8.24
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Deploy different configuration per stage with Capistrano.
|
79
|
+
test_files:
|
80
|
+
- spec/capistrano_spec.rb
|
81
|
+
- spec/configuration_spec.rb
|
82
|
+
- spec/spec_helper.rb
|
83
|
+
has_rdoc:
|