hako 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +0 -4
- data/lib/hako/commander.rb +16 -14
- data/lib/hako/container.rb +20 -0
- data/lib/hako/scheduler.rb +1 -1
- data/lib/hako/schedulers/echo.rb +4 -4
- data/lib/hako/schedulers/ecs.rb +14 -14
- data/lib/hako/{after_scripts.rb → scripts.rb} +1 -1
- data/lib/hako/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb5ba73f8d811faf60da24c071c8287b1c3dc439
|
4
|
+
data.tar.gz: 1a8548db2c69d4e9fc75b0b60a2119bff2f5c505
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0f4de4bb3bd8838879bd3ea09054b641658685b8bf3538329e89374c0d4ad8e749c24dd1c89fcad92148580c84bb870f95964f1271fc69fdbdb9c18f2d8ea90
|
7
|
+
data.tar.gz: b4cb1198bfd64381b703949cd7c24ddc34f6beb4ce13a34b39f977ee921093bc0d79defa381e092cc2c326ac526bc42940bb8bf0d06f5a1ef49cb32cc07d53a5
|
data/.rubocop_todo.yml
CHANGED
data/lib/hako/commander.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
require 'hako/
|
1
|
+
require 'hako/container'
|
2
2
|
require 'hako/env_expander'
|
3
3
|
require 'hako/error'
|
4
4
|
require 'hako/front_config'
|
5
5
|
require 'hako/fronts'
|
6
6
|
require 'hako/schedulers'
|
7
|
+
require 'hako/scripts'
|
7
8
|
|
8
9
|
module Hako
|
9
10
|
class Commander
|
@@ -11,7 +12,6 @@ module Hako
|
|
11
12
|
|
12
13
|
def initialize(app)
|
13
14
|
@app = app
|
14
|
-
$LOAD_PATH << @app.root_path.join('lib')
|
15
15
|
end
|
16
16
|
|
17
17
|
def deploy(force: false, tag: 'latest')
|
@@ -19,14 +19,16 @@ module Hako
|
|
19
19
|
front = load_front(@app.yaml['front'])
|
20
20
|
scheduler = load_scheduler(@app.yaml['scheduler'])
|
21
21
|
app_port = @app.yaml.fetch('port', nil)
|
22
|
-
docker_labels = @app.yaml.fetch('docker_labels', {})
|
23
22
|
image = @app.yaml.fetch('image') { raise Error.new('image must be set') }
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
app = Container.new(
|
24
|
+
'image_tag' => "#{image}:#{tag}",
|
25
|
+
'docker_labels' => @app.yaml.fetch('docker_labels', {}),
|
26
|
+
)
|
27
|
+
scripts = @app.yaml.fetch('scripts', []).map { |config| load_script(config) }
|
28
28
|
|
29
|
-
|
29
|
+
scripts.each { |script| script.before_deploy(app) }
|
30
|
+
scheduler.deploy(app, env, app_port, front, force: force)
|
31
|
+
scripts.each { |script| script.after_deploy(app) }
|
30
32
|
end
|
31
33
|
|
32
34
|
def oneshot(commands, tag: 'latest')
|
@@ -34,7 +36,7 @@ module Hako
|
|
34
36
|
scheduler = load_scheduler(@app.yaml['scheduler'])
|
35
37
|
image = @app.yaml.fetch('image') { raise Error.new('image must be set') }
|
36
38
|
image_tag = "#{image}:#{tag}"
|
37
|
-
exit scheduler.oneshot(image_tag, env, commands)
|
39
|
+
exit scheduler.oneshot(Container.new('image_tag' => image_tag), env, commands)
|
38
40
|
end
|
39
41
|
|
40
42
|
def status
|
@@ -42,9 +44,9 @@ module Hako
|
|
42
44
|
end
|
43
45
|
|
44
46
|
def remove
|
45
|
-
|
47
|
+
scripts = @app.yaml.fetch('scripts', []).map { |config| load_script(config) }
|
46
48
|
load_scheduler(@app.yaml['scheduler']).remove
|
47
|
-
|
49
|
+
scripts.each(&:after_remove)
|
48
50
|
end
|
49
51
|
|
50
52
|
private
|
@@ -81,10 +83,10 @@ module Hako
|
|
81
83
|
Hako::Fronts.const_get(camelize(front_config.type)).new(front_config)
|
82
84
|
end
|
83
85
|
|
84
|
-
def
|
86
|
+
def load_script(config)
|
85
87
|
type = config.fetch('type')
|
86
|
-
require "hako/
|
87
|
-
Hako::
|
88
|
+
require "hako/scripts/#{type}"
|
89
|
+
Hako::Scripts.const_get(camelize(type)).new(@app, config)
|
88
90
|
end
|
89
91
|
|
90
92
|
def camelize(name)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Hako
|
2
|
+
class Container
|
3
|
+
def initialize(definition)
|
4
|
+
@definition = definition
|
5
|
+
end
|
6
|
+
|
7
|
+
%w[
|
8
|
+
image_tag
|
9
|
+
docker_labels
|
10
|
+
].each do |name|
|
11
|
+
define_method(name) do
|
12
|
+
@definition[name]
|
13
|
+
end
|
14
|
+
|
15
|
+
define_method("#{name}=") do |val|
|
16
|
+
@definition[name] = val
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/hako/scheduler.rb
CHANGED
data/lib/hako/schedulers/echo.rb
CHANGED
@@ -7,16 +7,16 @@ module Hako
|
|
7
7
|
@app_id = app_id
|
8
8
|
end
|
9
9
|
|
10
|
-
def deploy(
|
11
|
-
puts "Deploy #{image_tag} with app_port=#{app_port}, force=#{force}"
|
10
|
+
def deploy(app, env, app_port, _front, force: false)
|
11
|
+
puts "Deploy #{app.image_tag} with app_port=#{app_port}, force=#{force}"
|
12
12
|
puts 'Environment variables:'
|
13
13
|
env.each do |key, val|
|
14
14
|
puts " #{key}=#{val.inspect}"
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def oneshot(
|
19
|
-
puts "Run #{image_tag} with oneshot commands=#{commands.inspect}"
|
18
|
+
def oneshot(app, env, commands)
|
19
|
+
puts "Run #{app.image_tag} with oneshot commands=#{commands.inspect}"
|
20
20
|
puts 'Environment variables:'
|
21
21
|
env.each do |key, val|
|
22
22
|
puts " #{key}=#{val.inspect}"
|
data/lib/hako/schedulers/ecs.rb
CHANGED
@@ -23,7 +23,7 @@ module Hako
|
|
23
23
|
@ec2 = Aws::EC2::Client.new(region: region)
|
24
24
|
end
|
25
25
|
|
26
|
-
def deploy(
|
26
|
+
def deploy(app, env, app_port, front, force: false)
|
27
27
|
@force_mode = force
|
28
28
|
front_env = {
|
29
29
|
'AWS_DEFAULT_REGION' => front.config.s3.region,
|
@@ -31,7 +31,7 @@ module Hako
|
|
31
31
|
'S3_CONFIG_KEY' => front.config.s3.key(@app_id),
|
32
32
|
}
|
33
33
|
front_port = determine_front_port
|
34
|
-
task_definition = register_task_definition(
|
34
|
+
task_definition = register_task_definition(app, env, front.config, front_env, front_port)
|
35
35
|
if task_definition == :noop
|
36
36
|
Hako.logger.info "Task definition isn't changed"
|
37
37
|
task_definition = @ecs.describe_task_definition(task_definition: @app_id).task_definition
|
@@ -50,8 +50,8 @@ module Hako
|
|
50
50
|
Hako.logger.info 'Deployment completed'
|
51
51
|
end
|
52
52
|
|
53
|
-
def oneshot(
|
54
|
-
task_definition = register_task_definition_for_oneshot(
|
53
|
+
def oneshot(app, env, commands)
|
54
|
+
task_definition = register_task_definition_for_oneshot(app)
|
55
55
|
Hako.logger.info "Registered task definition: #{task_definition.task_definition_arn}"
|
56
56
|
task = run_task(task_definition, env, commands)
|
57
57
|
Hako.logger.info "Started task: #{task.task_arn}"
|
@@ -195,26 +195,26 @@ module Hako
|
|
195
195
|
EcsDefinitionComparator.new(expected_container).different?(actual_container)
|
196
196
|
end
|
197
197
|
|
198
|
-
def register_task_definition(
|
199
|
-
|
200
|
-
|
201
|
-
if task_definition_changed?(
|
198
|
+
def register_task_definition(app, env, front_config, front_env, front_port)
|
199
|
+
front_def = front_container(front_config, front_env, front_port)
|
200
|
+
app_def = app_container(app, env)
|
201
|
+
if task_definition_changed?(front_def, app_def)
|
202
202
|
@ecs.register_task_definition(
|
203
203
|
family: @app_id,
|
204
|
-
container_definitions: [
|
204
|
+
container_definitions: [front_def, app_def],
|
205
205
|
).task_definition
|
206
206
|
else
|
207
207
|
:noop
|
208
208
|
end
|
209
209
|
end
|
210
210
|
|
211
|
-
def register_task_definition_for_oneshot(
|
211
|
+
def register_task_definition_for_oneshot(app)
|
212
212
|
@ecs.register_task_definition(
|
213
213
|
family: "#{@app_id}-oneshot",
|
214
214
|
container_definitions: [
|
215
215
|
{
|
216
216
|
name: 'oneshot',
|
217
|
-
image: image_tag,
|
217
|
+
image: app.image_tag,
|
218
218
|
cpu: @cpu,
|
219
219
|
memory: @memory,
|
220
220
|
links: [],
|
@@ -239,18 +239,18 @@ module Hako
|
|
239
239
|
}
|
240
240
|
end
|
241
241
|
|
242
|
-
def app_container(
|
242
|
+
def app_container(app, env)
|
243
243
|
environment = env.map { |k, v| { name: k, value: v } }
|
244
244
|
{
|
245
245
|
name: 'app',
|
246
|
-
image: image_tag,
|
246
|
+
image: app.image_tag,
|
247
247
|
cpu: @cpu,
|
248
248
|
memory: @memory,
|
249
249
|
links: [],
|
250
250
|
port_mappings: [],
|
251
251
|
essential: true,
|
252
252
|
environment: environment,
|
253
|
-
docker_labels: docker_labels,
|
253
|
+
docker_labels: app.docker_labels,
|
254
254
|
}
|
255
255
|
end
|
256
256
|
|
data/lib/hako/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hako
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kohei Suzuki
|
@@ -118,10 +118,10 @@ files:
|
|
118
118
|
- exe/hako
|
119
119
|
- hako.gemspec
|
120
120
|
- lib/hako.rb
|
121
|
-
- lib/hako/after_scripts.rb
|
122
121
|
- lib/hako/application.rb
|
123
122
|
- lib/hako/cli.rb
|
124
123
|
- lib/hako/commander.rb
|
124
|
+
- lib/hako/container.rb
|
125
125
|
- lib/hako/env_expander.rb
|
126
126
|
- lib/hako/env_provider.rb
|
127
127
|
- lib/hako/env_providers.rb
|
@@ -137,6 +137,7 @@ files:
|
|
137
137
|
- lib/hako/schedulers/ecs.rb
|
138
138
|
- lib/hako/schedulers/ecs_definition_comparator.rb
|
139
139
|
- lib/hako/schedulers/ecs_elb.rb
|
140
|
+
- lib/hako/scripts.rb
|
140
141
|
- lib/hako/templates/nginx.conf.erb
|
141
142
|
- lib/hako/templates/nginx.location.conf.erb
|
142
143
|
- lib/hako/version.rb
|