naifa 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +204 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/naifa +9 -0
- data/lib/naifa.rb +8 -0
- data/lib/naifa/cli.rb +46 -0
- data/lib/naifa/config.rb +34 -0
- data/lib/naifa/heroku.rb +43 -0
- data/lib/naifa/postgres.rb +180 -0
- data/lib/naifa/utils.rb +11 -0
- data/lib/naifa/version.rb +3 -0
- data/naifa.gemspec +32 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1329fb6a9bb4e66cdda6324051f3e96db9c580a4
|
4
|
+
data.tar.gz: 728f6f2db1382efb334a7401735d7612b8628f1f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5d5bd7b6421a6c83d74dae4f4dc4c5c13717e7b4fb6e87531ee4398d72e688f8296acaaac693052aeb214230825beedaaea3cb292b1442faffa7c411932107db
|
7
|
+
data.tar.gz: a6767db22a22bdc2bfe3bf3c9e5f600520e854a6b97aef24ab5516b0f7d7dd5db5d5192eb44b87ef217af9a30eab59de88a26364edb843efb4b2fa0179caad52
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Filipe Dias
|
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,204 @@
|
|
1
|
+
# Naifa
|
2
|
+
|
3
|
+
## Description
|
4
|
+
|
5
|
+
Naifa is a tool aimed at providing a collection of commands that simplify the development workflow.
|
6
|
+
This is still a WIP and it may have some rough edges, so please be sure to test it in a safe environment before using it. We are not responsible for any data that you may loose while using it.
|
7
|
+
This also means that features and even commands may changes in the future, so please read the [changelog](CHANGELOG.md) on every update to be aware of the changes and please test it before using it with production data/environments.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'naifa'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install naifa
|
24
|
+
|
25
|
+
After the gem is installed run the following command to initialize the configuration file in your project
|
26
|
+
|
27
|
+
$ naifa init
|
28
|
+
|
29
|
+
This command will create a file .naifa in your project folder with the default settings as if you didn't had a settings file.
|
30
|
+
|
31
|
+
You should now update some of the settings to meet your app configurations.
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
The .naifa file contains settings that will have an influence in the available command options.
|
36
|
+
|
37
|
+
The current default settings are the following:
|
38
|
+
```
|
39
|
+
---
|
40
|
+
version: 1.0
|
41
|
+
db:
|
42
|
+
plugin: :postgres
|
43
|
+
settings:
|
44
|
+
filename: db_backup
|
45
|
+
backup:
|
46
|
+
path: "./data/db_dumps"
|
47
|
+
db_name: ''
|
48
|
+
environment: :staging
|
49
|
+
production:
|
50
|
+
type: :heroku
|
51
|
+
staging:
|
52
|
+
type: :heroku
|
53
|
+
development:
|
54
|
+
type: :docker
|
55
|
+
app_name: db
|
56
|
+
database: ''
|
57
|
+
username: "\\$POSTGRES_USER"
|
58
|
+
path: "/db_dumps/"
|
59
|
+
restore:
|
60
|
+
path: "./data/db_dumps"
|
61
|
+
environment: :development
|
62
|
+
staging:
|
63
|
+
type: :heroku
|
64
|
+
development:
|
65
|
+
type: :docker
|
66
|
+
app_name: db
|
67
|
+
database: ''
|
68
|
+
username: "\\$POSTGRES_USER"
|
69
|
+
path: "/db_dumps/"
|
70
|
+
```
|
71
|
+
|
72
|
+
Taking this into account, you'll be able to run the following commands
|
73
|
+
|
74
|
+
### sync
|
75
|
+
|
76
|
+
```
|
77
|
+
$ naifa sync db
|
78
|
+
```
|
79
|
+
|
80
|
+
This will sync your staging postgres db in heroku to your development postgres in docker
|
81
|
+
|
82
|
+
```
|
83
|
+
$ naifa sync db production
|
84
|
+
```
|
85
|
+
|
86
|
+
This will sync your production postgres db in heroku to your development postgres in docker
|
87
|
+
|
88
|
+
### backup
|
89
|
+
|
90
|
+
```
|
91
|
+
$ naifa backup db
|
92
|
+
```
|
93
|
+
|
94
|
+
This will backup your staging postgres db in heroku to './data/db_dumps/db_backup'
|
95
|
+
|
96
|
+
```
|
97
|
+
$ naifa backup db production
|
98
|
+
```
|
99
|
+
|
100
|
+
This will backup your postgres postgres db in heroku to './data/db_dumps/db_backup'
|
101
|
+
|
102
|
+
### restore
|
103
|
+
|
104
|
+
```
|
105
|
+
$ naifa restore db
|
106
|
+
```
|
107
|
+
|
108
|
+
This will restore the backup in './data/db_dumps/db_backup' to your development postgres
|
109
|
+
|
110
|
+
## Advanced
|
111
|
+
|
112
|
+
Imagine that you have 2 databases with different settings and configurations
|
113
|
+
You can update you configuration file by adding another entry like in the example bellow
|
114
|
+
|
115
|
+
```
|
116
|
+
---
|
117
|
+
version: 1.0
|
118
|
+
db:
|
119
|
+
plugin: :postgres
|
120
|
+
settings:
|
121
|
+
filename: db_backup
|
122
|
+
backup:
|
123
|
+
path: "./data/db_dumps"
|
124
|
+
db_name: ''
|
125
|
+
environment: :staging
|
126
|
+
production:
|
127
|
+
type: :heroku
|
128
|
+
staging:
|
129
|
+
type: :heroku
|
130
|
+
development:
|
131
|
+
type: :docker
|
132
|
+
app_name: db
|
133
|
+
database: dev_db
|
134
|
+
username: "\\$POSTGRES_USER"
|
135
|
+
path: "/db_dumps/"
|
136
|
+
restore:
|
137
|
+
path: "./data/db_dumps"
|
138
|
+
environment: :development
|
139
|
+
staging:
|
140
|
+
type: :heroku
|
141
|
+
development:
|
142
|
+
type: :docker
|
143
|
+
app_name: db
|
144
|
+
database: dev_db
|
145
|
+
username: "\\$POSTGRES_USER"
|
146
|
+
path: "/db_dumps/"
|
147
|
+
db_local:
|
148
|
+
plugin: :postgres
|
149
|
+
settings:
|
150
|
+
filename: db_backup
|
151
|
+
backup:
|
152
|
+
path: "./data/db_dumps"
|
153
|
+
db_name: ''
|
154
|
+
environment: :staging
|
155
|
+
production:
|
156
|
+
type: :heroku
|
157
|
+
staging:
|
158
|
+
type: :heroku
|
159
|
+
development:
|
160
|
+
type: :local
|
161
|
+
database: dev_db1
|
162
|
+
username: postgres
|
163
|
+
restore:
|
164
|
+
path: "./data/db_dumps"
|
165
|
+
environment: :development
|
166
|
+
staging:
|
167
|
+
type: :heroku
|
168
|
+
development:
|
169
|
+
type: :local
|
170
|
+
database: dev_db1
|
171
|
+
username: postgres
|
172
|
+
```
|
173
|
+
|
174
|
+
This configuration will allow you to run the commands like this:
|
175
|
+
|
176
|
+
```
|
177
|
+
$ naifa sync db
|
178
|
+
$ naifa sync db_local
|
179
|
+
```
|
180
|
+
|
181
|
+
## Roadmap
|
182
|
+
|
183
|
+
* Add tests
|
184
|
+
* Add documentation
|
185
|
+
* Add AWS S3 sync between environments
|
186
|
+
* Add MySQL sync, backup and restore
|
187
|
+
* Add MongoDB sync, backup and restore
|
188
|
+
* Rethink the commands to more dynamic depending on the plugin
|
189
|
+
* Add logs and better error handling
|
190
|
+
|
191
|
+
## Development
|
192
|
+
|
193
|
+
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.
|
194
|
+
|
195
|
+
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).
|
196
|
+
|
197
|
+
## Contributing
|
198
|
+
|
199
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/runtimerevolution/naifa.
|
200
|
+
|
201
|
+
|
202
|
+
## License
|
203
|
+
|
204
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "naifa"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/naifa
ADDED
data/lib/naifa.rb
ADDED
data/lib/naifa/cli.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
module Naifa
|
2
|
+
require 'thor'
|
3
|
+
class CLI < Thor
|
4
|
+
|
5
|
+
desc "init <filename>", "Initializes <filename=.naifa> config file with all default settings"
|
6
|
+
def init(filename='.naifa')
|
7
|
+
File.write(filename, Naifa::Config.generate_full_default_settings.to_h.to_yaml)
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "sync <what> <from> <to>", "Syncs <what> from <from> to <to>"
|
11
|
+
def sync(what, from=nil, to=nil)
|
12
|
+
what_config = Naifa::Config.settings[what.to_sym] || {}
|
13
|
+
|
14
|
+
options = {backup: {}, restore: {}}
|
15
|
+
options[:backup][:environment] = from unless from.nil?
|
16
|
+
options[:restore][:environment] = to unless to.nil?
|
17
|
+
|
18
|
+
case what_config[:plugin]
|
19
|
+
when :postgres
|
20
|
+
Naifa::Postgres.sync(what_config.fetch(:settings,{}).deep_merge(options))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "backup <what> <from>", "Backup <what> from <from>"
|
25
|
+
def backup(what, from=nil)
|
26
|
+
what_config = Naifa::Config.settings[what.to_sym] || {}
|
27
|
+
options = from.nil? ? {} : {backup: {environment: from}}
|
28
|
+
|
29
|
+
case what_config[:plugin]
|
30
|
+
when :postgres
|
31
|
+
Naifa::Postgres.backup(what_config.fetch(:settings,{}).deep_merge(options))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "restore <what> <to>", "Restore <what> to <to>"
|
36
|
+
def restore(what, to=nil)
|
37
|
+
what_config = Naifa::Config.settings[what.to_sym] || {}
|
38
|
+
options = to.nil? ? {} : {restore: {environment: to}}
|
39
|
+
|
40
|
+
case what_config[:plugin]
|
41
|
+
when :postgres
|
42
|
+
Naifa::Postgres.restore(what_config.fetch(:settings,{}).deep_merge(options))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/naifa/config.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module Naifa
|
2
|
+
class Config
|
3
|
+
require 'yaml'
|
4
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
5
|
+
|
6
|
+
SETTINGS_VERSION = 1.0
|
7
|
+
DEFAULT_SETTINGS = {
|
8
|
+
db: {
|
9
|
+
:plugin => :postgres
|
10
|
+
}
|
11
|
+
}.with_indifferent_access.freeze
|
12
|
+
|
13
|
+
def self.settings
|
14
|
+
@settings ||= begin
|
15
|
+
loaded_settings = YAML.load(File.read('.naifa')).with_indifferent_access if File.exists?('.naifa')
|
16
|
+
if !loaded_settings.nil? && loaded_settings[:version] != SETTINGS_VERSION
|
17
|
+
raise 'Configuration file version is not supported. Please upgrade!'
|
18
|
+
end
|
19
|
+
loaded_settings
|
20
|
+
end || DEFAULT_SETTINGS
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.generate_full_default_settings
|
24
|
+
full_settings = {'version' => SETTINGS_VERSION}.with_indifferent_access
|
25
|
+
.merge(DEFAULT_SETTINGS)
|
26
|
+
full_settings[:db][:settings] = Naifa::Postgres::DEFAULT_SETTINGS
|
27
|
+
full_settings.to_hash
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.sub_commands
|
31
|
+
settings.keys
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/naifa/heroku.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
module Naifa
|
2
|
+
require 'naifa/utils'
|
3
|
+
|
4
|
+
class Heroku
|
5
|
+
class Postgres
|
6
|
+
def self.backup(filename, environment=:staging)
|
7
|
+
res = capture(environment)
|
8
|
+
Utils.download_file(filename, "`#{build_public_url_command(environment)}`") if res
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.sync(from=:production, to=:staging)
|
12
|
+
puts "Heroku Sync from: #{from} to: #{to}"
|
13
|
+
res = capture(from)
|
14
|
+
# puts build_restore_command("`#{build_public_url_command(from)}`", to)
|
15
|
+
Kernel.system(build_restore_command("`#{build_public_url_command(from)}`", to)) if res
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.capture(environment=:staging)
|
19
|
+
Kernel.system(build_capture_command(environment))
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.restore(environment=:staging)
|
23
|
+
Kernel.system(build_capture_command(environment))
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.build_restore_command(backup_url, environment)
|
27
|
+
"heroku pg:backups:restore #{backup_url} DATABASE_URL -r #{environment}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.build_public_url_command(environment)
|
31
|
+
"heroku pg:backups public-url -r #{environment}"
|
32
|
+
end
|
33
|
+
|
34
|
+
private_class_method :build_public_url_command
|
35
|
+
|
36
|
+
def self.build_capture_command(environment)
|
37
|
+
"heroku pg:backups capture -r #{environment}"
|
38
|
+
end
|
39
|
+
|
40
|
+
private_class_method :build_capture_command
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
module Naifa
|
2
|
+
require 'naifa/utils'
|
3
|
+
|
4
|
+
class Postgres
|
5
|
+
require 'active_support/core_ext/hash/deep_merge'
|
6
|
+
|
7
|
+
DEFAULT_SETTINGS = {
|
8
|
+
filename: 'db_backup',
|
9
|
+
backup: {
|
10
|
+
path: './data/db_dumps',
|
11
|
+
db_name: '',
|
12
|
+
environment: :staging,
|
13
|
+
production: {
|
14
|
+
type: :heroku
|
15
|
+
},
|
16
|
+
staging: {
|
17
|
+
type: :heroku
|
18
|
+
},
|
19
|
+
development: {
|
20
|
+
type: :docker,
|
21
|
+
app_name: 'db',
|
22
|
+
database: '',
|
23
|
+
username: '\$POSTGRES_USER',
|
24
|
+
path: '/db_dumps/'
|
25
|
+
}
|
26
|
+
},
|
27
|
+
restore: {
|
28
|
+
path: './data/db_dumps',
|
29
|
+
environment: :development,
|
30
|
+
staging: {
|
31
|
+
type: :heroku
|
32
|
+
},
|
33
|
+
development: {
|
34
|
+
type: :docker,
|
35
|
+
app_name: 'db',
|
36
|
+
database: '',
|
37
|
+
username: '\$POSTGRES_USER',
|
38
|
+
path: '/db_dumps/'
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}.with_indifferent_access.freeze
|
42
|
+
|
43
|
+
def self.restore(options={})
|
44
|
+
filename = options.fetch(:filename, DEFAULT_SETTINGS[:filename])
|
45
|
+
restore_settings = DEFAULT_SETTINGS[:restore].deep_merge(options.fetch(:restore, {}))
|
46
|
+
|
47
|
+
_restore(filename, restore_settings)
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.backup(options={})
|
51
|
+
filename = options.fetch(:filename, DEFAULT_SETTINGS[:filename])
|
52
|
+
backup_settings = DEFAULT_SETTINGS[:backup].deep_merge(options.fetch(:backup, {}))
|
53
|
+
|
54
|
+
_backup(filename, backup_settings)
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.sync(options={})
|
58
|
+
filename = options.fetch(:filename, DEFAULT_SETTINGS[:filename])
|
59
|
+
|
60
|
+
backup_settings = DEFAULT_SETTINGS[:backup].deep_merge(options.fetch(:backup, {}))
|
61
|
+
restore_settings = DEFAULT_SETTINGS[:restore].deep_merge(options.fetch(:restore, {}))
|
62
|
+
|
63
|
+
return false if backup_settings[:environment].nil? ||
|
64
|
+
backup_settings[backup_settings[:environment]].nil? ||
|
65
|
+
restore_settings[:environment].nil? ||
|
66
|
+
restore_settings[restore_settings[:environment]].nil?
|
67
|
+
|
68
|
+
if backup_settings[backup_settings[:environment]][:type] == :heroku &&
|
69
|
+
restore_settings[restore_settings[:environment]][:type] == :heroku
|
70
|
+
|
71
|
+
Heroku::Postgres.sync(
|
72
|
+
backup_settings[:environment],
|
73
|
+
restore_settings[:environment]
|
74
|
+
)
|
75
|
+
else
|
76
|
+
res = _backup(filename, backup_settings)
|
77
|
+
_restore(filename, restore_settings) if res
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def self._backup(filename, options)
|
82
|
+
environment = options[:environment]
|
83
|
+
return false if environment.nil? || options[environment].nil?
|
84
|
+
|
85
|
+
case options[environment][:type]
|
86
|
+
when :remote
|
87
|
+
command_line = build_backup_command(
|
88
|
+
options[environment][:host],
|
89
|
+
options[environment][:username] || options[:username],
|
90
|
+
options[environment][:database] || options[:database],
|
91
|
+
File.join(
|
92
|
+
options[environment][:path] || options[:path],
|
93
|
+
filename
|
94
|
+
)
|
95
|
+
)
|
96
|
+
Kernel.system(command_line)
|
97
|
+
when :local
|
98
|
+
command_line = build_backup_command(
|
99
|
+
'localhost',
|
100
|
+
options[environment][:username] || options[:username],
|
101
|
+
options[environment][:database] || options[:database],
|
102
|
+
File.join(
|
103
|
+
options[environment][:path] || options[:path],
|
104
|
+
filename
|
105
|
+
)
|
106
|
+
)
|
107
|
+
Kernel.system(command_line)
|
108
|
+
when :heroku
|
109
|
+
Heroku::Postgres.backup(
|
110
|
+
File.join(
|
111
|
+
options[environment][:path] || options[:path],
|
112
|
+
filename
|
113
|
+
),
|
114
|
+
environment
|
115
|
+
)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
private_class_method :_backup
|
120
|
+
|
121
|
+
def self._restore(filename, options={})
|
122
|
+
environment = options[:environment]
|
123
|
+
return false if environment.nil? || options[environment].nil?
|
124
|
+
|
125
|
+
case options[environment][:type]
|
126
|
+
when :remote
|
127
|
+
command_line = build_restore_command(
|
128
|
+
options[environment][:host],
|
129
|
+
options[environment][:username] || options[:username],
|
130
|
+
options[environment][:database] || options[:database],
|
131
|
+
File.join(
|
132
|
+
options[environment][:path] || options[:path],
|
133
|
+
filename
|
134
|
+
)
|
135
|
+
)
|
136
|
+
Kernel.system(command_line)
|
137
|
+
when :local
|
138
|
+
command_line = build_restore_command(
|
139
|
+
'localhost',
|
140
|
+
options[environment][:username] || options[:username],
|
141
|
+
options[environment][:database] || options[:database],
|
142
|
+
File.join(
|
143
|
+
options[environment][:path] || options[:path],
|
144
|
+
filename
|
145
|
+
)
|
146
|
+
)
|
147
|
+
Kernel.system(command_line)
|
148
|
+
when :docker
|
149
|
+
command_line = build_restore_command(
|
150
|
+
'localhost',
|
151
|
+
options[environment][:username] || options[:username],
|
152
|
+
options[environment][:database] || options[:database],
|
153
|
+
File.join(
|
154
|
+
options[environment][:path] || options[:path],
|
155
|
+
filename
|
156
|
+
)
|
157
|
+
)
|
158
|
+
Utils.docker_compose_exec_command(
|
159
|
+
options[environment][:app_name],
|
160
|
+
command_line
|
161
|
+
)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
private_class_method :_restore
|
166
|
+
|
167
|
+
def self.build_restore_command(host, username, database, filename)
|
168
|
+
"pg_restore --verbose --clean --no-acl --no-owner -h #{host} -U #{username} -d #{database} #{filename}"
|
169
|
+
end
|
170
|
+
|
171
|
+
private_class_method :build_restore_command
|
172
|
+
|
173
|
+
def self.build_backup_command(host, username, database, filename)
|
174
|
+
"pg_dump -Fc -h #{host} -U #{username} -d #{database} > #{filename}"
|
175
|
+
end
|
176
|
+
|
177
|
+
private_class_method :build_backup_command
|
178
|
+
|
179
|
+
end
|
180
|
+
end
|
data/lib/naifa/utils.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
module Naifa
|
2
|
+
class Utils
|
3
|
+
def self.download_file(filename, url)
|
4
|
+
Kernel.system("curl -o #{filename} #{url}")
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.docker_compose_exec_command(app_name, command)
|
8
|
+
Kernel.system("docker-compose exec #{app_name} bash -c \"#{command}\"")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/naifa.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'naifa/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "naifa"
|
8
|
+
spec.version = Naifa::VERSION
|
9
|
+
spec.authors = ["Filipe Dias"]
|
10
|
+
spec.email = ["f.dias@runtime-revolution.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Naifa is a tool aimed at providing a collection of commands that simplify the development workflow}
|
13
|
+
spec.description = <<-EOF
|
14
|
+
Naifa is a tool aimed at providing a collection of commands that simplify the development workflow.
|
15
|
+
EOF
|
16
|
+
spec.homepage = "https://github.com/runtimerevolution/naifa"
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
spec.add_development_dependency "pry-nav", "~> 0.2.4"
|
30
|
+
spec.add_dependency "activesupport", ">= 4"
|
31
|
+
spec.add_dependency "thor", "~> 0.19"
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: naifa
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Filipe Dias
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-07 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.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
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
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-nav
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.2.4
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.2.4
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '4'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '4'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: thor
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.19'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.19'
|
97
|
+
description: |2
|
98
|
+
Naifa is a tool aimed at providing a collection of commands that simplify the development workflow.
|
99
|
+
email:
|
100
|
+
- f.dias@runtime-revolution.com
|
101
|
+
executables:
|
102
|
+
- naifa
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- ".gitignore"
|
107
|
+
- ".rspec"
|
108
|
+
- ".travis.yml"
|
109
|
+
- CHANGELOG.md
|
110
|
+
- Gemfile
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- bin/console
|
115
|
+
- bin/setup
|
116
|
+
- exe/naifa
|
117
|
+
- lib/naifa.rb
|
118
|
+
- lib/naifa/cli.rb
|
119
|
+
- lib/naifa/config.rb
|
120
|
+
- lib/naifa/heroku.rb
|
121
|
+
- lib/naifa/postgres.rb
|
122
|
+
- lib/naifa/utils.rb
|
123
|
+
- lib/naifa/version.rb
|
124
|
+
- naifa.gemspec
|
125
|
+
homepage: https://github.com/runtimerevolution/naifa
|
126
|
+
licenses:
|
127
|
+
- MIT
|
128
|
+
metadata: {}
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubyforge_project:
|
145
|
+
rubygems_version: 2.4.5.2
|
146
|
+
signing_key:
|
147
|
+
specification_version: 4
|
148
|
+
summary: Naifa is a tool aimed at providing a collection of commands that simplify
|
149
|
+
the development workflow
|
150
|
+
test_files: []
|