mamiya 0.1.1 → 0.1.2
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/.gitignore +1 -0
- data/README.md +7 -1
- data/docs/internal/serf_events.md +22 -0
- data/docs/internal/serf_queries.md +6 -0
- data/docs/internal/tasks.md +36 -0
- data/lib/mamiya/agent.rb +2 -0
- data/lib/mamiya/agent/actions.rb +6 -2
- data/lib/mamiya/agent/tasks/ping.rb +19 -0
- data/lib/mamiya/agent/tasks/switch.rb +17 -5
- data/lib/mamiya/cli/client.rb +23 -7
- data/lib/mamiya/configuration.rb +1 -0
- data/lib/mamiya/master/agent_monitor.rb +0 -1
- data/lib/mamiya/master/web.rb +1 -1
- data/lib/mamiya/steps/build.rb +9 -9
- data/lib/mamiya/version.rb +1 -1
- data/spec/agent/actions_spec.rb +18 -3
- data/spec/agent/tasks/ping_spec.rb +34 -0
- data/spec/agent/tasks/switch_spec.rb +80 -0
- data/spec/master/web_spec.rb +3 -3
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36bd9c34a4fd00eeaa86b5cf5beee9fb61f73a4a
|
4
|
+
data.tar.gz: 94961d874eed9777d6f281a0e154c15807990c20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9c8f23fc8874eb97f98c2f8591aa4d3f6c48d7d5c9b8593dc383280bda9401a2c5151e2785ccbeac3defbcabd12061c4d73d3fcff47747dac6bd7aa88cd02f5
|
7
|
+
data.tar.gz: bc1b2048ec6f901d3cc98f08c0b02a5e84784c7e98374db56b4d736ced5fb59d64be8c2736df82b610ce8b3c94e3e1501b1b628a29916bb769a5ff9f23f7877d
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -16,7 +16,9 @@ Mamiya allows you to deploy using without ssh -- using tarballs, some storages (
|
|
16
16
|
4. Write deploy script for your own
|
17
17
|
- how to build package, how to prepare release, how to release, etc.
|
18
18
|
5. Build then push package
|
19
|
-
|
19
|
+
- `mamiya build`
|
20
|
+
- `mamiya push path/to/package.tar.gz`
|
21
|
+
6. Time to deploy: `mamiya client deploy -a app package`
|
20
22
|
|
21
23
|
### Example configuration
|
22
24
|
|
@@ -33,6 +35,10 @@ This solves such problem by using [Serf](http://www.serfdom.io/) and tarball on
|
|
33
35
|
Also, I'm planning to allow to distribute files before the deploy command. I guess this can skip or shorten
|
34
36
|
file transferring phase in deploy.
|
35
37
|
|
38
|
+
## In the production
|
39
|
+
|
40
|
+
- [Cookpad](https://info.cookpad.com/en) is using Mamiya in production of [cookpad.com](http://cookpad.com).
|
41
|
+
|
36
42
|
## Misc.
|
37
43
|
|
38
44
|
- [Scalable Deployments - How we deploy Rails app to 150+ hosts in a minute // Speaker Deck](https://speakerdeck.com/sorah/scalable-deployments-how-we-deploy-rails-app-to-150-plus-hosts-in-a-minute)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
## Serf Events used in Mamiya
|
2
|
+
|
3
|
+
## Master sends
|
4
|
+
|
5
|
+
- `mamiya:task`
|
6
|
+
- Enqueue `Task` to task queue.
|
7
|
+
- Payload is in JSON. `payload['task']` is a task name. Payload will be passed in `Agent:;TaskQueue#enqueue` directly.
|
8
|
+
|
9
|
+
## Agents send
|
10
|
+
|
11
|
+
- `mamiya:task:start`
|
12
|
+
- `mamiya:task:finish`
|
13
|
+
- `mamiya:task:error`
|
14
|
+
|
15
|
+
- `payload['task']` is a started/finished/errored task.
|
16
|
+
- `payload['error']` is a class name of exception occured.
|
17
|
+
|
18
|
+
----
|
19
|
+
|
20
|
+
- `mamiya:pkg:remove`
|
21
|
+
- `mamiya:prerelease:remove`
|
22
|
+
- `mamiya:release:remove`
|
@@ -0,0 +1,36 @@
|
|
1
|
+
## Task
|
2
|
+
|
3
|
+
Task is a some procedures that ordered remotely.
|
4
|
+
It'll be executed via `mamiya:task` serf event, and `TaskQueue`.
|
5
|
+
|
6
|
+
Task implementations are placed in `lib/mamiya/agent/tasks`.
|
7
|
+
|
8
|
+
Each task run has a job specification, such as target application and package.
|
9
|
+
|
10
|
+
### Base classes
|
11
|
+
|
12
|
+
- `abstract` - base
|
13
|
+
- `notifyable`
|
14
|
+
|
15
|
+
### Tasks
|
16
|
+
|
17
|
+
- `fetch` - Fetch specified package from storage
|
18
|
+
- `prepare` - Unpack fetched package then prepare it
|
19
|
+
- if specified package hasn't fetched, enqueues `fetch` task with chain
|
20
|
+
- `switch`
|
21
|
+
|
22
|
+
- `clean`
|
23
|
+
- `ping`
|
24
|
+
|
25
|
+
### Chaining
|
26
|
+
|
27
|
+
- task can have chain in `_chain` key
|
28
|
+
- `_chain` should be an Array (if specified,) like `['prepare', 'switch']`.
|
29
|
+
- When task run with `_chain` finished, Task named the first element of `_chain` will be enqueued into `TaskQueue`.
|
30
|
+
|
31
|
+
#### Example
|
32
|
+
|
33
|
+
1. User enqueue `{"_chain": ["bar"], "task": "foo", "test": 42}`
|
34
|
+
2. Task `{"_chain": ["bar"], "task": "foo", "test": 42}` run
|
35
|
+
3. Task `{"_chain": ["bar"], "task": "foo", "test": 42}` enqueues `{"task": "bar", "test": 42}`
|
36
|
+
4. Task `{"task": "bar", "test": 42}` run
|
data/lib/mamiya/agent.rb
CHANGED
@@ -15,6 +15,7 @@ require 'mamiya/agent/tasks/fetch'
|
|
15
15
|
require 'mamiya/agent/tasks/prepare'
|
16
16
|
require 'mamiya/agent/tasks/clean'
|
17
17
|
require 'mamiya/agent/tasks/switch'
|
18
|
+
require 'mamiya/agent/tasks/ping'
|
18
19
|
|
19
20
|
require 'mamiya/agent/handlers/task'
|
20
21
|
require 'mamiya/agent/actions'
|
@@ -44,6 +45,7 @@ module Mamiya
|
|
44
45
|
Mamiya::Agent::Tasks::Prepare,
|
45
46
|
Mamiya::Agent::Tasks::Clean,
|
46
47
|
Mamiya::Agent::Tasks::Switch,
|
48
|
+
Mamiya::Agent::Tasks::Ping,
|
47
49
|
])
|
48
50
|
end
|
49
51
|
|
data/lib/mamiya/agent/actions.rb
CHANGED
@@ -18,8 +18,12 @@ module Mamiya
|
|
18
18
|
order_task('prepare', app: application, pkg: package, labels: labels)
|
19
19
|
end
|
20
20
|
|
21
|
-
def switch(application, package, labels: nil, no_release: false)
|
22
|
-
order_task('switch', app: application, pkg: package, labels: labels, no_release: no_release)
|
21
|
+
def switch(application, package, labels: nil, no_release: false, do_release: false)
|
22
|
+
order_task('switch', app: application, pkg: package, labels: labels, no_release: no_release, do_release: do_release)
|
23
|
+
end
|
24
|
+
|
25
|
+
def ping
|
26
|
+
order_task('ping')
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'mamiya/agent'
|
2
|
+
require 'mamiya/agent/tasks/abstract'
|
3
|
+
|
4
|
+
module Mamiya
|
5
|
+
class Agent
|
6
|
+
module Tasks
|
7
|
+
class Ping < Abstract
|
8
|
+
def run
|
9
|
+
logger.info "Responding ping: #{task.inspect}"
|
10
|
+
|
11
|
+
agent.trigger('pong', coalesce: false,
|
12
|
+
at: Time.now.to_i,
|
13
|
+
id: self.task_id,
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -15,7 +15,8 @@ module Mamiya
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def check
|
18
|
-
return true if prerelease_path.exist?
|
18
|
+
return true if ignore_incompletion? && (prerelease_path.exist? || release_path.exist?)
|
19
|
+
return true if prerelease_prepared?
|
19
20
|
return true if release_prepared?
|
20
21
|
|
21
22
|
unless package_path.exist?
|
@@ -28,7 +29,7 @@ module Mamiya
|
|
28
29
|
return false
|
29
30
|
end
|
30
31
|
|
31
|
-
unless
|
32
|
+
unless prerelease_prepared?
|
32
33
|
new_chain = ['switch'] + (task['_chain'] || [])
|
33
34
|
logger.info "Package not prepared, enqueueing prepare task with #{new_chain.inspect}"
|
34
35
|
task_queue.enqueue(
|
@@ -43,10 +44,12 @@ module Mamiya
|
|
43
44
|
|
44
45
|
def run
|
45
46
|
case
|
46
|
-
when
|
47
|
+
when prerelease_prepared? && release_path.exist? && !release_path.join('.mamiya.prepared').exist?
|
47
48
|
logger.info "Removing existing release (not prepared)"
|
48
49
|
FileUtils.remove_entry_secure release_path
|
49
|
-
when
|
50
|
+
when ignore_incompletion? && (prerelease_path.exist? || release_path.exist?)
|
51
|
+
logger.warn "Using incomplete release or prereleases"
|
52
|
+
when !prerelease_prepared? && prerelease_path.exist? && !release_path.join('.mamiya.prepared').exist?
|
50
53
|
# this condition may be a bug
|
51
54
|
logger.error "Existing release is not prepared but prerelease doesn't exist"
|
52
55
|
raise PrereleaseMissing, "Existing release is not prepared but prerelease doesn't exist"
|
@@ -73,6 +76,10 @@ module Mamiya
|
|
73
76
|
task['pkg']
|
74
77
|
end
|
75
78
|
|
79
|
+
def ignore_incompletion?
|
80
|
+
task['allow_incomplete'] || task['allow_incompletion'] || task['incomplete']
|
81
|
+
end
|
82
|
+
|
76
83
|
def release_name
|
77
84
|
task['release'] || package
|
78
85
|
end
|
@@ -105,6 +112,10 @@ module Mamiya
|
|
105
112
|
release_path.exist? && release_path.join('.mamiya.prepared').exist?
|
106
113
|
end
|
107
114
|
|
115
|
+
def prerelease_prepared?
|
116
|
+
prerelease_path.exist? && prerelease_path.join('.mamiya.prepared').exist?
|
117
|
+
end
|
118
|
+
|
108
119
|
def labels
|
109
120
|
@labels ||= agent.labels
|
110
121
|
end
|
@@ -116,7 +127,8 @@ module Mamiya
|
|
116
127
|
logger: logger,
|
117
128
|
config: config,
|
118
129
|
labels: agent.labels,
|
119
|
-
no_release: !!task['no_release']
|
130
|
+
no_release: !!task['no_release'],
|
131
|
+
do_release: !!task['do_release'],
|
120
132
|
)
|
121
133
|
end
|
122
134
|
end
|
data/lib/mamiya/cli/client.rb
CHANGED
@@ -163,12 +163,7 @@ not distributed: #{dist['not_distributed_count']} agents
|
|
163
163
|
method_option :labels, type: :string
|
164
164
|
method_option :no_release, type: :boolean, default: false
|
165
165
|
def switch(package)
|
166
|
-
|
167
|
-
if options[:labels]
|
168
|
-
params[:labels] = Mamiya::Util::LabelMatcher.parse_string_expr(options[:labels])
|
169
|
-
end
|
170
|
-
|
171
|
-
p master_post("/packages/#{application}/#{package}/switch", params.merge(type: :json))
|
166
|
+
switch_(package, no_release: options[:no_release])
|
172
167
|
end
|
173
168
|
|
174
169
|
desc "refresh", "order refreshing agent status"
|
@@ -181,11 +176,15 @@ not distributed: #{dist['not_distributed_count']} agents
|
|
181
176
|
method_option :no_release, type: :boolean, default: false
|
182
177
|
method_option :config, aliases: '-C', type: :string
|
183
178
|
method_option :no_switch, type: :boolean, default: false
|
179
|
+
method_option :synced_release, type: :boolean, default: false
|
184
180
|
def deploy(package)
|
185
181
|
@deploy_exception = nil
|
182
|
+
synced_release = options[:synced_release] || (config && config.synced_release)
|
183
|
+
|
186
184
|
# TODO: move this run on master node side
|
187
185
|
puts "=> Deploying #{application}/#{package}"
|
188
186
|
puts " * onto agents which labeled: #{options[:labels].inspect}" if options[:labels] && !options[:labels].empty?
|
187
|
+
puts " * releasing will be synced in all agents" if synced_release
|
189
188
|
|
190
189
|
show_package(package)
|
191
190
|
|
@@ -220,10 +219,11 @@ not distributed: #{dist['not_distributed_count']} agents
|
|
220
219
|
end
|
221
220
|
|
222
221
|
###
|
222
|
+
#
|
223
223
|
|
224
224
|
unless options[:no_switch]
|
225
225
|
puts "=> Switching..."
|
226
|
-
|
226
|
+
switch_(package, no_release: synced_release)
|
227
227
|
|
228
228
|
puts " * Wait until switch"
|
229
229
|
puts ""
|
@@ -233,6 +233,13 @@ not distributed: #{dist['not_distributed_count']} agents
|
|
233
233
|
break if s['participants_count'] == s['switch']['done'].size
|
234
234
|
sleep 2
|
235
235
|
end
|
236
|
+
|
237
|
+
if synced_release
|
238
|
+
puts "=> Releasing..."
|
239
|
+
switch_(package, do_release: true)
|
240
|
+
|
241
|
+
puts " * due to current implementation's limitation, releasing will be untracked."
|
242
|
+
end
|
236
243
|
end
|
237
244
|
rescue Exception => e
|
238
245
|
@deploy_exception = e
|
@@ -349,6 +356,15 @@ not distributed: #{dist['not_distributed_count']} agents
|
|
349
356
|
raise e
|
350
357
|
end
|
351
358
|
|
359
|
+
def switch_(package, no_release: false, do_release: false)
|
360
|
+
params = {no_release: no_release, do_release: do_release}
|
361
|
+
if options[:labels]
|
362
|
+
params[:labels] = Mamiya::Util::LabelMatcher.parse_string_expr(options[:labels])
|
363
|
+
end
|
364
|
+
|
365
|
+
p master_post("/packages/#{application}/#{package}/switch", params.merge(type: :json))
|
366
|
+
end
|
367
|
+
|
352
368
|
def master_http
|
353
369
|
url = master_url
|
354
370
|
Net::HTTP.new(url.host, url.port).tap do |http|
|
data/lib/mamiya/configuration.rb
CHANGED
@@ -26,6 +26,7 @@ module Mamiya
|
|
26
26
|
# master
|
27
27
|
set_default :master, {monitor: {refresh_interval: nil}} # TODO: don't nest
|
28
28
|
set_default :web, {port: 7761, bind: '0.0.0.0', environment: :development} # TODO: IPv6
|
29
|
+
set_default :synced_release, false
|
29
30
|
|
30
31
|
add_hook :labels, chain: true
|
31
32
|
|
data/lib/mamiya/master/web.rb
CHANGED
@@ -110,7 +110,7 @@ module Mamiya
|
|
110
110
|
post '/packages/:application/:package/switch' do
|
111
111
|
if storage(params[:application]).meta(params[:package])
|
112
112
|
status 204
|
113
|
-
master.switch(params[:application], params[:package], labels: params['labels'], no_release: !!(params['no_release'] || params[:no_release]))
|
113
|
+
master.switch(params[:application], params[:package], labels: params['labels'], no_release: !!(params['no_release'] || params[:no_release]), do_release: !!(params['do_release'] || params[:do_release]))
|
114
114
|
else
|
115
115
|
status 404
|
116
116
|
content_type :json
|
data/lib/mamiya/steps/build.rb
CHANGED
@@ -20,8 +20,6 @@ module Mamiya
|
|
20
20
|
raise ApplicationNotSpecified, ":application should be specified in your script file"
|
21
21
|
end
|
22
22
|
|
23
|
-
logger.info "Initiating package build"
|
24
|
-
|
25
23
|
run_before_build
|
26
24
|
run_prepare_build
|
27
25
|
run_build
|
@@ -48,7 +46,9 @@ module Mamiya
|
|
48
46
|
logger.info "Running script.after_build"
|
49
47
|
script.after_build[@exception]
|
50
48
|
|
51
|
-
|
49
|
+
unless @exception
|
50
|
+
logger.info "DONE: #{package_name} built at #{package.path}"
|
51
|
+
end
|
52
52
|
end
|
53
53
|
|
54
54
|
private
|
@@ -72,7 +72,7 @@ module Mamiya
|
|
72
72
|
begin
|
73
73
|
# Using without block because chdir in block shows warning
|
74
74
|
Dir.chdir(script.build_from)
|
75
|
-
logger.info "Running script.build
|
75
|
+
logger.info "Running script.build"
|
76
76
|
logger.debug "pwd=#{Dir.pwd}"
|
77
77
|
script.build[]
|
78
78
|
ensure
|
@@ -82,7 +82,7 @@ module Mamiya
|
|
82
82
|
|
83
83
|
def copy_deploy_scripts
|
84
84
|
# XXX: TODO: move to another class?
|
85
|
-
logger.info "Copying script files
|
85
|
+
logger.info "Copying script files"
|
86
86
|
|
87
87
|
if script_dest.exist?
|
88
88
|
logger.warn "Removing existing .mamiya.script"
|
@@ -90,7 +90,7 @@ module Mamiya
|
|
90
90
|
end
|
91
91
|
script_dest.mkdir
|
92
92
|
|
93
|
-
logger.
|
93
|
+
logger.debug "- #{script_file} -> #{script_dest}"
|
94
94
|
FileUtils.cp script_file, script_dest
|
95
95
|
|
96
96
|
if script.script_additionals
|
@@ -98,7 +98,7 @@ module Mamiya
|
|
98
98
|
script.script_additionals.each do |additional|
|
99
99
|
src = script_dir.join(additional)
|
100
100
|
dst = script_dest.join(additional)
|
101
|
-
logger.
|
101
|
+
logger.debug "- #{src} -> #{dst}"
|
102
102
|
FileUtils.mkdir_p dst.dirname
|
103
103
|
FileUtils.cp_r src, dst
|
104
104
|
end
|
@@ -114,7 +114,7 @@ module Mamiya
|
|
114
114
|
end
|
115
115
|
|
116
116
|
def build_package
|
117
|
-
logger.
|
117
|
+
logger.debug "Packaging to: #{package.path}"
|
118
118
|
logger.debug "meta=#{package.meta.inspect}"
|
119
119
|
package.build!(script.build_from,
|
120
120
|
exclude_from_package: script.exclude_from_package || [],
|
@@ -131,7 +131,7 @@ module Mamiya
|
|
131
131
|
[Time.now.strftime("%Y%m%d%H%M%S"), script.application]
|
132
132
|
].join('-')
|
133
133
|
}
|
134
|
-
logger.
|
134
|
+
logger.debug "Package name determined: #{name}"
|
135
135
|
name
|
136
136
|
end
|
137
137
|
end
|
data/lib/mamiya/version.rb
CHANGED
data/spec/agent/actions_spec.rb
CHANGED
@@ -57,26 +57,41 @@ describe Mamiya::Agent::Actions do
|
|
57
57
|
|
58
58
|
describe "#switch" do
|
59
59
|
it "sends switch request" do
|
60
|
-
expect(agent).to receive(:trigger).with('task', task: 'switch', app: 'myapp', pkg: 'mypkg', coalesce: false, no_release: false)
|
60
|
+
expect(agent).to receive(:trigger).with('task', task: 'switch', app: 'myapp', pkg: 'mypkg', coalesce: false, no_release: false, do_release: false)
|
61
61
|
|
62
62
|
agent.switch('myapp', 'mypkg')
|
63
63
|
end
|
64
64
|
|
65
65
|
context "with no_release" do
|
66
66
|
it "sends switch request" do
|
67
|
-
expect(agent).to receive(:trigger).with('task', task: 'switch', app: 'myapp', pkg: 'mypkg', coalesce: false, no_release: true)
|
67
|
+
expect(agent).to receive(:trigger).with('task', task: 'switch', app: 'myapp', pkg: 'mypkg', coalesce: false, no_release: true, do_release: false)
|
68
68
|
|
69
69
|
agent.switch('myapp', 'mypkg', no_release: true)
|
70
70
|
end
|
71
|
+
end
|
71
72
|
|
73
|
+
context "with no_release" do
|
74
|
+
it "sends switch request" do
|
75
|
+
expect(agent).to receive(:trigger).with('task', task: 'switch', app: 'myapp', pkg: 'mypkg', coalesce: false, no_release: false, do_release: true)
|
76
|
+
|
77
|
+
agent.switch('myapp', 'mypkg', do_release: true)
|
78
|
+
end
|
72
79
|
end
|
73
80
|
|
74
81
|
context "with labels" do
|
75
82
|
it "adds _labels on task" do
|
76
|
-
expect(agent).to receive(:trigger).with('task', task: 'switch', app: 'myapp', pkg: 'mypkg', _labels: ['foo'], coalesce: false, no_release: false)
|
83
|
+
expect(agent).to receive(:trigger).with('task', task: 'switch', app: 'myapp', pkg: 'mypkg', _labels: ['foo'], coalesce: false, no_release: false, do_release: false)
|
77
84
|
|
78
85
|
agent.switch('myapp', 'mypkg', labels: ['foo'])
|
79
86
|
end
|
80
87
|
end
|
81
88
|
end
|
89
|
+
|
90
|
+
describe "#ping" do
|
91
|
+
it "pings cluster" do
|
92
|
+
expect(agent).to receive(:trigger).with('task', task: 'ping', coalesce: false)
|
93
|
+
|
94
|
+
agent.ping
|
95
|
+
end
|
96
|
+
end
|
82
97
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'mamiya/agent/tasks/abstract'
|
4
|
+
require 'mamiya/agent/tasks/ping'
|
5
|
+
require 'mamiya/configuration'
|
6
|
+
|
7
|
+
describe Mamiya::Agent::Tasks::Ping do
|
8
|
+
let(:config) do
|
9
|
+
Mamiya::Configuration.new
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:agent) { double('agent', config: config) }
|
13
|
+
let(:task_queue) { double('task_queue') }
|
14
|
+
|
15
|
+
subject(:task) { described_class.new(task_queue, {}, agent: agent, raise_error: true) }
|
16
|
+
|
17
|
+
it 'inherits abstract task' do
|
18
|
+
expect(described_class.ancestors).to include(Mamiya::Agent::Tasks::Abstract)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#execute" do
|
22
|
+
let(:now) { Time.now }
|
23
|
+
|
24
|
+
before do
|
25
|
+
allow(Time).to receive(:now).and_return(now)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "responds with it's task_id" do
|
29
|
+
expect(agent).to receive(:trigger).with('pong', at: now.to_i, id: task.task_id, coalesce: false)
|
30
|
+
|
31
|
+
task.execute
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -94,6 +94,65 @@ describe Mamiya::Agent::Tasks::Switch do
|
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
|
+
context "when package fetched but incompletely prepared" do
|
98
|
+
before do
|
99
|
+
File.write packages_app_dir.join('mypkg.tar.gz'), "\n"
|
100
|
+
File.write packages_app_dir.join('mypkg.json'), "{}\n"
|
101
|
+
|
102
|
+
# no .mamiya.prepare
|
103
|
+
prerelease = prereleases_app_dir.join('mypkg').tap(&:mkpath)
|
104
|
+
File.write prerelease.join('hello'), "hola\n"
|
105
|
+
end
|
106
|
+
|
107
|
+
context "without task.incomplete" do
|
108
|
+
before do
|
109
|
+
expect(Mamiya::Steps::Switch).not_to receive(:new)
|
110
|
+
end
|
111
|
+
|
112
|
+
it "enqueues prepare task and finish" do
|
113
|
+
expect(task_queue).to receive(:enqueue).with(
|
114
|
+
:prepare, job.merge('task' => 'switch', '_chain' => ['switch'])
|
115
|
+
)
|
116
|
+
|
117
|
+
task.execute
|
118
|
+
end
|
119
|
+
|
120
|
+
context "with _chain-ed job" do
|
121
|
+
let(:job) { {'app' => 'myapp', 'pkg' => 'mypkg', '_chain' => ['next']} }
|
122
|
+
|
123
|
+
it "enqueues prepare task and finish" do
|
124
|
+
expect(task_queue).to receive(:enqueue).with(
|
125
|
+
:prepare, job.merge('task' => 'switch', '_chain' => ['switch', 'next'])
|
126
|
+
)
|
127
|
+
|
128
|
+
task.execute
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "with task.incomplete=true" do
|
134
|
+
let(:job) { {'app' => 'myapp', 'pkg' => 'mypkg', 'incomplete' => true} }
|
135
|
+
|
136
|
+
before do
|
137
|
+
allow(Mamiya::Steps::Switch).to receive(:new).with(
|
138
|
+
target: deploy_to.join('releases', 'mypkg'),
|
139
|
+
labels: [:foo, :bar],
|
140
|
+
no_release: false,
|
141
|
+
do_release: false,
|
142
|
+
config: config,
|
143
|
+
logger: task.logger,
|
144
|
+
).and_return(switch_step)
|
145
|
+
end
|
146
|
+
|
147
|
+
it "calls switch step" do
|
148
|
+
expect(switch_step).to receive(:run!) do
|
149
|
+
expect(deploy_to.join('releases', 'mypkg', 'hello')).to be_exist
|
150
|
+
end
|
151
|
+
task.execute
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
97
156
|
context "when package prepared" do
|
98
157
|
before do
|
99
158
|
File.write packages_app_dir.join('mypkg.tar.gz'), "\n"
|
@@ -107,6 +166,7 @@ describe Mamiya::Agent::Tasks::Switch do
|
|
107
166
|
target: deploy_to.join('releases', 'mypkg'),
|
108
167
|
labels: [:foo, :bar],
|
109
168
|
no_release: false,
|
169
|
+
do_release: false,
|
110
170
|
config: config,
|
111
171
|
logger: task.logger,
|
112
172
|
).and_return(switch_step)
|
@@ -162,6 +222,26 @@ describe Mamiya::Agent::Tasks::Switch do
|
|
162
222
|
target: deploy_to.join('releases', 'mypkg'),
|
163
223
|
labels: [:foo, :bar],
|
164
224
|
no_release: true,
|
225
|
+
do_release: false,
|
226
|
+
config: config,
|
227
|
+
logger: task.logger,
|
228
|
+
).and_return(switch_step)
|
229
|
+
|
230
|
+
expect(switch_step).to receive(:run!)
|
231
|
+
|
232
|
+
task.execute
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
context "with do_release" do
|
237
|
+
let(:job) { {'app' => 'myapp', 'pkg' => 'mypkg', 'do_release' => true} }
|
238
|
+
|
239
|
+
it "calls switch step with no_release" do
|
240
|
+
expect(Mamiya::Steps::Switch).to receive(:new).with(
|
241
|
+
target: deploy_to.join('releases', 'mypkg'),
|
242
|
+
labels: [:foo, :bar],
|
243
|
+
no_release: false,
|
244
|
+
do_release: true,
|
165
245
|
config: config,
|
166
246
|
logger: task.logger,
|
167
247
|
).and_return(switch_step)
|
data/spec/master/web_spec.rb
CHANGED
@@ -219,7 +219,7 @@ describe Mamiya::Master::Web do
|
|
219
219
|
|
220
220
|
describe "POST /packages/:application/:package/switch" do
|
221
221
|
it "dispatchs switch request" do
|
222
|
-
expect(master).to receive(:switch).with('myapp', 'mypackage', labels: nil, no_release: false)
|
222
|
+
expect(master).to receive(:switch).with('myapp', 'mypackage', labels: nil, no_release: false, do_release: false)
|
223
223
|
|
224
224
|
post '/packages/myapp/mypackage/switch'
|
225
225
|
|
@@ -228,7 +228,7 @@ describe Mamiya::Master::Web do
|
|
228
228
|
|
229
229
|
context "with no_release" do
|
230
230
|
it "dispatchs switch request" do
|
231
|
-
expect(master).to receive(:switch).with('myapp', 'mypackage', labels: nil, no_release: true)
|
231
|
+
expect(master).to receive(:switch).with('myapp', 'mypackage', labels: nil, no_release: true, do_release: false)
|
232
232
|
|
233
233
|
post '/packages/myapp/mypackage/switch',
|
234
234
|
{'no_release' => true}.to_json,
|
@@ -240,7 +240,7 @@ describe Mamiya::Master::Web do
|
|
240
240
|
|
241
241
|
context "with labels" do
|
242
242
|
it "dispatchs prepare request with labels" do
|
243
|
-
expect(master).to receive(:switch).with('myapp', 'mypackage', labels: ['foo'], no_release: false)
|
243
|
+
expect(master).to receive(:switch).with('myapp', 'mypackage', labels: ['foo'], no_release: false, do_release: false)
|
244
244
|
|
245
245
|
post '/packages/myapp/mypackage/switch',
|
246
246
|
{'labels' => ["foo"]}.to_json,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mamiya
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shota Fukumori (sora_h)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09
|
11
|
+
date: 2014-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -180,6 +180,9 @@ files:
|
|
180
180
|
- README.md
|
181
181
|
- Rakefile
|
182
182
|
- bin/mamiya
|
183
|
+
- docs/internal/serf_events.md
|
184
|
+
- docs/internal/serf_queries.md
|
185
|
+
- docs/internal/tasks.md
|
183
186
|
- docs/upgrading.md
|
184
187
|
- example/.gitignore
|
185
188
|
- example/Procfile
|
@@ -198,6 +201,7 @@ files:
|
|
198
201
|
- lib/mamiya/agent/tasks/clean.rb
|
199
202
|
- lib/mamiya/agent/tasks/fetch.rb
|
200
203
|
- lib/mamiya/agent/tasks/notifyable.rb
|
204
|
+
- lib/mamiya/agent/tasks/ping.rb
|
201
205
|
- lib/mamiya/agent/tasks/prepare.rb
|
202
206
|
- lib/mamiya/agent/tasks/switch.rb
|
203
207
|
- lib/mamiya/cli.rb
|
@@ -238,6 +242,7 @@ files:
|
|
238
242
|
- spec/agent/tasks/clean_spec.rb
|
239
243
|
- spec/agent/tasks/fetch_spec.rb
|
240
244
|
- spec/agent/tasks/notifyable_spec.rb
|
245
|
+
- spec/agent/tasks/ping_spec.rb
|
241
246
|
- spec/agent/tasks/prepare_spec.rb
|
242
247
|
- spec/agent/tasks/switch_spec.rb
|
243
248
|
- spec/agent_spec.rb
|
@@ -292,7 +297,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
292
297
|
version: '0'
|
293
298
|
requirements: []
|
294
299
|
rubyforge_project:
|
295
|
-
rubygems_version: 2.
|
300
|
+
rubygems_version: 2.4.1
|
296
301
|
signing_key:
|
297
302
|
specification_version: 4
|
298
303
|
summary: Fast deploy tool using tarballs and serf
|
@@ -304,6 +309,7 @@ test_files:
|
|
304
309
|
- spec/agent/tasks/clean_spec.rb
|
305
310
|
- spec/agent/tasks/fetch_spec.rb
|
306
311
|
- spec/agent/tasks/notifyable_spec.rb
|
312
|
+
- spec/agent/tasks/ping_spec.rb
|
307
313
|
- spec/agent/tasks/prepare_spec.rb
|
308
314
|
- spec/agent/tasks/switch_spec.rb
|
309
315
|
- spec/agent_spec.rb
|