capistrano-overrides 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 ADDED
@@ -0,0 +1,23 @@
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
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ default.vim
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-overrides.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Maher Hawash
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,61 @@
1
+ # Capistrano::Overrides
2
+
3
+ Provides tasks to copy override configuration files for different stages.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'capistrano-overrides'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install capistrano-overrides
18
+
19
+ ## Usage
20
+
21
+ ### 1. Copying and decrypting secure tokens (encrypted files)
22
+ #### 1.1 Usage
23
+ ```ruby
24
+ bundle exec cap production deploy:update_secure_overrides
25
+ ```
26
+ * The current state of the gem assumes that your encrypted files are:
27
+ * In `config/overrides/production`
28
+ * They have an `asc` extension; e.g., `key.txt.asc`
29
+ * The task first checks whether the `asc` file has changed since the last deploy (using checksums) and only decrypt the `asc` file if the file has changed.
30
+ * It will ask for password during deploy, decrypt the file in memory, and place it in `{shared_path}/config/key.txt`
31
+
32
+ #### 1.1 Setup of encrypted file
33
+ Encrypt the file `key.txt` using a `symmetric cipher (-c)` and place it in `key.txt.asc (-o)`
34
+ ```ruby
35
+ gpg -a -c -o key.txt.asc key.txt
36
+
37
+ ```
38
+
39
+ ### 2. Copying override files for different stages.
40
+ ####2.1 Usage
41
+ ```ruby
42
+ bundle exec cap production deploy:copy_stage_configs
43
+ ```
44
+ * Setup your folder structure as follows:
45
+
46
+ ```
47
+ /config/overrides/
48
+ /staging/*
49
+ /production/*
50
+ /alpha/*
51
+ ```
52
+ * Upon deploy of the `stage`, all the files in the `stage` folder will be copied in `/config` and overwrite any files with the same name in that folder.
53
+
54
+ ## Contributing
55
+
56
+ 1. Fork it ( https://github.com/[my-github-username]/capistrano-overrides/fork )
57
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
58
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
59
+ 4. Push to the branch (`git push origin my-new-feature`)
60
+ 5. Create a new Pull Request
61
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano/overrides/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "capistrano-overrides"
8
+ spec.version = Capistrano::Overrides::VERSION
9
+ spec.authors = ["Maher Hawash", "Dave Miller"]
10
+ spec.email = ["mhawash@renewfund.com", "dave.miller@renewfund.com"]
11
+ spec.summary = %q{Capistrano stage configuration overrides.}
12
+ spec.description = %q{Capistrano stage configuration overrides.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_dependency "gpgme", '~> 2.0'
24
+
25
+ end
@@ -0,0 +1,3 @@
1
+ require "capistrano/overrides/version"
2
+
3
+ Dir[File.expand_path("../tasks/*.rake", __FILE__)].each { |file| load file }
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module Overrides
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,14 @@
1
+ namespace :deploy do
2
+ desc 'Copy Stage specific configs into place'
3
+ task :copy_overrides do
4
+ on roles(:app), :only => { :primary => true } do
5
+ within release_path do
6
+ source = "#{release_path}/config/overrides/#{fetch(:stage)}"
7
+ target = "#{release_path}/config"
8
+ execute %Q([ -d #{source} ] && cp -R #{source}/* #{target} || true)
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ before "deploy:copy_overrides", "deploy:copy_secure_overrides"
@@ -0,0 +1,53 @@
1
+ require 'gpgme'
2
+ # Note: to encrypt the file after a change use the command line:
3
+ # gpg -a -c -o config/overrides/#{stage}/filename.yml.asc config/overrides/#{stage}/filename.yml
4
+
5
+ namespace :deploy do
6
+ desc "update encrypted files in `stage` overrides, if necessary, and link"
7
+ task :copy_secure_overrides do
8
+ on roles(:all) do
9
+ stage = fetch(:stage)
10
+ Dir.glob(deploy_config_path.expand_path.dirname.join('overrides',stage.to_s,'*.asc')).each do |local_encrypted_file|
11
+ filename = File.split(local_encrypted_file).last.chomp('.asc')
12
+ remote_encrypted_file = "#{shared_path}/config/#{filename}.asc"
13
+ remote_plaintext_file = "#{shared_path}/config/#{filename}"
14
+ remote_override_file = "#{release_path}/config/overrides/#{stage}/#{filename}"
15
+ if chksums_differ?(local_encrypted_file, remote_encrypted_file)
16
+ plaintext = decrypt(local_encrypted_file)
17
+ execute "mkdir -p '#{shared_path}/config'"
18
+ upload! local_encrypted_file, remote_encrypted_file
19
+ upload! StringIO.new(plaintext), remote_plaintext_file
20
+ execute "chmod 600 #{remote_plaintext_file}"
21
+ end
22
+ execute "mkdir -p '#{release_path}/config/overrides/#{stage}'"
23
+ execute "/bin/ln -nsf #{remote_plaintext_file} #{remote_override_file}"
24
+ execute "rm -f #{remote_override_file}.asc"
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ def decrypt(local_encrypted_file)
31
+ got_it = false
32
+ while not got_it
33
+ begin
34
+ print "\nPlease enter the passphrase to decrypt %s: " % File.split(local_encrypted_file).last
35
+ password = $stdin.noecho(&:gets).chomp
36
+ crypto = GPGME::Crypto.new(:password => password)
37
+ data = crypto.decrypt File.read(local_encrypted_file)
38
+ plaintext = data.read
39
+ got_it = true
40
+ rescue GPGME::Error::DecryptFailed
41
+ puts "\nInvalid Password, decryption failed"
42
+ puts
43
+ end
44
+ end
45
+ plaintext
46
+ end
47
+
48
+ def chksums_differ?(local,remote)
49
+ local_hasher = system('which','sha1sum') ? 'sha1sum' : 'shasum'
50
+ local_chksum = `#{local_hasher} "#{local}"`.split(' ').first
51
+ remote_chksum = capture("[ -f #{remote} ] && sha1sum #{remote} || true").split(' ').first || 'file_not_found'
52
+ local_chksum != remote_chksum
53
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-overrides
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Maher Hawash
9
+ - Dave Miller
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-09-03 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '1.6'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: '1.6'
31
+ - !ruby/object:Gem::Dependency
32
+ name: rake
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: gpgme
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '2.0'
63
+ description: Capistrano stage configuration overrides.
64
+ email:
65
+ - mhawash@renewfund.com
66
+ - dave.miller@renewfund.com
67
+ executables: []
68
+ extensions: []
69
+ extra_rdoc_files: []
70
+ files:
71
+ - .gitignore
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - capistrano-overrides.gemspec
77
+ - lib/capistrano/overrides.rb
78
+ - lib/capistrano/overrides/version.rb
79
+ - lib/capistrano/tasks/overrides.rake
80
+ - lib/capistrano/tasks/secure.rake
81
+ homepage: ''
82
+ licenses:
83
+ - MIT
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ segments:
95
+ - 0
96
+ hash: -2059193147161923779
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ segments:
104
+ - 0
105
+ hash: -2059193147161923779
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 1.8.23
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: Capistrano stage configuration overrides.
112
+ test_files: []