capistrano-env 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +10 -0
- data/Guardfile +17 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +6 -0
- data/capistrano-env.gemspec +29 -0
- data/lib/capistrano-env.rb +1 -0
- data/lib/capistrano/env.rb +13 -0
- data/lib/capistrano/env/config.rb +50 -0
- data/lib/capistrano/env/formatter/ruby_formatter.rb +15 -0
- data/lib/capistrano/env/plugin.rb +26 -0
- data/lib/capistrano/env/railtie.rb +12 -0
- data/lib/capistrano/env/version.rb +5 -0
- data/spec/capistrano/env/config_spec.rb +54 -0
- data/spec/capistrano/env/formatter/ruby_formatter_spec.rb +11 -0
- data/spec/capistrano/env/plugin_spec.rb +14 -0
- data/spec/capistrano/env/railtie_spec.rb +11 -0
- data/spec/capistrano/env_spec.rb +7 -0
- data/spec/dummy/.gitignore +16 -0
- data/spec/dummy/Gemfile +46 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +17 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/capenv.rb +3 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +21 -0
- data/spec/dummy/config/boot.rb +4 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/hoge.rb +1 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +56 -0
- data/spec/dummy/db/schema.rb +16 -0
- data/spec/dummy/db/seeds.rb +7 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/lib/tasks/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/robots.txt +5 -0
- data/spec/dummy/vendor/assets/javascripts/.keep +0 -0
- data/spec/dummy/vendor/assets/stylesheets/.keep +0 -0
- data/spec/spec_helper.rb +10 -0
- metadata +273 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e00329dc244bee9eadc29d79b75fa4cd7849fd4a
|
4
|
+
data.tar.gz: 84cc3f90598ab776c95b438da25a3aad4f627751
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0663b3e41ee6beb0e1bccff277399a6b70c8500c1853efec0f1ef84b1c48dd75baa239c51ac8269e83da6702a59c6bf2a179dd7448d6e7cb198589728ef81603
|
7
|
+
data.tar.gz: e165280f0e65a3f9cedca071e7780b481319db8600f88951a854335d04de3289beaea27aa8f261cd1185d397ca08f68a9fd29fcd876823893b96372d330d88b3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :rspec do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
|
9
|
+
# Rails example
|
10
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
11
|
+
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
12
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
13
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
14
|
+
watch('config/routes.rb') { "spec/routing" }
|
15
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
16
|
+
end
|
17
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 masarakki
|
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,49 @@
|
|
1
|
+
# Capistrano::Env
|
2
|
+
|
3
|
+
Capistrano with Env via file
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'capistrano-env'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install capistrano-env
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
|
22
|
+
#### 1. set env names in deploy.rb
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
capenv.use do |env|
|
26
|
+
env.add /^MYAPP_/
|
27
|
+
env.add 'UNICORN_PROCESSES'
|
28
|
+
env.add 'HOGE', 'hage'
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
#### 2. deploy
|
33
|
+
|
34
|
+
```
|
35
|
+
bundle exec cap production deploy
|
36
|
+
```
|
37
|
+
|
38
|
+
- automaticaly create #{current_path}/capenv.rb
|
39
|
+
- automaticaly load #{current_path}/capenv.rb in rails boot
|
40
|
+
- you should load manualy in other framework
|
41
|
+
- you can use ENV['ENV_NAME'] in application
|
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
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'capistrano/env/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "capistrano-env"
|
8
|
+
spec.version = Capistrano::Env::VERSION
|
9
|
+
spec.authors = ["masarakki"]
|
10
|
+
spec.email = ["masaki@hisme.net"]
|
11
|
+
spec.description = %q{capistrano with environments}
|
12
|
+
spec.summary = %q{capistrano with environments}
|
13
|
+
spec.homepage = "https://github.com/masarakki/capistrano-env"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "rails", ">= 3.0", "< 5.0"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "rspec-rails", '~> 3.0.0.beta'
|
27
|
+
spec.add_development_dependency "sqlite3"
|
28
|
+
spec.add_development_dependency "capistrano"
|
29
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'capistrano/env'
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Capistrano
|
2
|
+
module Env
|
3
|
+
class Config
|
4
|
+
attr_accessor :formatter
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@formatter = :ruby
|
8
|
+
@values = {}
|
9
|
+
@keys = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def add(name_or_regexp, val = nil)
|
13
|
+
if val && name_or_regexp.is_a?(String)
|
14
|
+
@values[name_or_regexp] = val
|
15
|
+
else
|
16
|
+
@keys << name_or_regexp
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def formatter_class
|
21
|
+
@formatter_class ||= begin
|
22
|
+
require "capistrano/env/formatter/#{@formatter}_formatter"
|
23
|
+
Capistrano::Env::Formatter.const_get "#{formatter.capitalize}Formatter"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def envs
|
28
|
+
result = {}
|
29
|
+
@keys.each do |key|
|
30
|
+
key_values = if key.is_a? Regexp
|
31
|
+
ENV.select{|x| x =~ key }
|
32
|
+
else
|
33
|
+
ENV.select{|x| x == key }
|
34
|
+
end
|
35
|
+
|
36
|
+
result.merge!(key_values)
|
37
|
+
end
|
38
|
+
result.merge(@values)
|
39
|
+
end
|
40
|
+
|
41
|
+
def capenv_file
|
42
|
+
"capenv.#{formatter_class.file_ext}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def capenv_content
|
46
|
+
formatter_class.format(envs)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Capistrano
|
2
|
+
module Env
|
3
|
+
module Plugin
|
4
|
+
def use
|
5
|
+
config = Capistrano::Env::Config.new
|
6
|
+
yield(config)
|
7
|
+
add config
|
8
|
+
config
|
9
|
+
end
|
10
|
+
|
11
|
+
def add(config)
|
12
|
+
namespace :deploy do
|
13
|
+
namespace :capenv do
|
14
|
+
task :copy do
|
15
|
+
parent.parent.upload StringIO.new(config.capenv_content), "#{fetch(:current_path)}/#{config.capenv_file}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
after 'deploy:finalize_update', 'deploy:capenv:copy'
|
20
|
+
before 'deploy:restart', 'deploy:capenv:copy'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Capistrano.plugin :capenv, Capistrano::Env::Plugin
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Capistrano
|
2
|
+
module Env
|
3
|
+
class Railtie < ::Rails::Railtie
|
4
|
+
config.before_configuration do
|
5
|
+
p :before_configuration
|
6
|
+
capenv_file = File.expand_path("./capenv.rb", Rails.root)
|
7
|
+
require capenv_file if File.exists?(capenv_file)
|
8
|
+
# p ENV
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Capistrano::Env::Config do
|
4
|
+
let(:config) { described_class.new }
|
5
|
+
describe :formatter do
|
6
|
+
it { expect(config.formatter).to eq :ruby }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe :formatter_class do
|
10
|
+
it { expect(config.formatter_class).to eq Capistrano::Env::Formatter::RubyFormatter }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe :capenv_file do
|
14
|
+
it { expect(config.capenv_file).to eq "capenv.rb" }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe :capenv_content do
|
18
|
+
it {
|
19
|
+
require 'capistrano/env/formatter/ruby_formatter'
|
20
|
+
allow(config).to receive(:envs).and_return( { "a" => "b" } )
|
21
|
+
expect(Capistrano::Env::Formatter::RubyFormatter).to receive(:format).with({"a" => "b"}).and_return "hello"
|
22
|
+
expect(config.capenv_content).to eq "hello"
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
describe :add do
|
27
|
+
before do
|
28
|
+
ENV["CAPENV_TEST_A"] = "a"
|
29
|
+
ENV["CAPENV_TEST_B"] = "1,2,3"
|
30
|
+
ENV["CAPENV_TEST"] = "$"
|
31
|
+
ENV["VAPENV_XYZ_A"] = "X"
|
32
|
+
end
|
33
|
+
|
34
|
+
describe :regex do
|
35
|
+
before do
|
36
|
+
config.add /^CAPENV_TEST_/
|
37
|
+
end
|
38
|
+
it { expect(config.envs).to eq({"CAPENV_TEST_A" => "a", "CAPENV_TEST_B" => "1,2,3"}) }
|
39
|
+
end
|
40
|
+
describe :string do
|
41
|
+
before do
|
42
|
+
config.add "CAPENV_TEST"
|
43
|
+
end
|
44
|
+
it { expect(config.envs).to eq({"CAPENV_TEST" => "$"}) }
|
45
|
+
end
|
46
|
+
describe :override do
|
47
|
+
before do
|
48
|
+
config.add /^CAPENV_TEST_/
|
49
|
+
config.add "CAPENV_TEST_B", "UNKO"
|
50
|
+
end
|
51
|
+
it { expect(config.envs).to eq({"CAPENV_TEST_A" => "a", "CAPENV_TEST_B" => "UNKO"}) }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'capistrano/env/formatter/ruby_formatter'
|
3
|
+
|
4
|
+
describe Capistrano::Env::Formatter::RubyFormatter do
|
5
|
+
let(:envs) { {"HELLO" => "WORLD", "HOGE" => "1,2,3"} }
|
6
|
+
expect_string =<<EOF
|
7
|
+
ENV["HELLO"] = "WORLD"
|
8
|
+
ENV["HOGE"] = "1,2,3"
|
9
|
+
EOF
|
10
|
+
it { expect(described_class.format(envs)).to eq expect_string }
|
11
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Capistrano::Env::Plugin do
|
4
|
+
let(:capistrano) { Capistrano::Configuration.new }
|
5
|
+
|
6
|
+
describe :capenv do
|
7
|
+
let(:setup) { capistrano.capenv.use {|config| ; } }
|
8
|
+
it 'add task' do
|
9
|
+
expect(capistrano.capenv).to receive(:add)
|
10
|
+
setup
|
11
|
+
end
|
12
|
+
it { expect(setup).to be_a Capistrano::Env::Config }
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Capistrano::Env::Railtie" do
|
4
|
+
describe "use in application.rb" do
|
5
|
+
it { expect(Rails.configuration.hello).to eq "WORLD" }
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "use in initializers" do
|
9
|
+
it { expect(Rails.configuration.hoge).to eq "HAGE" }
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile '~/.gitignore_global'
|
6
|
+
|
7
|
+
# Ignore bundler config.
|
8
|
+
/.bundle
|
9
|
+
|
10
|
+
# Ignore the default SQLite database.
|
11
|
+
/db/*.sqlite3
|
12
|
+
/db/*.sqlite3-journal
|
13
|
+
|
14
|
+
# Ignore all logfiles and tempfiles.
|
15
|
+
/log/*.log
|
16
|
+
/tmp
|
data/spec/dummy/Gemfile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
4
|
+
gem 'rails', '4.0.1'
|
5
|
+
|
6
|
+
# Use sqlite3 as the database for Active Record
|
7
|
+
gem 'sqlite3'
|
8
|
+
|
9
|
+
# Use SCSS for stylesheets
|
10
|
+
gem 'sass-rails', '~> 4.0.0'
|
11
|
+
|
12
|
+
# Use Uglifier as compressor for JavaScript assets
|
13
|
+
gem 'uglifier', '>= 1.3.0'
|
14
|
+
|
15
|
+
# Use CoffeeScript for .js.coffee assets and views
|
16
|
+
gem 'coffee-rails', '~> 4.0.0'
|
17
|
+
|
18
|
+
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
19
|
+
# gem 'therubyracer', platforms: :ruby
|
20
|
+
|
21
|
+
# Use jquery as the JavaScript library
|
22
|
+
gem 'jquery-rails'
|
23
|
+
|
24
|
+
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
|
25
|
+
gem 'turbolinks'
|
26
|
+
|
27
|
+
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
|
28
|
+
gem 'jbuilder', '~> 1.2'
|
29
|
+
|
30
|
+
group :doc do
|
31
|
+
# bundle exec rake doc:rails generates the API under doc/api.
|
32
|
+
gem 'sdoc', require: false
|
33
|
+
end
|
34
|
+
|
35
|
+
# Use ActiveModel has_secure_password
|
36
|
+
# gem 'bcrypt-ruby', '~> 3.1.2'
|
37
|
+
|
38
|
+
# Use unicorn as the app server
|
39
|
+
# gem 'unicorn'
|
40
|
+
|
41
|
+
# Use Capistrano for deployment
|
42
|
+
# gem 'capistrano', group: :development
|
43
|
+
|
44
|
+
# Use debugger
|
45
|
+
# gem 'debugger', group: [:development, :test]
|
46
|
+
gemspec path: File.expand_path('../../../', __FILE__)
|