mamiya 0.0.1.alpha2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +16 -0
  5. data/Gemfile +8 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +43 -0
  8. data/Rakefile +6 -0
  9. data/bin/mamiya +17 -0
  10. data/config.example.yml +11 -0
  11. data/docs/sequences/deploy.png +0 -0
  12. data/docs/sequences/deploy.uml +58 -0
  13. data/example.rb +74 -0
  14. data/lib/mamiya.rb +5 -0
  15. data/lib/mamiya/agent.rb +181 -0
  16. data/lib/mamiya/agent/actions.rb +12 -0
  17. data/lib/mamiya/agent/fetcher.rb +137 -0
  18. data/lib/mamiya/agent/handlers/abstract.rb +20 -0
  19. data/lib/mamiya/agent/handlers/fetch.rb +68 -0
  20. data/lib/mamiya/cli.rb +322 -0
  21. data/lib/mamiya/cli/client.rb +172 -0
  22. data/lib/mamiya/config.rb +57 -0
  23. data/lib/mamiya/dsl.rb +192 -0
  24. data/lib/mamiya/helpers/git.rb +75 -0
  25. data/lib/mamiya/logger.rb +190 -0
  26. data/lib/mamiya/master.rb +118 -0
  27. data/lib/mamiya/master/agent_monitor.rb +146 -0
  28. data/lib/mamiya/master/agent_monitor_handlers.rb +44 -0
  29. data/lib/mamiya/master/web.rb +148 -0
  30. data/lib/mamiya/package.rb +122 -0
  31. data/lib/mamiya/script.rb +117 -0
  32. data/lib/mamiya/steps/abstract.rb +19 -0
  33. data/lib/mamiya/steps/build.rb +72 -0
  34. data/lib/mamiya/steps/extract.rb +26 -0
  35. data/lib/mamiya/steps/fetch.rb +24 -0
  36. data/lib/mamiya/steps/push.rb +34 -0
  37. data/lib/mamiya/storages.rb +17 -0
  38. data/lib/mamiya/storages/abstract.rb +48 -0
  39. data/lib/mamiya/storages/mock.rb +61 -0
  40. data/lib/mamiya/storages/s3.rb +127 -0
  41. data/lib/mamiya/util/label_matcher.rb +38 -0
  42. data/lib/mamiya/version.rb +3 -0
  43. data/mamiya.gemspec +35 -0
  44. data/misc/logger_test.rb +12 -0
  45. data/spec/agent/actions_spec.rb +37 -0
  46. data/spec/agent/fetcher_spec.rb +199 -0
  47. data/spec/agent/handlers/fetch_spec.rb +121 -0
  48. data/spec/agent_spec.rb +255 -0
  49. data/spec/config_spec.rb +50 -0
  50. data/spec/dsl_spec.rb +291 -0
  51. data/spec/fixtures/dsl_test_load.rb +1 -0
  52. data/spec/fixtures/dsl_test_use.rb +1 -0
  53. data/spec/fixtures/helpers/foo.rb +1 -0
  54. data/spec/fixtures/test-package-source/.mamiya.meta.json +1 -0
  55. data/spec/fixtures/test-package-source/greeting +1 -0
  56. data/spec/fixtures/test-package.tar.gz +0 -0
  57. data/spec/fixtures/test.yml +4 -0
  58. data/spec/logger_spec.rb +68 -0
  59. data/spec/master/agent_monitor_spec.rb +269 -0
  60. data/spec/master/web_spec.rb +121 -0
  61. data/spec/master_spec.rb +94 -0
  62. data/spec/package_spec.rb +394 -0
  63. data/spec/script_spec.rb +78 -0
  64. data/spec/spec_helper.rb +38 -0
  65. data/spec/steps/build_spec.rb +261 -0
  66. data/spec/steps/extract_spec.rb +68 -0
  67. data/spec/steps/fetch_spec.rb +96 -0
  68. data/spec/steps/push_spec.rb +73 -0
  69. data/spec/storages/abstract_spec.rb +22 -0
  70. data/spec/storages/s3_spec.rb +342 -0
  71. data/spec/storages_spec.rb +33 -0
  72. data/spec/support/dummy_serf.rb +70 -0
  73. data/spec/util/label_matcher_spec.rb +85 -0
  74. metadata +272 -0
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+ require 'mamiya/storages'
3
+ require 'mamiya/storages/abstract'
4
+
5
+ describe Mamiya::Storages do
6
+ describe ".find" do
7
+ let(:name) { :abstract }
8
+ subject { Mamiya::Storages.find(name) }
9
+
10
+ it "finds class by the name" do
11
+ expect(subject).to eq Mamiya::Storages::Abstract
12
+ end
13
+
14
+ context "when not exists yet" do
15
+ let(:name) { :shouldnt_exist }
16
+
17
+ context "if load suceeded" do
18
+ let(:klass) { Class.new }
19
+
20
+ before do
21
+ expect(Mamiya::Storages).to receive(:require) \
22
+ .with('mamiya/storages/shouldnt_exist') do
23
+ stub_const('Mamiya::Storages::ShouldntExist', klass)
24
+ end
25
+ end
26
+
27
+ it "returns loaded constant" do
28
+ expect(subject).to eq klass
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,70 @@
1
+ class DummySerf
2
+ def initialize()
3
+ @hooks = {}
4
+ @responders = {}
5
+
6
+ @tags = {}
7
+ class << @tags
8
+ alias_method :update, :merge!
9
+ end
10
+ end
11
+
12
+ attr_reader :tags
13
+
14
+ def name
15
+ 'my-name'
16
+ end
17
+
18
+ def start!
19
+ end
20
+
21
+ def auto_stop
22
+ end
23
+
24
+ def ready?
25
+ true
26
+ end
27
+
28
+ def wait_for_ready
29
+ end
30
+
31
+ def event(name, payload)
32
+ end
33
+
34
+ %w(member_join member_leave member_failed
35
+ member_update member_reap
36
+ user_event query stop event).each do |event|
37
+
38
+ define_method(:"on_#{event}") do |&block|
39
+ hooks(event) << block
40
+ end
41
+ end
42
+
43
+ def hooks(name)
44
+ @hooks[name] ||= []
45
+ end
46
+
47
+ def respond(name, override: false, &block)
48
+ raise 'already defined' if !override && @responders[name.to_s]
49
+ @responders[name.to_s] = block
50
+ self
51
+ end
52
+
53
+ def trigger_query(name, payload)
54
+ event = Villein::Event.new(
55
+ {
56
+ 'SERF_EVENT' => 'query',
57
+ 'SERF_QUERY_NAME' => "name",
58
+ },
59
+ payload: payload.to_s,
60
+ )
61
+ @responders[name.to_s] && @responders[name.to_s].call(event)
62
+ end
63
+
64
+ def trigger(name, *args)
65
+ hooks(name).each do |hook|
66
+ hook.call(*args)
67
+ end
68
+ nil
69
+ end
70
+ end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+ require 'mamiya/util/label_matcher'
3
+
4
+ describe Mamiya::Util::LabelMatcher do
5
+ describe "#match?(expression)" do
6
+ let(:klass) {
7
+ Class.new {
8
+ include Mamiya::Util::LabelMatcher
9
+
10
+ def initialize(labels)
11
+ @labels = labels
12
+ end
13
+
14
+ attr_reader :labels
15
+ }
16
+ }
17
+
18
+ let(:labels) { [:a, :b, :d] }
19
+ let(:expression) { [] }
20
+ subject { klass.new(labels).match?(*expression) }
21
+
22
+ context "when expression is Array<Symbol>" do
23
+ context "and match" do
24
+ let(:expression) { [[:a, :d]] }
25
+ it { should eq true }
26
+ end
27
+
28
+ context "and match (2)" do
29
+ let(:expression) { [[:a]] }
30
+ it { should eq true }
31
+ end
32
+
33
+ context "and not match" do
34
+ let(:expression) { [[:a, :c]] }
35
+ it { should eq false }
36
+ end
37
+ end
38
+
39
+ context "when expression is Symbol" do
40
+ context "and match" do
41
+ let(:expression) { [:a] }
42
+ it { should eq true }
43
+ end
44
+
45
+ context "and not match" do
46
+ let(:expression) { [:c] }
47
+ it { should eq false }
48
+ end
49
+ end
50
+
51
+ context "when all expressions are Symbol" do
52
+ context "and match" do
53
+ let(:expression) { [:a, :b] }
54
+ it { should eq true }
55
+ end
56
+
57
+ context "and not match" do
58
+ let(:expression) { [:a, :c] }
59
+ it { should eq false }
60
+ end
61
+ end
62
+
63
+ context "when expression is Array<Array> (recursive call)" do
64
+ describe "(case A)" do
65
+ let(:expression) { [ [[:a, :c], [:b, :d]] ] }
66
+ it { should eq true }
67
+ end
68
+
69
+ describe "(case B)" do
70
+ let(:expression) { [ [[:a]] ] }
71
+ it { should eq true }
72
+ end
73
+
74
+ describe "(case C)" do
75
+ let(:expression) { [ [[:c]] ] }
76
+ it { should eq false }
77
+ end
78
+
79
+ describe "(case D)" do
80
+ let(:expression) { [ [[:a, :c], :b] ] }
81
+ it { should eq true }
82
+ end
83
+ end
84
+ end
85
+ end
metadata ADDED
@@ -0,0 +1,272 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mamiya
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alpha2
5
+ platform: ruby
6
+ authors:
7
+ - Shota Fukumori (sora_h)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.18.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.18.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: aws-sdk-core
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.0.rc6
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.0.rc6
41
+ - !ruby/object:Gem::Dependency
42
+ name: term-ansicolor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.3.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.3.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: villein
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 0.3.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.3.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: sinatra
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.4.5
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.4.5
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 2.14.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 2.14.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: rack-test
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.6.2
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.6.2
111
+ - !ruby/object:Gem::Dependency
112
+ name: bundler
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.5'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.5'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Deploy tool using tarballs and serf for lot of servers
140
+ email:
141
+ - her@sorah.jp
142
+ executables:
143
+ - mamiya
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".travis.yml"
150
+ - Gemfile
151
+ - LICENSE.txt
152
+ - README.md
153
+ - Rakefile
154
+ - bin/mamiya
155
+ - config.example.yml
156
+ - docs/sequences/deploy.png
157
+ - docs/sequences/deploy.uml
158
+ - example.rb
159
+ - lib/mamiya.rb
160
+ - lib/mamiya/agent.rb
161
+ - lib/mamiya/agent/actions.rb
162
+ - lib/mamiya/agent/fetcher.rb
163
+ - lib/mamiya/agent/handlers/abstract.rb
164
+ - lib/mamiya/agent/handlers/fetch.rb
165
+ - lib/mamiya/cli.rb
166
+ - lib/mamiya/cli/client.rb
167
+ - lib/mamiya/config.rb
168
+ - lib/mamiya/dsl.rb
169
+ - lib/mamiya/helpers/git.rb
170
+ - lib/mamiya/logger.rb
171
+ - lib/mamiya/master.rb
172
+ - lib/mamiya/master/agent_monitor.rb
173
+ - lib/mamiya/master/agent_monitor_handlers.rb
174
+ - lib/mamiya/master/web.rb
175
+ - lib/mamiya/package.rb
176
+ - lib/mamiya/script.rb
177
+ - lib/mamiya/steps/abstract.rb
178
+ - lib/mamiya/steps/build.rb
179
+ - lib/mamiya/steps/extract.rb
180
+ - lib/mamiya/steps/fetch.rb
181
+ - lib/mamiya/steps/push.rb
182
+ - lib/mamiya/storages.rb
183
+ - lib/mamiya/storages/abstract.rb
184
+ - lib/mamiya/storages/mock.rb
185
+ - lib/mamiya/storages/s3.rb
186
+ - lib/mamiya/util/label_matcher.rb
187
+ - lib/mamiya/version.rb
188
+ - mamiya.gemspec
189
+ - misc/logger_test.rb
190
+ - spec/agent/actions_spec.rb
191
+ - spec/agent/fetcher_spec.rb
192
+ - spec/agent/handlers/fetch_spec.rb
193
+ - spec/agent_spec.rb
194
+ - spec/config_spec.rb
195
+ - spec/dsl_spec.rb
196
+ - spec/fixtures/dsl_test_load.rb
197
+ - spec/fixtures/dsl_test_use.rb
198
+ - spec/fixtures/helpers/foo.rb
199
+ - spec/fixtures/test-package-source/.mamiya.meta.json
200
+ - spec/fixtures/test-package-source/greeting
201
+ - spec/fixtures/test-package.tar.gz
202
+ - spec/fixtures/test.yml
203
+ - spec/logger_spec.rb
204
+ - spec/master/agent_monitor_spec.rb
205
+ - spec/master/web_spec.rb
206
+ - spec/master_spec.rb
207
+ - spec/package_spec.rb
208
+ - spec/script_spec.rb
209
+ - spec/spec_helper.rb
210
+ - spec/steps/build_spec.rb
211
+ - spec/steps/extract_spec.rb
212
+ - spec/steps/fetch_spec.rb
213
+ - spec/steps/push_spec.rb
214
+ - spec/storages/abstract_spec.rb
215
+ - spec/storages/s3_spec.rb
216
+ - spec/storages_spec.rb
217
+ - spec/support/dummy_serf.rb
218
+ - spec/util/label_matcher_spec.rb
219
+ homepage: https://github.com/sorah/mamiya
220
+ licenses:
221
+ - MIT
222
+ metadata: {}
223
+ post_install_message:
224
+ rdoc_options: []
225
+ require_paths:
226
+ - lib
227
+ required_ruby_version: !ruby/object:Gem::Requirement
228
+ requirements:
229
+ - - ">="
230
+ - !ruby/object:Gem::Version
231
+ version: '0'
232
+ required_rubygems_version: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">"
235
+ - !ruby/object:Gem::Version
236
+ version: 1.3.1
237
+ requirements: []
238
+ rubyforge_project:
239
+ rubygems_version: 2.2.2
240
+ signing_key:
241
+ specification_version: 4
242
+ summary: Fast deploy tool using tarballs and serf
243
+ test_files:
244
+ - spec/agent/actions_spec.rb
245
+ - spec/agent/fetcher_spec.rb
246
+ - spec/agent/handlers/fetch_spec.rb
247
+ - spec/agent_spec.rb
248
+ - spec/config_spec.rb
249
+ - spec/dsl_spec.rb
250
+ - spec/fixtures/dsl_test_load.rb
251
+ - spec/fixtures/dsl_test_use.rb
252
+ - spec/fixtures/helpers/foo.rb
253
+ - spec/fixtures/test-package-source/.mamiya.meta.json
254
+ - spec/fixtures/test-package-source/greeting
255
+ - spec/fixtures/test-package.tar.gz
256
+ - spec/fixtures/test.yml
257
+ - spec/logger_spec.rb
258
+ - spec/master/agent_monitor_spec.rb
259
+ - spec/master/web_spec.rb
260
+ - spec/master_spec.rb
261
+ - spec/package_spec.rb
262
+ - spec/script_spec.rb
263
+ - spec/spec_helper.rb
264
+ - spec/steps/build_spec.rb
265
+ - spec/steps/extract_spec.rb
266
+ - spec/steps/fetch_spec.rb
267
+ - spec/steps/push_spec.rb
268
+ - spec/storages/abstract_spec.rb
269
+ - spec/storages/s3_spec.rb
270
+ - spec/storages_spec.rb
271
+ - spec/support/dummy_serf.rb
272
+ - spec/util/label_matcher_spec.rb