capistrano-container-db 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +93 -0
- data/Rakefile +1 -0
- data/capistrano-container-db.gemspec +25 -0
- data/lib/capistrano-container-db.rb +1 -0
- data/lib/capistrano/container/db.rb +11 -0
- data/lib/capistrano/tasks/db.rb +46 -0
- data/lib/db/dump_helper.rb +27 -0
- data/lib/db/helper.rb +24 -0
- data/lib/db/load_helper.rb +21 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3d98988d18e9e5933477ae48f580f326c1437354
|
4
|
+
data.tar.gz: 34fa561aa7fe1c6f24d5104a9d62d71dd027278b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ca50a7a187fe63763af30a83ae7017178210bbfbf5ebbba12633464bcfd01a0de95485de113f56990490603d466db8e4faf4e4df97d2bb31daed54789e2ee72e
|
7
|
+
data.tar.gz: 73e5b05349530e7dad385de6125639be794a918981a45083a36fc3a5b080f2769f9ba3ba2572af883b6ae73a473aa1b1e07e5af291778ee5bd3ee3c227144937
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 creative-workflow
|
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 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,
|
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 THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# Capistrano::Container::Db [![Gem Version](https://badge.fury.io/rb/capistrano-container-db.svg)](https://badge.fury.io/rb/capistrano-container-db)
|
2
|
+
|
3
|
+
Helps managing databases on local and remote stages, also on remote [docker](https://www.docker.com/) container for Capistrano 3.x.
|
4
|
+
|
5
|
+
This project is in an early stage but helps me alot dealing with my container deployments and keeps my code clean. It is not only ment for mysql, but at the moment there only supports mysql, feel free to contribute =)
|
6
|
+
|
7
|
+
This gem depends on [capistrano-container](https://github.com/creative-workflow/capistrano-container).
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'capistrano', '>= 3.0.0'
|
15
|
+
gem 'capistrano-container-db'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install capistrano-container-db
|
25
|
+
|
26
|
+
Dont forget to require the module in your Capfile:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'capistrano/container/db'
|
30
|
+
```
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
### definition
|
34
|
+
To define and register a container do the following in your stage config or deploy.rb:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
...
|
38
|
+
|
39
|
+
# for usage in conjunction with capistrano-container
|
40
|
+
server('www.example.com', user: 'root', roles: %w{web})
|
41
|
+
|
42
|
+
container 'db', roles: %w{db},
|
43
|
+
container_id: 'website_company_beta_db',
|
44
|
+
server: ['www.example.com']
|
45
|
+
|
46
|
+
# here the capistrano-container-db config comes
|
47
|
+
|
48
|
+
set :db_is_container, true
|
49
|
+
set :db_user, 'wordpress'
|
50
|
+
set :db_pass, 'wordpress'
|
51
|
+
set :db_name, 'my_wordpress_db_inside_docker'
|
52
|
+
|
53
|
+
...
|
54
|
+
```
|
55
|
+
|
56
|
+
This configures the db access for the db container. If 'db_is_container' is true, the gem uses the capistrano-container extension to select the container by name 'fetch(:db_container_name)' (defaults to 'db').
|
57
|
+
|
58
|
+
If the stage name is equal ':local', the gem runs export/import on local host.
|
59
|
+
|
60
|
+
If the stage is unequal ':local' and the param ':db_is_container' is false, the export/import will run on remote host.
|
61
|
+
|
62
|
+
### commandline tasks
|
63
|
+
```ruby
|
64
|
+
cap db:export # export a local, remote or remote container mysql db
|
65
|
+
cap db:import # import a local, remote or remote container mysql db
|
66
|
+
```
|
67
|
+
|
68
|
+
### default configuration
|
69
|
+
```ruby
|
70
|
+
set :db_user, 'root'
|
71
|
+
set :db_pass, ''
|
72
|
+
set :db_name, ''
|
73
|
+
set :db_remote_dump, '/tmp/dump.sql'
|
74
|
+
set :db_local_dump, 'config/db/dump.sql'
|
75
|
+
set :db_is_container, false
|
76
|
+
set :db_container_name, 'db'
|
77
|
+
```
|
78
|
+
|
79
|
+
## TODO
|
80
|
+
* Implement provider pattern for other db engines.
|
81
|
+
* Write tests.
|
82
|
+
|
83
|
+
## Changes
|
84
|
+
### Version 0.0.1
|
85
|
+
* Initial release
|
86
|
+
|
87
|
+
## Contributing
|
88
|
+
|
89
|
+
1. Fork it
|
90
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
91
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
92
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
93
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -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
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'capistrano-container-db'
|
7
|
+
spec.version = '0.0.1'
|
8
|
+
spec.date = '2016-09-26'
|
9
|
+
spec.summary = 'Helps managing databases on local and remote stages, also on remote docker container'
|
10
|
+
spec.description = spec.summary
|
11
|
+
spec.authors = ['Tom Hanoldt']
|
12
|
+
spec.email = ['tom@creative-workflow.berlin']
|
13
|
+
spec.homepage = 'https://github.com/creative-workflow/capistrano-container-db'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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_dependency 'capistrano', '>= 3.0.0.pre'
|
22
|
+
spec.add_dependency 'capistrano-container', '>= 0.0.4'
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.1'
|
25
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'capistrano/container/db.rb'
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require_relative('../../db/helper.rb')
|
2
|
+
require_relative('../../db/dump_helper.rb')
|
3
|
+
require_relative('../../db/load_helper.rb')
|
4
|
+
|
5
|
+
namespace :db do
|
6
|
+
desc "export a local, remote or remote container mysql db"
|
7
|
+
task :export do
|
8
|
+
on roles(:db, :container_host) do |host|
|
9
|
+
|
10
|
+
if fetch(:db_is_container)
|
11
|
+
DumpHelper::dump_on_container_and_download container_by_name(fetch(:db_container_name))
|
12
|
+
elsif fetch(:stage) == :local
|
13
|
+
DumpHelper::dump_on_local
|
14
|
+
else
|
15
|
+
DumpHelper::dump_on_server_and_download
|
16
|
+
end
|
17
|
+
|
18
|
+
Helper::duplicate_local_dump_to_staged_dump
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "import a local, remote or remote container mysql db"
|
23
|
+
task :import do
|
24
|
+
on roles(:db, :container_host) do
|
25
|
+
if fetch(:db_is_container)
|
26
|
+
LoadHelper::import_on_container container_by_name(fetch(:db_container_name))
|
27
|
+
elsif fetch(:stage) == :local
|
28
|
+
LoadHelper::import_on_local
|
29
|
+
else
|
30
|
+
LoadHelper::import_on_server
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
namespace :load do
|
37
|
+
task :defaults do
|
38
|
+
set :db_user, 'root'
|
39
|
+
set :db_pass, ''
|
40
|
+
set :db_name, ''
|
41
|
+
set :db_remote_dump, '/tmp/dump.sql'
|
42
|
+
set :db_local_dump, 'config/db/dump.sql'
|
43
|
+
set :db_is_container, false
|
44
|
+
set :db_container_name, 'db'
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative "helper.rb"
|
2
|
+
|
3
|
+
module DumpHelper
|
4
|
+
def self.dump_on_local()
|
5
|
+
args = Helper::mysql_args(['--no-create-db'])
|
6
|
+
|
7
|
+
run_locally do
|
8
|
+
execute "mysqldump #{args} > #{fetch(:db_local_dump)}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.dump_on_server_and_download()
|
13
|
+
args = Helper::mysql_args(['--no-create-db'])
|
14
|
+
|
15
|
+
execute "mysqldump #{args} > #{fetch(:db_remote_dump)}"
|
16
|
+
|
17
|
+
download!(fetch(:db_remote_dump), fetch(:db_local_dump))
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.dump_on_container_and_download(container)
|
21
|
+
args = Helper::mysql_args(['--no-create-db'])
|
22
|
+
|
23
|
+
container.execute("mysqldump #{args} > #{fetch(:db_remote_dump)}")
|
24
|
+
|
25
|
+
container.download!(fetch(:db_remote_dump), fetch(:db_local_dump))
|
26
|
+
end
|
27
|
+
end
|
data/lib/db/helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Helper
|
2
|
+
def self.mysql_args(additional_args=[])
|
3
|
+
command = " -u #{fetch(:db_user)}"
|
4
|
+
command+= " -p#{fetch(:db_pass)}" unless fetch(:db_pass).empty?
|
5
|
+
command+= " #{additional_args.join(' ')} "
|
6
|
+
|
7
|
+
# dont use --database statement, so no use '...' will be generated
|
8
|
+
command+= " #{fetch(:db_name)}" unless fetch(:db_name).empty?
|
9
|
+
command
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.append_stage_to_filename(file_name, stage = 'local')
|
13
|
+
splitted = file_name.split('.')
|
14
|
+
extension = splitted.pop
|
15
|
+
splitted.push stage, extension
|
16
|
+
splitted.join('.')
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.duplicate_local_dump_to_staged_dump()
|
20
|
+
staged_file = append_stage_to_filename(fetch(:db_local_dump), fetch(:stage))
|
21
|
+
|
22
|
+
FileUtils.cp(fetch(:db_local_dump), staged_file)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative "helper.rb"
|
2
|
+
|
3
|
+
module LoadHelper
|
4
|
+
def self.import_on_local()
|
5
|
+
run_locally do
|
6
|
+
execute "mysql #{Helper::mysql_args} < #{fetch(:db_local_dump)}"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.import_on_container(container)
|
11
|
+
container.upload!(fetch(:db_local_dump), fetch(:db_remote_dump))
|
12
|
+
|
13
|
+
container.execute("mysql #{Helper::mysql_args} < #{fetch(:db_remote_dump)}")
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.import_on_server()
|
17
|
+
upload!(fetch(:db_local_dump), fetch(:db_remote_dump))
|
18
|
+
|
19
|
+
execute("mysql #{Helper::mysql_args} < #{fetch(:db_remote_dump)}")
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-container-db
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tom Hanoldt
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-26 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: capistrano-container
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.4
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.0.4
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.1'
|
69
|
+
description: Helps managing databases on local and remote stages, also on remote docker
|
70
|
+
container
|
71
|
+
email:
|
72
|
+
- tom@creative-workflow.berlin
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".DS_Store"
|
78
|
+
- ".gitignore"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- capistrano-container-db.gemspec
|
84
|
+
- lib/capistrano-container-db.rb
|
85
|
+
- lib/capistrano/container/db.rb
|
86
|
+
- lib/capistrano/tasks/db.rb
|
87
|
+
- lib/db/dump_helper.rb
|
88
|
+
- lib/db/helper.rb
|
89
|
+
- lib/db/load_helper.rb
|
90
|
+
homepage: https://github.com/creative-workflow/capistrano-container-db
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.5.1
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Helps managing databases on local and remote stages, also on remote docker
|
114
|
+
container
|
115
|
+
test_files: []
|