capistrano-upload-config 0.1.0
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/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +133 -0
- data/Rakefile +1 -0
- data/capistrano-upload-config.gemspec +24 -0
- data/lib/capistrano-upload-config.rb +18 -0
- data/lib/upload-config/tasks.rake +64 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dde3a6365279fc68794a1c8cc8938d6b0f042373
|
4
|
+
data.tar.gz: c67453f9d0ffa572d0c23f01922396ba7b00919e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6a99074b5c47f0fb34abc3525973a0474237d2566deea9d26f731fd8a852d8a86780ea1c740bc55f42f11031e6122e9e53c9ccc565bede8aaa9b1c2540c043ea
|
7
|
+
data.tar.gz: 81324123e0ff7512c6e634836ba9e977a4559977261cd9a53a0365d4dc6f2644a4b8ddad657e3478657054be45655603464e15c9c41e0b5cf226e926edb2c124
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Robert Coleman
|
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,133 @@
|
|
1
|
+
# Capistrano-Upload-Config
|
2
|
+
|
3
|
+
Upload, initialize and maintain configuration files for Capistrano 3.x outside of SCM.
|
4
|
+
(or in SCM just different files for different stages - the choice is yours!)
|
5
|
+
|
6
|
+
Say you're working in a small team on a Rails app, you've got a couple of environments and you have a `config/database.yml` that's got some secrets that differ per stage in it.
|
7
|
+
You'd like to maintain these secrets outside of source control but placing a `config/database.yml` on the server manually makes you nervous. What happens if it's lost? Did you upload the right one? Chaos. Stress. Sad face.
|
8
|
+
|
9
|
+
Capistrano-upload-config to the rescue. You can maintain a version of `config/database.yml` per stage, with different contents if you wish, keep these outside of your source control and still upload them without manual fiddling.
|
10
|
+
|
11
|
+
Equally this could be used to manage many other text based configuration files and used if you're in a team or not.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'capistrano', '~> 3.1.0'
|
19
|
+
gem 'capistrano-upload-config'
|
20
|
+
```
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
`$ bundle`
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
`$ gem install capistrano-upload-config`
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
Require the module in your `Capfile`:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
require 'capistrano-upload-config'
|
36
|
+
```
|
37
|
+
|
38
|
+
`capistrano-upload-config` comes with 3 tasks:
|
39
|
+
|
40
|
+
* `config:check`
|
41
|
+
* `config:init`
|
42
|
+
* `config:push`
|
43
|
+
|
44
|
+
|
45
|
+
#### config:check
|
46
|
+
|
47
|
+
This task checks to see if all your set configuration files exist for the current stage:
|
48
|
+
|
49
|
+
```shell
|
50
|
+
$ cap staging config:check
|
51
|
+
INFO Found: config/database.staging.yml
|
52
|
+
WARN Not found: config/example.staging.yml
|
53
|
+
```
|
54
|
+
|
55
|
+
|
56
|
+
#### config:init
|
57
|
+
|
58
|
+
This creates the configured config files for the current stage if it doesn't already exist.
|
59
|
+
Bonus: It copies from an example file if one exists.
|
60
|
+
|
61
|
+
|
62
|
+
```shell
|
63
|
+
$ cap staging config:init
|
64
|
+
WARN Already Exists: config/database.staging.yml
|
65
|
+
INFO Copied: config/example.yml-example to config/example.staging.yml
|
66
|
+
Created: config/foobar.staging.yml as empty file
|
67
|
+
```
|
68
|
+
|
69
|
+
|
70
|
+
#### config:push
|
71
|
+
|
72
|
+
This task creates the config on the remote server.
|
73
|
+
|
74
|
+
|
75
|
+
```shell
|
76
|
+
$ cap staging config:init
|
77
|
+
WARN Already Exists: config/database.staging.yml
|
78
|
+
INFO Copied: config/example.yml-example to config/example.staging.yml
|
79
|
+
Created: config/foobar.staging.yml as empty file
|
80
|
+
```
|
81
|
+
|
82
|
+
Can be used during a deploy, If your `:config_files` and `:linked_files` are going to be the same I suggest hooking in before
|
83
|
+
`deploy:starting` to that the config files exist before symlinks are created:
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
# add to config/deploy.rb
|
87
|
+
|
88
|
+
before 'deploy:starting', 'config:push'
|
89
|
+
```
|
90
|
+
|
91
|
+
|
92
|
+
### Configuration
|
93
|
+
|
94
|
+
Configurable options, shown here with defaults:
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
set :config_files, fetch(:linked_files)
|
98
|
+
set :config_example_prefix, '-example'
|
99
|
+
```
|
100
|
+
|
101
|
+
By default your `:linked_files` are assumed to be config files, this might be totally wrong for your environment, never fear just:
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
# in deploy.rb (or similar)
|
105
|
+
|
106
|
+
set :config_files, %w{dir1/config.toml config/example.ini hidden/secrets.json}
|
107
|
+
|
108
|
+
```
|
109
|
+
|
110
|
+
Note, capistrano-upload-config can only upload confir to your shared folder (and it's sub directories) so it's likely that `:config_files` will be a subset of `:linked_files`.
|
111
|
+
|
112
|
+
#### Example files
|
113
|
+
|
114
|
+
Do you use example files checked into your source control? e.g. `config/database.yml-example`
|
115
|
+
These will be used when running `config:init`. If your prefix differs, e.g. `config/database.yml.eg` set this as:
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
# in deploy.rb (or similar)
|
119
|
+
|
120
|
+
set :config_example_prefix, '.eg'
|
121
|
+
|
122
|
+
```
|
123
|
+
|
124
|
+
Note, only prefixes (i.e. after the whole filename) are supported.
|
125
|
+
|
126
|
+
|
127
|
+
## Contributing
|
128
|
+
|
129
|
+
1. Fork it
|
130
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
131
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
132
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
133
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'capistrano-upload-config'
|
7
|
+
spec.version = '0.1.0'
|
8
|
+
spec.authors = 'Robert Coleman'
|
9
|
+
spec.email = 'github@robert.net.nz'
|
10
|
+
spec.description = %q{Capistrano 3.x tasks to upload shared config that is stored outside of SCM}
|
11
|
+
spec.summary = %q{Capistrano 3.x tasks to upload shared config that is stored outside of SCM}
|
12
|
+
spec.homepage = 'https://github.com/rjocoleman/capistrano-upload-config'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_dependency 'capistrano', '>= 3.0'
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
23
|
+
spec.add_development_dependency 'rake'
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
load File.expand_path('../upload-config/tasks.rake', __FILE__)
|
2
|
+
|
3
|
+
module CapistranoUploadConfig
|
4
|
+
class Helpers
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def get_local_config_name(config, stage)
|
8
|
+
path = File.dirname(config)
|
9
|
+
extension = File.extname(config)
|
10
|
+
filename = File.basename(config, extension)
|
11
|
+
extension.sub!(/^\./, '')
|
12
|
+
local_file = [filename, stage, extension].join('.')
|
13
|
+
local_path = File.join(path, local_file)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
namespace :config do
|
2
|
+
|
3
|
+
desc 'Initialize local configuration files for each stage'
|
4
|
+
task :init do
|
5
|
+
run_locally do
|
6
|
+
fetch(:config_files).each do |config|
|
7
|
+
local_path = CapistranoUploadConfig::Helpers.get_local_config_name(config, fetch(:stage).to_s)
|
8
|
+
if File.exists?(local_path)
|
9
|
+
warn "Already Exists: #{local_path}"
|
10
|
+
else
|
11
|
+
example_prefix = fetch(:config_example_prefix, '')
|
12
|
+
if File.exists?("#{config}#{example_prefix}")
|
13
|
+
FileUtils.cp "#{config}#{example_prefix}", local_path
|
14
|
+
info "Copied: #{config}#{example_prefix} to #{local_path}"
|
15
|
+
else
|
16
|
+
File.open(local_path, "w") {}
|
17
|
+
info "Created: #{local_path} as empty file"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Check local configuration files for each stage'
|
25
|
+
task :check do
|
26
|
+
run_locally do
|
27
|
+
fetch(:config_files).each do |config|
|
28
|
+
local_path = CapistranoUploadConfig::Helpers.get_local_config_name(config, fetch(:stage).to_s)
|
29
|
+
if File.exists?(local_path)
|
30
|
+
info "Found: #{local_path}"
|
31
|
+
else
|
32
|
+
warn "Not found: #{local_path}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
desc 'Push configuration to the remote server'
|
39
|
+
task :push do
|
40
|
+
on release_roles :all do
|
41
|
+
within shared_path do
|
42
|
+
fetch(:config_files).each do |config|
|
43
|
+
local_path = CapistranoUploadConfig::Helpers.get_local_config_name(config, fetch(:stage).to_s)
|
44
|
+
if File.exists?(local_path)
|
45
|
+
info "Uploading config #{local_path} as #{config}"
|
46
|
+
upload! StringIO.new(local_path), File.join(shared_path, config)
|
47
|
+
else
|
48
|
+
fail "#{local_path} doesn't exist"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
namespace :load do
|
58
|
+
task :defaults do
|
59
|
+
|
60
|
+
set :config_files, -> { fetch(:linked_files) }
|
61
|
+
set :config_example_prefix, '-example'
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-upload-config
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert Coleman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capistrano
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Capistrano 3.x tasks to upload shared config that is stored outside of
|
56
|
+
SCM
|
57
|
+
email: github@robert.net.nz
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- capistrano-upload-config.gemspec
|
68
|
+
- lib/capistrano-upload-config.rb
|
69
|
+
- lib/upload-config/tasks.rake
|
70
|
+
homepage: https://github.com/rjocoleman/capistrano-upload-config
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.2.2
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Capistrano 3.x tasks to upload shared config that is stored outside of SCM
|
94
|
+
test_files: []
|