capistrano-sumo 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 97db649190e9888495fd7809b17eaafb8c4b833c
4
+ data.tar.gz: 627e2ad6d4034fe15089701a9d544258d371dfd5
5
+ SHA512:
6
+ metadata.gz: cef5b9c214578570ce55a6a1f2280a4154428505a722925ff5fdc6948715e22907ca09353fa1fa6ecf4cc42e8262d369710369925e6ac50dac65b51da90743fa
7
+ data.tar.gz: 6f32f27469dbe00eee2df4430c3e538ec52a4097fccb920fe76b24d50f669932378315052fe12ff806e85f445e087d47f0663d818fd6f55c1af482a5754c12f5
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.3
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+ source "https://rubygems.org"
3
+
4
+ group :development do
5
+ gem 'rake', '~> 12.0'
6
+ gem 'rspec', '~> 3.0'
7
+ end
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) Tijs Verkoyen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Tijs Verkoyen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # Capistrano::Sumo
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/capistrano/sumo`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'capistrano-sumo'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install capistrano-sumo
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/tijsverkoyen/capistrano-sumo/issues](https://github.com/tijsverkoyen/capistrano-cachetool/issues).
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler'
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:test) do |spec|
6
+ spec.pattern = "spec/**/*_spec.rb"
7
+ end
8
+
9
+ task :default => :test
@@ -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/sumo/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "capistrano-sumo"
8
+ spec.version = Capistrano::Sumo::VERSION
9
+ spec.authors = ["Tijs Verkoyen"]
10
+ spec.email = ["tijs@verkoyen.eu"]
11
+
12
+ spec.summary = %q{Sumo specific task for Capistrano 3.x.}
13
+ spec.description = %q{Sumo specific task for Capistrano 3.x.}
14
+ spec.homepage = "https://github.com/tijsverkoyen/capistrano-sumo"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.15"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ end
@@ -0,0 +1,4 @@
1
+ require 'rake'
2
+ require 'capistrano/sumo/version'
3
+
4
+ load File.expand_path('../tasks/db.rake', __FILE__)
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module Sumo
3
+ VERSION = '0.2.0'
4
+ end
5
+ end
@@ -0,0 +1,103 @@
1
+ namespace :sumo do
2
+ namespace :db do
3
+ desc "Create the database if it doesn't exists yet"
4
+ task :create do
5
+ if fetch(:stage).to_s != "staging"
6
+ warn Airbrussh::Colors.red('✘') + " This task will only work on staging"
7
+ exit 1
8
+ end
9
+
10
+ on roles(:web) do
11
+ execute "create_db #{(fetch :client)[0, 8]}_#{(fetch :project)[0, 7]}"
12
+ end
13
+ end
14
+
15
+ desc "Get info about the database"
16
+ task :info do
17
+ if fetch(:stage).to_s != "staging"
18
+ warn Airbrussh::Colors.red('✘') + " This task will only work on staging"
19
+ exit 1
20
+ end
21
+
22
+ on roles(:web) do
23
+ execute "info_db #{(fetch :client)[0, 8]}_#{(fetch :project)[0, 7]}"
24
+ end
25
+ end
26
+
27
+ desc "Replace the remote database with the local database"
28
+ task :put do
29
+ on roles(:db) do
30
+ execute :mysqldump, "--lock-tables=false --set-charset #{remote_db_options} #{extract_from_remote_parameters('database.name')} > #{shared_path}/backup_#{Time.now.strftime('%Y%m%d%H%M')}.sql"
31
+ end
32
+
33
+ run_locally do
34
+ execute :mysqldump, "--lock-tables=false --set-charset #{extract_from_local_parameters('database.name')} > ./db_upload.tmp.sql"
35
+ end
36
+
37
+ on roles(:db) do
38
+ upload! File.open('./db_upload.tmp.sql'), "#{shared_path}/db_upload.tmp.sql"
39
+ execute :mysql, "#{remote_db_options} #{extract_from_remote_parameters('database.name')} < #{shared_path}/db_upload.tmp.sql"
40
+ execute :rm, "#{shared_path}/db_upload.tmp.sql"
41
+ end
42
+
43
+ run_locally do
44
+ execute :rm, './db_upload.tmp.sql'
45
+ end
46
+ end
47
+
48
+ desc "Replace the local database with the remote database"
49
+ task :get do
50
+ on roles(:db) do
51
+ execute :mysqldump, "--lock-tables=false --set-charset #{remote_db_options} #{extract_from_remote_parameters('database.name')} > #{shared_path}/db_download.tmp.sql"
52
+ download! "#{shared_path}/db_download.tmp.sql", './db_download.tmp.sql'
53
+ end
54
+
55
+ run_locally do
56
+ execute :mysql, extract_from_local_parameters('database.name'), "< ./db_download.tmp.sql"
57
+ end
58
+
59
+ on roles(:db) do
60
+ execute :rm, "#{shared_path}/db_download.tmp.sql"
61
+ end
62
+
63
+ run_locally do
64
+ execute :rm, './db_download.tmp.sql'
65
+ end
66
+ end
67
+
68
+ ## Some helper methods
69
+ private
70
+ def remote_db_options
71
+ data = {
72
+ 'host' => extract_from_remote_parameters("database.host"),
73
+ 'user' => extract_from_remote_parameters("database.user"),
74
+ 'password' => extract_from_remote_parameters("database.password"),
75
+ }
76
+ options = ''
77
+
78
+ data.each do |key, value|
79
+ options << "--#{key}=#{value} " unless value.empty?
80
+ end
81
+ options
82
+ end
83
+
84
+ def extract_from_local_parameters(key)
85
+ data = IO.read('./app/config/parameters.yml')
86
+ extract_from_parameters(key, data)
87
+ end
88
+
89
+ def extract_from_remote_parameters(key)
90
+ data = capture("cat #{shared_path}/app/config/parameters.yml")
91
+ extract_from_parameters(key, data)
92
+ end
93
+
94
+ def extract_from_parameters(key, data)
95
+ # It seems we use invalid yml in our config files
96
+ # Therefore we need to fix some issues with it.
97
+ data = data.gsub(/:(\s*)%(.*)/, ':\1"%\2"')
98
+
99
+ config = YAML::load(data)
100
+ config.fetch('parameters').fetch(key)
101
+ end
102
+ end
103
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-sumo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Tijs Verkoyen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Sumo specific task for Capistrano 3.x.
56
+ email:
57
+ - tijs@verkoyen.eu
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.md
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - capistrano-sumo.gemspec
71
+ - lib/capistrano/sumo.rb
72
+ - lib/capistrano/sumo/version.rb
73
+ - lib/capistrano/tasks/db.rake
74
+ homepage: https://github.com/tijsverkoyen/capistrano-sumo
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.6.11
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Sumo specific task for Capistrano 3.x.
98
+ test_files: []