capistrano-database-yml 1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 81e5035d9d8bcfc7aa939e7998b3951831afd974
4
+ data.tar.gz: 446cef3b8d633c68f8645e05994a9fadc3f33273
5
+ SHA512:
6
+ metadata.gz: d94a3bb350f08425f74e66f5985980f6ba8552763b1a12315e7ffa985fb429d7b6b6d9639ede18f9895bdcd6723708c568bd89524697854ab7e3032a714405d9
7
+ data.tar.gz: 8123784d09b9b52165036b8a5833768eb5302e3eb75dd4aefaea966307f773814cc1f739a805f7dc83c36e5210b57c1f1cf15095ba052be07f42850d5999330a
@@ -0,0 +1 @@
1
+ /pkg/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in *.gemspec
4
+ gemspec
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ capistrano-database-yml (1.0.1)
5
+ capistrano (>= 3.1)
6
+ sshkit (>= 1.2.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ airbrussh (1.0.2)
12
+ sshkit (>= 1.6.1, != 1.7.0)
13
+ capistrano (3.5.0)
14
+ airbrussh (>= 1.0.0)
15
+ capistrano-harrow
16
+ i18n
17
+ rake (>= 10.0.0)
18
+ sshkit (>= 1.9.0)
19
+ capistrano-harrow (0.5.2)
20
+ i18n (0.7.0)
21
+ net-scp (1.2.1)
22
+ net-ssh (>= 2.6.5)
23
+ net-ssh (3.2.0)
24
+ rake (11.2.2)
25
+ sshkit (1.11.1)
26
+ net-scp (>= 1.1.2)
27
+ net-ssh (>= 2.8.0)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ capistrano-database-yml!
34
+ rake
35
+
36
+ BUNDLED WITH
37
+ 1.12.5
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2014 Bruno Sutic
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the "Software"),
5
+ to deal in the Software without restriction, including without limitation
6
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
7
+ and/or sell copies of the Software, and to permit persons to whom the
8
+ Software is furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included
11
+ in all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
18
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
19
+ OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,92 @@
1
+ # Capistrano::DatabaseYml
2
+
3
+ Capistrano tasks for handling `database.yml` when deploying Rails 4+ apps.
4
+ This is a slightly modified clone of [capistrano-secrets-yml](https://github.com/capistrano-plugins/capistrano-secrets-yml).
5
+
6
+ ### Install
7
+
8
+ Add this to `Gemfile`:
9
+
10
+ group :development do
11
+ gem 'capistrano', '~> 3.2.1'
12
+ gem 'capistrano-database-yml', '~> 1.0.0'
13
+ end
14
+
15
+ And then:
16
+
17
+ $ bundle install
18
+
19
+ ### Setup and usage
20
+
21
+ - make sure your local `config/database.yml` is not git tracked. It **should be on
22
+ the disk**, but gitignored.
23
+
24
+ - populate production database in local `config/database.yml`:
25
+
26
+ production:
27
+ adapter: mysql2
28
+
29
+ - add to `Capfile`:
30
+
31
+ require 'capistrano/database_yml'
32
+
33
+ - create `database.yml` file on the remote server by executing this task:
34
+
35
+ $ bundle exec cap production setup
36
+
37
+ You can now proceed with other deployment tasks.
38
+
39
+ #### What if a new config is added to database file?
40
+
41
+ - add it to local `config/database.yml`:
42
+
43
+ production:
44
+ adapter: mysql2
45
+ foobar: some_other_config
46
+
47
+ - if you're working in a team where other people have the deploy rights, compare
48
+ you local `database.yml` with the one on the server. This is to ensure you
49
+ didn't miss an update.
50
+ - copy to the server:
51
+
52
+ $ bundle exec cap production setup
53
+
54
+ - notify your colleagues that have the deploy rights that the remote
55
+ `database.yml` has been updated so they can change their copy.
56
+
57
+ ### How it works
58
+
59
+ When you execute `$ bundle exec production setup`:
60
+
61
+ - database from your local `database.yml` are copied to the server.<br/>
62
+ - only "stage" database are copied: if you are deploying to `production`,
63
+ only production database are copied there
64
+ - on the server database file is located in `#{shared_path}/config/database.yml`
65
+
66
+ On deployment:
67
+
68
+ - database file is automatically symlinked to `#{current_path}/config/database.yml`
69
+
70
+ ### Configuration
71
+
72
+ None.
73
+
74
+ ### More Capistrano automation?
75
+
76
+ Check out [capistrano-plugins](https://github.com/capistrano-plugins) github org.
77
+
78
+ ### FAQ
79
+
80
+ - shouldn't we be keeping configuration in environment variables as per
81
+ [12 factor app rules](http://12factor.net/config)?
82
+
83
+ On Heroku, yes.<br/>
84
+ With Capistrano, those env vars still have to be written somewhere on the disk
85
+ and used with a tool like [dotenv](https://github.com/bkeepers/dotenv).
86
+
87
+ Since we have to keep configuration on the disk anyway, it probably makes
88
+ sense to use Rails 4 built-in `database.yml` mechanism.
89
+
90
+ ### License
91
+
92
+ [MIT](LICENSE.md)
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "capistrano/database_yml/version"
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "capistrano-database-yml"
8
+ gem.version = Capistrano::DatabaseYml::VERSION
9
+ gem.authors = ["Shimpei Otsubo"]
10
+ gem.email = ["potsbo@gmail.com"]
11
+ gem.description = <<-EOF.gsub(/^\s+/, "")
12
+ Capistrano tasks for automating `database.yml` file handling for Rails 4+ apps.
13
+
14
+ This plugins syncs contents of your local database file and copies that to
15
+ the remote server.
16
+ EOF
17
+ gem.summary = "Capistrano tasks for automating `database.yml` file handling for Rails 4+ apps."
18
+ gem.homepage = "https://github.com/capistrano-plugins/capistrano-database-yml"
19
+
20
+ gem.files = `git ls-files`.split($/)
21
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
22
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
23
+ gem.require_paths = ["lib"]
24
+
25
+ gem.add_dependency "capistrano", ">= 3.1"
26
+ gem.add_dependency "sshkit", ">= 1.2.0"
27
+
28
+ gem.add_development_dependency "rake"
29
+ end
File without changes
@@ -0,0 +1,3 @@
1
+ require "capistrano/database_yml/paths"
2
+ require "capistrano/database_yml/helpers"
3
+ load File.expand_path("../tasks/database_yml.rake", __FILE__)
@@ -0,0 +1,50 @@
1
+ require "yaml"
2
+
3
+ module Capistrano
4
+ module DatabaseYml
5
+ module Helpers
6
+
7
+ def local_database_yml(env)
8
+ @local_database_yml ||= YAML.load_file(database_yml_local_path)
9
+ @local_database_yml[env]
10
+ end
11
+
12
+ def database_yml_env
13
+ fetch(:database_yml_env).to_s
14
+ end
15
+
16
+ def database_yml_content
17
+ { database_yml_env => local_database_yml(database_yml_env) }.to_yaml
18
+ end
19
+
20
+ # error helpers
21
+
22
+ def check_git_tracking_error
23
+ puts
24
+ puts "Error - please remove '#{fetch(:database_yml_local_path)}' from git:"
25
+ puts
26
+ puts " $ git rm --cached #{fetch(:database_yml_local_path)}"
27
+ puts
28
+ puts "and gitignore it:"
29
+ puts
30
+ puts " $ echo '#{fetch(:database_yml_local_path)}' >> .gitignore"
31
+ puts
32
+ end
33
+
34
+ def check_config_present_error
35
+ puts
36
+ puts "Error - '#{database_yml_env}' config not present in '#{fetch(:database_yml_local_path)}'."
37
+ puts "Please populate it."
38
+ puts
39
+ end
40
+
41
+ def check_database_file_exists_error
42
+ puts
43
+ puts "Error - '#{fetch(:database_yml_local_path)}' file does not exists, and it's required."
44
+ puts
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+
@@ -0,0 +1,17 @@
1
+ require "pathname"
2
+
3
+ module Capistrano
4
+ module DatabaseYml
5
+ module Paths
6
+
7
+ def database_yml_local_path
8
+ Pathname.new fetch(:database_yml_local_path)
9
+ end
10
+
11
+ def database_yml_remote_path
12
+ shared_path.join fetch(:database_yml_remote_path)
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module DatabaseYml
3
+ VERSION = "1.0.1"
4
+ end
5
+ end
@@ -0,0 +1,58 @@
1
+ include Capistrano::DatabaseYml::Paths
2
+ include Capistrano::DatabaseYml::Helpers
3
+ namespace :load do task :defaults do
4
+ set :database_yml_local_path, "config/database.yml"
5
+ set :database_yml_remote_path, "config/database.yml"
6
+ set :database_yml_env, -> { fetch(:rails_env) || fetch(:stage) }
7
+ end
8
+ end
9
+
10
+ namespace :database_yml do
11
+
12
+ task :check_database_file_exists do
13
+ next if File.exists?(database_yml_local_path)
14
+ check_database_file_exists_error
15
+ exit 1
16
+ end
17
+
18
+ task :check_git_tracking do
19
+ next unless system("git ls-files #{fetch(:database_yml_local_path)} --error-unmatch >/dev/null 2>&1")
20
+ check_git_tracking_error
21
+ exit 1
22
+ end
23
+
24
+ task :check_config_present do
25
+ next unless local_database_yml(database_yml_env).nil?
26
+ check_config_present_error
27
+ exit 1
28
+ end
29
+
30
+ desc "database.yml file checks"
31
+ task :check do
32
+ invoke "database_yml:check_database_file_exists"
33
+ invoke "database_yml:check_git_tracking"
34
+ invoke "database_yml:check_config_present"
35
+ end
36
+
37
+ desc "Setup `database.yml` file on the server(s)"
38
+ task setup: [:check] do
39
+ content = database_yml_content
40
+ on release_roles :all do
41
+ execute :mkdir, "-pv", File.dirname(database_yml_remote_path)
42
+ upload! StringIO.new(content), database_yml_remote_path
43
+ end
44
+ end
45
+
46
+ # Update `linked_files` after the deploy starts so that users'
47
+ # `database_yml_remote_path` override is respected.
48
+ task :database_yml_symlink do
49
+ set :linked_files, fetch(:linked_files, []).push(fetch(:database_yml_remote_path))
50
+ end
51
+ after "deploy:started", "database_yml:database_yml_symlink"
52
+
53
+ end
54
+
55
+ desc "Server setup tasks"
56
+ task :setup do
57
+ invoke "database_yml:setup"
58
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-database-yml
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Shimpei Otsubo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-14 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.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sshkit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.2.0
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: |
56
+ Capistrano tasks for automating `database.yml` file handling for Rails 4+ apps.
57
+ This plugins syncs contents of your local database file and copies that to
58
+ the remote server.
59
+ email:
60
+ - potsbo@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - ".gitignore"
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - LICENSE.md
69
+ - README.md
70
+ - Rakefile
71
+ - capistrano-database-yml.gemspec
72
+ - lib/capistrano-database-yml.rb
73
+ - lib/capistrano/database_yml.rb
74
+ - lib/capistrano/database_yml/helpers.rb
75
+ - lib/capistrano/database_yml/paths.rb
76
+ - lib/capistrano/database_yml/version.rb
77
+ - lib/capistrano/tasks/database_yml.rake
78
+ homepage: https://github.com/capistrano-plugins/capistrano-database-yml
79
+ licenses: []
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.5.1
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Capistrano tasks for automating `database.yml` file handling for Rails 4+
101
+ apps.
102
+ test_files: []