capistrano-chewy 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc03aaa995d6e19dcf3628db3ee4ebe0ded4e093
|
4
|
+
data.tar.gz: 6d4d0d9068d11e6c3b2443fdf8f3cdeec181ef75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66e508f1ee8d0c208bb70be8ab31bfadb579c01a7f4c1c8500beeb10e4d7ab8c073ce37afab9f453ca24555866ef6f360b4bedc2ff6e6197dc8cbc4742ec81b4
|
7
|
+
data.tar.gz: dba7535113a333ad4b302cf41bd3e0e719976de73e4bcba9d63e49c94615afabfd0da9b2cbfca0094f0d47222fd72b05b515a0170b490ae02919f21c2a3d87ac
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
Manage and continuously rebuild your ElasticSearch indexes with [Chewy](https://github.com/toptal/chewy/) and [Capistrano](https://github.com/capistrano/capistrano) v3.
|
6
6
|
|
7
|
-
`Capistrano::Chewy` gem adds automatic conditionally reset only modified Chewy indexes to your deploy flow so you do not have to
|
7
|
+
`Capistrano::Chewy` gem adds automatic conditionally reset of only modified Chewy indexes and the removal of deleted index files to your deploy flow so you do not have to do it manually.
|
8
8
|
Moreover, it adds the possibility of manual index management with the base Chewy tasks on the remote server.
|
9
9
|
|
10
10
|
## Requirements
|
@@ -38,6 +38,12 @@ Or install it yourself as:
|
|
38
38
|
$ gem install capistrano-chewy
|
39
39
|
```
|
40
40
|
|
41
|
+
If you want to use the latest version from the `master`, then add the following line to your Gemfile:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
gem 'capistrano-chewy', git: 'https://github.com/nbulaj/capistrano-chewy.git'
|
45
|
+
```
|
46
|
+
|
41
47
|
## Usage
|
42
48
|
|
43
49
|
Require it in your `Capfile`:
|
@@ -45,7 +51,9 @@ Require it in your `Capfile`:
|
|
45
51
|
```ruby
|
46
52
|
# Capfile
|
47
53
|
|
54
|
+
...
|
48
55
|
require 'capistrano/chewy'
|
56
|
+
...
|
49
57
|
```
|
50
58
|
|
51
59
|
then you can use `cap -T` to list `Capistrano::Chewy` tasks:
|
@@ -58,6 +66,9 @@ cap deploy:chewy:update # Updates data to all the indexes
|
|
58
66
|
cap deploy:chewy:update[indexes] # Updates data to the specified indexes
|
59
67
|
```
|
60
68
|
|
69
|
+
By default `Capistrano::Chewy` adds `deploy:chewy:rebuild` task after `deploy:updated` and `deploy:reverted`.
|
70
|
+
If you want to change it, then you need to disable default gem hooks by setting `chewy_default_hooks` to `false` in your deployment config and manually define the order of the tasks.
|
71
|
+
|
61
72
|
## Configuration
|
62
73
|
|
63
74
|
You can setup the following:
|
@@ -68,8 +79,8 @@ set :chewy_conditionally_reset, false # Reset only modified Chewy indexes, true
|
|
68
79
|
set :chewy_path, 'app/my_indexes' # Path to Chewy indexes, 'app/chewy' by default
|
69
80
|
set :chewy_env, :chewy_production # Environment variable for Chewy, equal to RAILS_ENV by default
|
70
81
|
set :chewy_role, :web # Chewy role, :app by default
|
71
|
-
set :chewy_skip, true # Skip processing Chewy indexes during deploy, false by default
|
72
82
|
set :chewy_default_hooks, false # Add default capistrano-chewy hooks to your deploy flow, true by default
|
83
|
+
set :chewy_delete_removed_indexes, false # Delete indexes which files have been deleted, true by default
|
73
84
|
```
|
74
85
|
|
75
86
|
## Contributing
|
@@ -7,8 +7,8 @@ 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-
|
11
|
-
spec.email = ['
|
10
|
+
spec.date = '2016-10-19'
|
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.'
|
14
14
|
spec.homepage = 'https://github.com/nbulaj/capistrano-chewy'
|
@@ -8,6 +8,10 @@ module CapistranoChewy
|
|
8
8
|
@changed = []
|
9
9
|
@added = []
|
10
10
|
end
|
11
|
+
|
12
|
+
def empty?
|
13
|
+
[@removed, @changed, @added].all?(&:empty?)
|
14
|
+
end
|
11
15
|
end
|
12
16
|
|
13
17
|
CHANGED_FILE_PATTERN = /Files\s+.+\s+and\s+(.+)\s+differ/i
|
@@ -15,7 +19,7 @@ module CapistranoChewy
|
|
15
19
|
|
16
20
|
class << self
|
17
21
|
def parse(diff, current_path, release_path)
|
18
|
-
|
22
|
+
return Result.new if current_path == release_path
|
19
23
|
|
20
24
|
diff.split("\n").each_with_object(Result.new) do |line, result|
|
21
25
|
# File was changed
|
@@ -1,11 +1,11 @@
|
|
1
1
|
namespace :load do
|
2
2
|
task :defaults do
|
3
|
+
set :chewy_default_hooks, -> { true }
|
3
4
|
set :chewy_conditionally_reset, -> { true }
|
4
5
|
set :chewy_path, -> { 'app/chewy' }
|
5
6
|
set :chewy_env, -> { fetch(:rails_env, fetch(:stage)) }
|
6
7
|
set :chewy_role, -> { :app }
|
7
|
-
set :
|
8
|
-
set :chewy_default_hooks, -> { true }
|
8
|
+
set :chewy_delete_removed_indexes, -> { true }
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
@@ -17,7 +17,8 @@ namespace :deploy do
|
|
17
17
|
namespace :chewy do
|
18
18
|
# Adds default Capistrano::Chewy hooks to the deploy flow
|
19
19
|
task :add_default_hooks do
|
20
|
-
after 'deploy:updated', 'deploy:chewy:rebuild'
|
20
|
+
after :'deploy:updated', 'deploy:chewy:rebuild'
|
21
|
+
after :'deploy:reverted', 'deploy:chewy:rebuild'
|
21
22
|
end
|
22
23
|
|
23
24
|
# Default Chewy rake tasks
|
@@ -60,11 +61,6 @@ namespace :deploy do
|
|
60
61
|
desc 'Reset Chewy indexes if they have been added, changed or removed'
|
61
62
|
task :rebuild do
|
62
63
|
on roles fetch(:chewy_role) do
|
63
|
-
if fetch(:chewy_skip)
|
64
|
-
info 'Skipping task according to the deploy settings'
|
65
|
-
exit 0
|
66
|
-
end
|
67
|
-
|
68
64
|
info "Checking Chewy directory (#{fetch(:chewy_path)})"
|
69
65
|
|
70
66
|
chewy_path = File.join(release_path, fetch(:chewy_path))
|
@@ -91,11 +87,6 @@ namespace :deploy do
|
|
91
87
|
desc 'Runs smart Chewy indexes rebuilding (only for changed files)'
|
92
88
|
task :rebuilding do
|
93
89
|
on roles fetch(:chewy_role) do
|
94
|
-
if fetch(:chewy_skip)
|
95
|
-
info 'Skipping task according to the deploy settings'
|
96
|
-
exit 0
|
97
|
-
end
|
98
|
-
|
99
90
|
chewy_path = fetch(:chewy_path)
|
100
91
|
info "Checking changes in #{chewy_path}"
|
101
92
|
|
@@ -107,25 +98,41 @@ namespace :deploy do
|
|
107
98
|
# -Z, --ignore-trailing-space ignore white space at line end
|
108
99
|
# -B, --ignore-blank-lines ignore changes where lines are all blank
|
109
100
|
#
|
110
|
-
|
101
|
+
diff_args = "-qZEB #{chewy_release_path} #{chewy_current_path}"
|
102
|
+
indexes_diff = capture :diff, diff_args, raise_on_non_zero_exit: false
|
103
|
+
changes = ::CapistranoChewy::DiffParser.parse(indexes_diff, chewy_current_path, chewy_release_path)
|
111
104
|
|
112
105
|
# If diff is empty then indices have not changed
|
113
|
-
if
|
106
|
+
if changes.empty?
|
114
107
|
info 'Skipping `deploy:chewy:rebuilding` (nothing changed in the Chewy path)'
|
108
|
+
exit 0
|
115
109
|
else
|
116
|
-
|
117
|
-
|
118
|
-
changes = ::CapistranoChewy::DiffParser.parse(indexes_diff, chewy_current_path, chewy_release_path)
|
110
|
+
indexes_to_reset = changes.changed.concat(changes.added)
|
111
|
+
indexes_to_delete = changes.removed
|
119
112
|
|
120
|
-
|
121
|
-
|
113
|
+
# Reset indexes which have been modified or added
|
114
|
+
if indexes_to_reset.any?
|
115
|
+
indexes = indexes_to_reset.map { |file| File.basename(file, '_index.rb') }.join(',')
|
122
116
|
|
123
|
-
|
124
|
-
|
117
|
+
within release_path do
|
118
|
+
with rails_env: fetch(:chewy_env) do
|
119
|
+
info "Modified or new indexes: #{indexes}"
|
125
120
|
execute :rake, "chewy:reset[#{indexes}]"
|
126
121
|
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# Delete indexes which have been removed
|
126
|
+
if indexes_to_delete.any? && fetch(:chewy_delete_removed_indexes)
|
127
|
+
indexes = indexes_to_delete.map { |file| File.basename(file, '.rb').camelize }.uniq
|
128
|
+
runner_code = "[#{indexes.join(', ')}].each(&:delete)"
|
127
129
|
|
128
|
-
|
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
|
129
136
|
end
|
130
137
|
end
|
131
138
|
end
|
data/spec/diff_parser_spec.rb
CHANGED
@@ -4,6 +4,7 @@ describe CapistranoChewy::DiffParser do
|
|
4
4
|
let(:current_path) { '/project/1/app/chewy' }
|
5
5
|
let(:release_path) { '/project/2/app/chewy' }
|
6
6
|
|
7
|
+
# TODO: make a real diff
|
7
8
|
let(:full_diff) do
|
8
9
|
"Files #{current_path}/accounts_index.rb and #{release_path}/accounts_index.rb differ\n" \
|
9
10
|
"Files #{current_path}/posts_index.rb and #{release_path}/posts_index.rb differ\n" \
|
@@ -20,6 +21,8 @@ describe CapistranoChewy::DiffParser do
|
|
20
21
|
expect(result.changed).to eq(["#{release_path}/accounts_index.rb", "#{release_path}/posts_index.rb", "#{release_path}/comments_index.rb"])
|
21
22
|
expect(result.added).to eq(["#{release_path}/applications_index.rb"])
|
22
23
|
expect(result.removed).to eq(["#{current_path}/users_index.rb"])
|
24
|
+
|
25
|
+
expect(result.empty?).to be_falsey
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|
@@ -30,12 +33,20 @@ describe CapistranoChewy::DiffParser do
|
|
30
33
|
expect(result.changed).to be_empty
|
31
34
|
expect(result.added).to be_empty
|
32
35
|
expect(result.removed).to be_empty
|
36
|
+
|
37
|
+
expect(result.empty?).to be_truthy
|
33
38
|
end
|
34
39
|
end
|
35
40
|
|
36
41
|
context 'with the same directories' do
|
37
|
-
it '
|
38
|
-
|
42
|
+
it 'returns blank result' do
|
43
|
+
result = described_class.parse('', current_path, current_path)
|
44
|
+
|
45
|
+
expect(result.changed).to be_empty
|
46
|
+
expect(result.added).to be_empty
|
47
|
+
expect(result.removed).to be_empty
|
48
|
+
|
49
|
+
expect(result.empty?).to be_truthy
|
39
50
|
end
|
40
51
|
end
|
41
52
|
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.
|
4
|
+
version: 0.2.0
|
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-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capistrano
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
description: Manage and continuously rebuild your ElasticSearch indexes with Chewy
|
56
56
|
and Capistrano v3.
|
57
57
|
email:
|
58
|
-
-
|
58
|
+
- bulajnikita@gmail.com
|
59
59
|
executables: []
|
60
60
|
extensions: []
|
61
61
|
extra_rdoc_files: []
|
@@ -68,7 +68,7 @@ files:
|
|
68
68
|
- LICENSE
|
69
69
|
- README.md
|
70
70
|
- Rakefile
|
71
|
-
-
|
71
|
+
- capistrano-chewy.gemspec
|
72
72
|
- lib/capistrano-chewy.rb
|
73
73
|
- lib/capistrano-chewy/diff_parser.rb
|
74
74
|
- lib/capistrano-chewy/version.rb
|