capistrano-bedrock-mysql 0.0.1

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: 9ec444f3e276f09f6a91d3825acb41d87c3b3d97
4
+ data.tar.gz: e24acb3b0636f3d8f5847d5e695ed93afed0be66
5
+ SHA512:
6
+ metadata.gz: 18eb876a79e50c796fab8a7c478ebb4a1ce23e952ca922f48a3adb57d0f6b61fd3ea689ce3fffa7dcf8a3c0f57d5b9609ba90f2a07ed26f04d3316924a2b3153
7
+ data.tar.gz: 5b06513b2c0b5495a87c1a0df75b6703e7478ee08712cd08b2cd9ec81bf14cab4299a08a930c58612b851347817fdb2c64d047d64001ccc897de1f6fe3933720
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ # Mac OS X
2
+ .DS_Store
3
+
4
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ capistrano-bedrock-mysql (0.0.2)
5
+ capistrano (>= 3.0.0.pre)
6
+ dotenv (>= 2.0.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ capistrano (3.4.0)
12
+ i18n
13
+ rake (>= 10.0.0)
14
+ sshkit (~> 1.3)
15
+ colorize (0.7.7)
16
+ dotenv (2.0.1)
17
+ i18n (0.7.0)
18
+ net-scp (1.2.1)
19
+ net-ssh (>= 2.6.5)
20
+ net-ssh (2.9.2)
21
+ rake (10.4.2)
22
+ sshkit (1.7.1)
23
+ colorize (>= 0.7.0)
24
+ net-scp (>= 1.1.2)
25
+ net-ssh (>= 2.8.0)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ capistrano-bedrock-mysql!
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Norkay AB – Step by step, to the top.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # Capistrano MySQL-tasks for Bedrock (https://github.com/roots/bedrock)
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'capistrano-bedrock-mysql', '~> 0.0.1'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install capistrano-bedrock-mysql
18
+
19
+ You need to add two lines to your local .env file:
20
+
21
+ ```
22
+ VAGRANT_PATH=~/path-to-bedrock-ansible
23
+ VAGRANT_SITE_NAME=site-name
24
+ ```
25
+
26
+ You also need to add the line VAGRANT_PATH to your local .env file, pointing to your local `bedrock-ansible` project. You also to keep an .env-file for each environment. Meaning you need .env for your local environment, and one for each additional environment you want to work with – i.e. .env.staging, .env.production and so on...
27
+
28
+ ## Usage
29
+
30
+ Require the module in your `Capfile`:
31
+
32
+ ```ruby
33
+ require 'capistrano-bedrock-mysql'
34
+ ```
35
+
36
+ `capistrano-bedrock-mysql` comes with five tasks:
37
+
38
+ * mysql:backup
39
+ * mysql:download
40
+ * mysql:change_url
41
+ * mysql:import
42
+
43
+ The `mysql:backup` task will backup your database to your shared-folder. It will keep the five latest backups. `mysql:download` downloads the file to your local project folder. `mysql:change_url` does a search and replace for the domain. `mysql:import` imports it into your dev database and `mysql:sync` does everything, in this order.
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
@@ -0,0 +1,22 @@
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-bedrock-mysql'
7
+ spec.version = '0.0.1'
8
+ spec.authors = ['Fredrik Sundström']
9
+ spec.email = ['fredrik.sundstrom@norkay.se']
10
+ spec.description = %q{MySQL tasks for roots/bedrock, using Capistrano 3.x}
11
+ spec.summary = %q{MySQL tasks for roots/bedrock, using Capistrano 3.x}
12
+ spec.homepage = 'https://github.com/norkay/capistrano-bedrock-mysql'
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.0.pre'
21
+ spec.add_dependency 'dotenv', '>= 2.0.1'
22
+ end
@@ -0,0 +1 @@
1
+ load File.expand_path('../../tasks/mysql.rake', __FILE__)
@@ -0,0 +1,98 @@
1
+ require 'dotenv'
2
+ require 'fileutils'
3
+
4
+ namespace(:mysql) do
5
+ task :before do
6
+ on roles(:db) do
7
+ TIMESTAMP = Time.now.strftime('%Y%m%d%H%M%S')
8
+ text = capture "cat #{shared_path}/.env"
9
+ REMOTE_ENV = Dotenv::Parser.call(text)
10
+ file = File.open(".env")
11
+ text = file.read
12
+ LOCAL_ENV = Dotenv::Parser.call(text)
13
+ end
14
+ end
15
+ task :backup => :before
16
+ task :download => :before
17
+ task :change_url => :before
18
+ task :import => :before
19
+
20
+ desc "Sync MySQL Database"
21
+ task :sync => [:backup, :download, :import, :change_url]
22
+
23
+ desc "Backup MySQL Database"
24
+ task :backup do
25
+ on roles(:db) do
26
+ create_dir("#{shared_path}/db_backups")
27
+ create_backup(
28
+ REMOTE_ENV['DB_HOST'],
29
+ REMOTE_ENV['DB_USER'],
30
+ REMOTE_ENV['DB_PASSWORD'],
31
+ REMOTE_ENV['DB_NAME'],
32
+ TIMESTAMP
33
+ )
34
+ remove_old_backups("#{shared_path}/db_backups")
35
+ end
36
+ end
37
+
38
+ desc "Download the last backuped MySQL Database"
39
+ task :download do
40
+ on roles(:db) do
41
+ filename = get_latest_backup_filename("#{shared_path}/db_backups")
42
+ download! "#{shared_path}/db_backups/#{filename}", "example_dev.sql"
43
+ end
44
+ end
45
+
46
+ desc "Change the urls in the MySQL backup file"
47
+ task :change_url do
48
+ on roles(:db) do
49
+ system "cd ..; cd #{LOCAL_ENV['VAGRANT_PATH']}; vagrant ssh -c 'cd /srv/www/#{LOCAL_ENV['VAGRANT_SITE_NAME']}/current; wp search-replace \'#{REMOTE_ENV['WP_HOME']}\' \'#{LOCAL_ENV['WP_HOME']}\''"
50
+ puts "Changed urls!"
51
+ end
52
+ end
53
+
54
+ desc "Clean and import the remote MySQL database to the local one"
55
+ task :import do
56
+ on roles(:db) do
57
+ import_local_mysql_database("example_dev.sql")
58
+ puts "Database imported!"
59
+ end
60
+ end
61
+ end
62
+
63
+ private
64
+
65
+ def create_dir(path)
66
+ execute "mkdir -p #{path}"
67
+ end
68
+
69
+ def create_backup(host, user, password, name, timestamp)
70
+ execute "mysqldump -h #{host} -u#{user} -p#{password} #{name} > #{shared_path}/db_backups/#{timestamp}.sql"
71
+ end
72
+
73
+ def remove_old_backups(path)
74
+ execute "(cd #{path}; ls -1tr | head -n -5 | xargs -d '\\n' rm)" # Keep only five latest
75
+ end
76
+
77
+ def get_latest_backup_filename(path)
78
+ filename = capture "cd #{path}; ls -t | awk '{printf(\"%s\", $0); exit}'"
79
+ filename
80
+ end
81
+
82
+ def local_mysql_credentials
83
+ credential_params = ""
84
+
85
+ credential_params << " -u #{LOCAL_ENV['DB_USER']} " if LOCAL_ENV['DB_USER']
86
+ credential_params << " -p'#{LOCAL_ENV['DB_PASSWORD']}' " if LOCAL_ENV['DB_USER']
87
+ credential_params << " -h #{LOCAL_ENV['DB_HOST']} " if LOCAL_ENV['DB_HOST']
88
+
89
+ credential_params
90
+ end
91
+
92
+ def local_mysql_database
93
+ LOCAL_ENV['DB_NAME']
94
+ end
95
+
96
+ def import_local_mysql_database(filename)
97
+ system "cd ..; cd #{LOCAL_ENV['VAGRANT_PATH']}; vagrant ssh -c 'mysql #{local_mysql_credentials} -D #{local_mysql_database} < /srv/www/#{LOCAL_ENV['VAGRANT_SITE_NAME']}/current/#{filename}'"
98
+ end
@@ -0,0 +1 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/capistrano/bedrock/mysql")
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-bedrock-mysql
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Fredrik Sundström
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-09 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.0.pre
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.0.pre
27
+ - !ruby/object:Gem::Dependency
28
+ name: dotenv
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.1
41
+ description: MySQL tasks for roots/bedrock, using Capistrano 3.x
42
+ email:
43
+ - fredrik.sundstrom@norkay.se
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - Gemfile.lock
51
+ - LICENSE
52
+ - README.md
53
+ - capistrano-bedrock-mysql.gemspec
54
+ - lib/capistrano-bedrock-mysql.rb
55
+ - lib/capistrano/bedrock/mysql.rb
56
+ - lib/capistrano/tasks/mysql.rake
57
+ homepage: https://github.com/norkay/capistrano-bedrock-mysql
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.5.1
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: MySQL tasks for roots/bedrock, using Capistrano 3.x
81
+ test_files: []