capistrano-chewy 0.2.0 → 0.2.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.
- checksums.yaml +4 -4
- data/README.md +12 -11
- data/capistrano-chewy.gemspec +4 -2
- data/lib/capistrano-chewy/version.rb +1 -1
- data/lib/capistrano/tasks/chewy.rake +109 -102
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b6374523d9371bd4b852392ca60ee9cd55a4af6
|
4
|
+
data.tar.gz: d4823ef99f9c17c9ed9c3cc7037d4823b39914e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b658bbbe5b8f28656bef50eddd9850fae492d82a82520b3071240ef9d369d736e016f9242272e3c9a0f781de4d56f000e18e4b3ffc32672919b86cd149d613d7
|
7
|
+
data.tar.gz: e39fda7430b47631c38f48880ad0caede6103ac825e718e48f457cece00f9fed7481c56a51d7a39b6e4ea42c4960993759ca730545ae7290f3468d52b10c6a36
|
data/README.md
CHANGED
@@ -9,6 +9,7 @@ Moreover, it adds the possibility of manual index management with the base Chewy
|
|
9
9
|
|
10
10
|
## Requirements
|
11
11
|
|
12
|
+
* Ruby >= 1.9.3
|
12
13
|
* Capistrano >= 3.0
|
13
14
|
* Chewy >= 0.4
|
14
15
|
|
@@ -59,11 +60,11 @@ require 'capistrano/chewy'
|
|
59
60
|
then you can use `cap -T` to list `Capistrano::Chewy` tasks:
|
60
61
|
|
61
62
|
```ruby
|
62
|
-
cap
|
63
|
-
cap
|
64
|
-
cap
|
65
|
-
cap
|
66
|
-
cap
|
63
|
+
cap chewy:rebuild # Reset only modified Chewy indexes
|
64
|
+
cap chewy:reset # Destroy, recreate and import data to all the indexes
|
65
|
+
cap chewy:reset[indexes] # Destroy, recreate and import data to the specified indexes
|
66
|
+
cap chewy:update # Updates data to all the indexes
|
67
|
+
cap chewy:update[indexes] # Updates data to the specified indexes
|
67
68
|
```
|
68
69
|
|
69
70
|
By default `Capistrano::Chewy` adds `deploy:chewy:rebuild` task after `deploy:updated` and `deploy:reverted`.
|
@@ -75,12 +76,12 @@ You can setup the following:
|
|
75
76
|
|
76
77
|
```ruby
|
77
78
|
# deploy.rb
|
78
|
-
set :chewy_conditionally_reset, false
|
79
|
-
set :chewy_path, 'app/my_indexes'
|
80
|
-
set :chewy_env, :chewy_production
|
81
|
-
set :chewy_role, :web
|
82
|
-
set :chewy_default_hooks, false
|
83
|
-
set :chewy_delete_removed_indexes, false
|
79
|
+
set :chewy_conditionally_reset, false # Reset only modified Chewy indexes, true by default
|
80
|
+
set :chewy_path, 'app/my_indexes' # Path to Chewy indexes, 'app/chewy' by default
|
81
|
+
set :chewy_env, :chewy_production # Environment variable for Chewy, equal to RAILS_ENV by default
|
82
|
+
set :chewy_role, :web # Chewy role, :app by default
|
83
|
+
set :chewy_default_hooks, false # Add default capistrano-chewy hooks to your deploy flow, true by default
|
84
|
+
set :chewy_delete_removed_indexes, false # Delete indexes which files have been deleted, true by default
|
84
85
|
```
|
85
86
|
|
86
87
|
## Contributing
|
data/capistrano-chewy.gemspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require 'capistrano-chewy/version'
|
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = 'capistrano-chewy'
|
8
8
|
spec.version = CapistranoChewy.gem_version
|
9
9
|
spec.authors = ['Nikita Bulai']
|
10
|
-
spec.date = '2016-10-
|
10
|
+
spec.date = '2016-10-20'
|
11
11
|
spec.email = ['bulajnikita@gmail.com']
|
12
12
|
spec.summary = 'Manage and continuously rebuild your ElasticSearch indexes with Chewy and Capistrano'
|
13
13
|
spec.description = 'Manage and continuously rebuild your ElasticSearch indexes with Chewy and Capistrano v3.'
|
@@ -19,6 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
|
+
spec.required_ruby_version = '>= 1.9.3'
|
23
|
+
|
22
24
|
spec.add_dependency 'capistrano', '~> 3.0'
|
23
25
|
spec.add_dependency 'chewy', '~> 0.4'
|
24
26
|
|
@@ -11,130 +11,137 @@ end
|
|
11
11
|
|
12
12
|
namespace :deploy do
|
13
13
|
before :starting, :check_chewy_hooks do
|
14
|
-
invoke :'
|
14
|
+
invoke :'chewy:add_default_hooks' if fetch(:chewy_default_hooks)
|
15
15
|
end
|
16
|
+
end
|
17
|
+
|
18
|
+
namespace :chewy do
|
19
|
+
def delete_indexes(index_files)
|
20
|
+
index_classes = index_files.map { |file| File.basename(file, '.rb').camelize }.uniq
|
21
|
+
runner_code = "[#{index_classes.join(', ')}].each(&:delete)"
|
22
|
+
|
23
|
+
# Removed index files exists only in the old (current) release
|
24
|
+
within current_path do
|
25
|
+
with rails_env: fetch(:chewy_env) do
|
26
|
+
info "Removing indexes: #{index_classes.join(',')}"
|
27
|
+
execute :rails, "runner '#{runner_code}'"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def reset_modified_indexes(index_files)
|
33
|
+
index_names = index_files.map { |file| File.basename(file, '_index.rb') }.join(',')
|
16
34
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
35
|
+
within release_path do
|
36
|
+
with rails_env: fetch(:chewy_env) do
|
37
|
+
info "Modified or new indexes: #{index_names}"
|
38
|
+
execute :rake, "chewy:reset[#{index_names}]"
|
39
|
+
end
|
22
40
|
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Adds default Capistrano::Chewy hooks to the deploy flow
|
44
|
+
task :add_default_hooks do
|
45
|
+
after :'deploy:updated', 'chewy:rebuild'
|
46
|
+
after :'deploy:reverted', 'chewy:rebuild'
|
47
|
+
end
|
23
48
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
49
|
+
# Default Chewy rake tasks
|
50
|
+
desc 'Destroy, recreate and import data to all or specified (pass with [one,two]) indexes'
|
51
|
+
task :reset do |_task, args|
|
52
|
+
indexes = args.extras
|
53
|
+
|
54
|
+
on roles fetch(:chewy_role) do
|
55
|
+
within release_path do
|
56
|
+
with rails_env: fetch(:chewy_env) do
|
57
|
+
if indexes.any?
|
58
|
+
execute :rake, "chewy:reset[#{indexes.join(',')}]"
|
59
|
+
else
|
60
|
+
# Simply chewy:reset / chewy:update for Chewy > 0.8.4
|
61
|
+
execute :rake, 'chewy:reset:all'
|
38
62
|
end
|
39
63
|
end
|
40
64
|
end
|
41
65
|
end
|
66
|
+
end
|
42
67
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
68
|
+
desc 'Updates data to all or specified (passed with [one,two]) indexes'
|
69
|
+
task :update do |_task, args|
|
70
|
+
indexes = args.extras
|
71
|
+
|
72
|
+
on roles fetch(:chewy_role) do
|
73
|
+
within release_path do
|
74
|
+
with rails_env: fetch(:chewy_env) do
|
75
|
+
if indexes.any?
|
76
|
+
execute :rake, "chewy:update[#{indexes.join(',')}]"
|
77
|
+
else
|
78
|
+
execute :rake, 'chewy:update:all'
|
55
79
|
end
|
56
80
|
end
|
57
81
|
end
|
58
82
|
end
|
83
|
+
end
|
59
84
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
85
|
+
# Smart rebuild of modified Chewy indexes
|
86
|
+
desc 'Reset Chewy indexes if they have been added, changed or removed'
|
87
|
+
task :rebuild do
|
88
|
+
on roles fetch(:chewy_role) do
|
89
|
+
info "Checking Chewy directory (#{fetch(:chewy_path)})"
|
65
90
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
91
|
+
chewy_path = File.join(release_path, fetch(:chewy_path))
|
92
|
+
unless test("[ -d #{chewy_path} ]")
|
93
|
+
error "Directory #{chewy_path} doesn't exist!"
|
94
|
+
exit 1
|
95
|
+
end
|
71
96
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
else
|
77
|
-
error "Can't check the difference between Chewy indexes - install 'diff' tool first!"
|
78
|
-
exit 1
|
79
|
-
end
|
97
|
+
if fetch(:chewy_conditionally_reset)
|
98
|
+
if test('diff -v')
|
99
|
+
info 'Running smart indexes reset...'
|
100
|
+
invoke :'chewy:rebuilding'
|
80
101
|
else
|
81
|
-
|
82
|
-
|
102
|
+
error "Can't check the difference between Chewy indexes - install 'diff' tool first!"
|
103
|
+
exit 1
|
83
104
|
end
|
105
|
+
else
|
106
|
+
info 'Running chewy:reset:all'
|
107
|
+
invoke :'chewy:reset:all'
|
84
108
|
end
|
85
109
|
end
|
110
|
+
end
|
86
111
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
within release_path do
|
118
|
-
with rails_env: fetch(:chewy_env) do
|
119
|
-
info "Modified or new indexes: #{indexes}"
|
120
|
-
execute :rake, "chewy:reset[#{indexes}]"
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
112
|
+
desc 'Runs smart Chewy indexes rebuilding (only for changed files)'
|
113
|
+
task :rebuilding do
|
114
|
+
on roles fetch(:chewy_role) do
|
115
|
+
chewy_path = fetch(:chewy_path)
|
116
|
+
info "Checking changes in #{chewy_path}"
|
117
|
+
|
118
|
+
chewy_release_path = File.join(release_path, chewy_path)
|
119
|
+
chewy_current_path = File.join(current_path, chewy_path)
|
120
|
+
|
121
|
+
# -q, --brief report only when files differ
|
122
|
+
# -E, --ignore-tab-expansion ignore changes due to tab expansion
|
123
|
+
# -Z, --ignore-trailing-space ignore white space at line end
|
124
|
+
# -B, --ignore-blank-lines ignore changes where lines are all blank
|
125
|
+
#
|
126
|
+
diff_args = "-qZEB #{chewy_release_path} #{chewy_current_path}"
|
127
|
+
indexes_diff = capture :diff, diff_args, raise_on_non_zero_exit: false
|
128
|
+
changes = ::CapistranoChewy::DiffParser.parse(indexes_diff, chewy_current_path, chewy_release_path)
|
129
|
+
|
130
|
+
# If diff is empty then indices have not changed
|
131
|
+
if changes.empty?
|
132
|
+
info 'Skipping `chewy:rebuilding` (nothing changed in the Chewy path)'
|
133
|
+
else
|
134
|
+
indexes_to_reset = changes.changed.concat(changes.added)
|
135
|
+
indexes_to_delete = changes.removed
|
136
|
+
|
137
|
+
# Reset indexes which have been modified or added
|
138
|
+
if indexes_to_reset.any?
|
139
|
+
reset_modified_indexes(indexes_to_reset)
|
140
|
+
end
|
124
141
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
runner_code = "[#{indexes.join(', ')}].each(&:delete)"
|
129
|
-
|
130
|
-
# Removed index files exists only in the old (current) release
|
131
|
-
within current_path do
|
132
|
-
with rails_env: fetch(:chewy_env) do
|
133
|
-
info "Removing indexes: #{indexes.join(',')}"
|
134
|
-
execute :rails, "runner '#{runner_code}'"
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
142
|
+
# Delete indexes which have been removed
|
143
|
+
if indexes_to_delete.any? && fetch(:chewy_delete_removed_indexes)
|
144
|
+
delete_indexes(indexes_to_delete)
|
138
145
|
end
|
139
146
|
end
|
140
147
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-chewy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikita Bulai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capistrano
|
@@ -88,7 +88,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
88
88
|
requirements:
|
89
89
|
- - ">="
|
90
90
|
- !ruby/object:Gem::Version
|
91
|
-
version:
|
91
|
+
version: 1.9.3
|
92
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - ">="
|