hako 0.12.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/front.yml +1 -4
- data/examples/hello-lb.yml +5 -2
- data/examples/hello.yml +5 -1
- data/lib/hako/container.rb +4 -1
- data/lib/hako/definition_loader.rb +1 -6
- data/lib/hako/scheduler.rb +0 -11
- data/lib/hako/schedulers/ecs.rb +13 -38
- data/lib/hako/scripts/nginx_front.rb +138 -0
- data/lib/hako/version.rb +1 -1
- metadata +3 -5
- data/lib/hako/front.rb +0 -51
- data/lib/hako/fronts.rb +0 -5
- data/lib/hako/fronts/nginx.rb +0 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44168c92adc956e117f59a47a63eeab9479288d0
|
4
|
+
data.tar.gz: 8dc7fbc348b50f6ea2194e2e2adb6a9802258e89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a2cf60847f746fcc21a7c2b84c74898239d7b8d8b85a950491d01f9e367dcc8b7a5667279e6a1378c71a35a14e455a5613601d896e482b874cfe670d832d3bb
|
7
|
+
data.tar.gz: f39fcc090dac6613a3c6886582841bee8226a926da2d0ea1a63c231ba80d25d45f4ce5192af2def86cc52521e3722beeada382b8713bca5bc281dae7ca401c98
|
data/examples/front.yml
CHANGED
data/examples/hello-lb.yml
CHANGED
data/examples/hello.yml
CHANGED
@@ -17,9 +17,13 @@ app:
|
|
17
17
|
PORT: 3000
|
18
18
|
MESSAGE: '#{username}-san'
|
19
19
|
front:
|
20
|
-
|
20
|
+
image_tag: hako-nginx
|
21
|
+
memory: 32
|
22
|
+
cpu: 32
|
21
23
|
additional_containers:
|
22
24
|
redis:
|
23
25
|
image_tag: redis:3.0
|
24
26
|
cpu: 64
|
25
27
|
memory: 512
|
28
|
+
scripts:
|
29
|
+
- !include front.yml
|
data/lib/hako/container.rb
CHANGED
@@ -18,6 +18,7 @@ module Hako
|
|
18
18
|
cpu
|
19
19
|
memory
|
20
20
|
links
|
21
|
+
port_mappings
|
21
22
|
].each do |name|
|
22
23
|
define_method(name) do
|
23
24
|
@definition[name]
|
@@ -29,7 +30,7 @@ module Hako
|
|
29
30
|
end
|
30
31
|
|
31
32
|
def env
|
32
|
-
@expanded_env ||= expand_env(@definition.fetch('env'
|
33
|
+
@expanded_env ||= expand_env(@definition.fetch('env'))
|
33
34
|
end
|
34
35
|
|
35
36
|
def mount_points
|
@@ -65,9 +66,11 @@ module Hako
|
|
65
66
|
|
66
67
|
def default_config
|
67
68
|
{
|
69
|
+
'env' => {},
|
68
70
|
'docker_labels' => {},
|
69
71
|
'links' => [],
|
70
72
|
'mount_points' => [],
|
73
|
+
'port_mappings' => [],
|
71
74
|
}
|
72
75
|
end
|
73
76
|
|
@@ -2,7 +2,6 @@
|
|
2
2
|
require 'set'
|
3
3
|
require 'hako/app_container'
|
4
4
|
require 'hako/container'
|
5
|
-
require 'hako/fronts'
|
6
5
|
require 'hako/loader'
|
7
6
|
|
8
7
|
module Hako
|
@@ -39,7 +38,7 @@ module Hako
|
|
39
38
|
when 'app'
|
40
39
|
AppContainer.new(@app, @app.yaml['app'].merge('tag' => tag), dry_run: @dry_run)
|
41
40
|
when 'front'
|
42
|
-
|
41
|
+
Container.new(@app, @app.yaml.fetch('front'), dry_run: @dry_run)
|
43
42
|
else
|
44
43
|
Container.new(@app, additional_containers.fetch(name), dry_run: @dry_run)
|
45
44
|
end
|
@@ -52,9 +51,5 @@ module Hako
|
|
52
51
|
end
|
53
52
|
containers
|
54
53
|
end
|
55
|
-
|
56
|
-
def load_front(yaml, dry_run:)
|
57
|
-
Loader.new(Hako::Fronts, 'hako/fronts').load(yaml.fetch('type')).new(@app, yaml, dry_run: dry_run)
|
58
|
-
end
|
59
54
|
end
|
60
55
|
end
|
data/lib/hako/scheduler.rb
CHANGED
@@ -30,17 +30,6 @@ module Hako
|
|
30
30
|
raise NotImplementedError
|
31
31
|
end
|
32
32
|
|
33
|
-
def upload_front_config(app_id, front, app_port)
|
34
|
-
front_conf = front.generate_config(app_port)
|
35
|
-
s3_config = front.s3
|
36
|
-
s3 = Aws::S3::Client.new(region: s3_config.region)
|
37
|
-
s3.put_object(
|
38
|
-
body: front_conf,
|
39
|
-
bucket: s3_config.bucket,
|
40
|
-
key: s3_config.key(app_id),
|
41
|
-
)
|
42
|
-
end
|
43
|
-
|
44
33
|
private
|
45
34
|
|
46
35
|
def validation_error!(message)
|
data/lib/hako/schedulers/ecs.rb
CHANGED
@@ -26,11 +26,9 @@ module Hako
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def deploy(containers)
|
29
|
-
app = containers.fetch('app')
|
30
|
-
front = containers.fetch('front')
|
31
29
|
front_port = determine_front_port
|
32
30
|
@scripts.each { |script| script.deploy_started(containers, front_port) }
|
33
|
-
definitions = create_definitions(containers
|
31
|
+
definitions = create_definitions(containers)
|
34
32
|
|
35
33
|
if @dry_run
|
36
34
|
definitions.each do |d|
|
@@ -43,8 +41,6 @@ module Hako
|
|
43
41
|
task_definition = @ecs.describe_task_definition(task_definition: @app_id).task_definition
|
44
42
|
else
|
45
43
|
Hako.logger.info "Registered task definition: #{task_definition.task_definition_arn}"
|
46
|
-
upload_front_config(@app_id, front, app.port)
|
47
|
-
Hako.logger.debug "Uploaded front configuration to s3://#{front.s3.bucket}/#{front.s3.key(@app_id)}"
|
48
44
|
end
|
49
45
|
service = create_or_update_service(task_definition.task_definition_arn, front_port)
|
50
46
|
if service == :noop
|
@@ -58,7 +54,7 @@ module Hako
|
|
58
54
|
end
|
59
55
|
|
60
56
|
def oneshot(containers, commands, env)
|
61
|
-
definitions = create_definitions(containers
|
57
|
+
definitions = create_definitions(containers)
|
62
58
|
definitions.each do |definition|
|
63
59
|
definition.delete(:essential)
|
64
60
|
end
|
@@ -273,14 +269,9 @@ module Hako
|
|
273
269
|
end
|
274
270
|
end
|
275
271
|
|
276
|
-
def create_definitions(containers
|
272
|
+
def create_definitions(containers)
|
277
273
|
containers.map do |name, container|
|
278
|
-
|
279
|
-
when 'front'
|
280
|
-
front_container(container, front_port)
|
281
|
-
else
|
282
|
-
app_container(name, container)
|
283
|
-
end
|
274
|
+
create_definition(name, container)
|
284
275
|
end
|
285
276
|
end
|
286
277
|
|
@@ -306,35 +297,19 @@ module Hako
|
|
306
297
|
end
|
307
298
|
end
|
308
299
|
|
309
|
-
def
|
310
|
-
environment =
|
311
|
-
{
|
312
|
-
name: 'front',
|
313
|
-
image: front.image_tag,
|
314
|
-
cpu: front.cpu,
|
315
|
-
memory: front.memory,
|
316
|
-
links: front.links,
|
317
|
-
port_mappings: [{ container_port: 80, host_port: front_port, protocol: 'tcp' }],
|
318
|
-
essential: true,
|
319
|
-
environment: environment,
|
320
|
-
docker_labels: front.docker_labels,
|
321
|
-
mount_points: front.mount_points,
|
322
|
-
}
|
323
|
-
end
|
324
|
-
|
325
|
-
def app_container(name, app)
|
326
|
-
environment = app.env.map { |k, v| { name: k, value: v } }
|
300
|
+
def create_definition(name, container)
|
301
|
+
environment = container.env.map { |k, v| { name: k, value: v } }
|
327
302
|
{
|
328
303
|
name: name,
|
329
|
-
image:
|
330
|
-
cpu:
|
331
|
-
memory:
|
332
|
-
links:
|
333
|
-
port_mappings:
|
304
|
+
image: container.image_tag,
|
305
|
+
cpu: container.cpu,
|
306
|
+
memory: container.memory,
|
307
|
+
links: container.links,
|
308
|
+
port_mappings: container.port_mappings,
|
334
309
|
essential: true,
|
335
310
|
environment: environment,
|
336
|
-
docker_labels:
|
337
|
-
mount_points:
|
311
|
+
docker_labels: container.docker_labels,
|
312
|
+
mount_points: container.mount_points,
|
338
313
|
}
|
339
314
|
end
|
340
315
|
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'aws-sdk'
|
3
|
+
require 'erb'
|
4
|
+
require 'hako'
|
5
|
+
require 'hako/script'
|
6
|
+
|
7
|
+
module Hako
|
8
|
+
module Scripts
|
9
|
+
class NginxFront < Script
|
10
|
+
S3Config = Struct.new(:region, :bucket, :prefix) do
|
11
|
+
def initialize(options)
|
12
|
+
self.region = options.fetch('region')
|
13
|
+
self.bucket = options.fetch('bucket')
|
14
|
+
self.prefix = options.fetch('prefix', nil)
|
15
|
+
end
|
16
|
+
|
17
|
+
def key(app_id)
|
18
|
+
if prefix
|
19
|
+
"#{prefix}/#{app_id}.conf"
|
20
|
+
else
|
21
|
+
"#{app_id}.conf"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def deploy_starting(containers)
|
27
|
+
front = containers.fetch('front')
|
28
|
+
front.definition['env'].merge!(
|
29
|
+
'AWS_DEFAULT_REGION' => @s3.region,
|
30
|
+
'S3_CONFIG_BUCKET' => @s3.bucket,
|
31
|
+
'S3_CONFIG_KEY' => @s3.key(@app.id),
|
32
|
+
)
|
33
|
+
front.links << link_app
|
34
|
+
end
|
35
|
+
|
36
|
+
def deploy_started(containers, front_port)
|
37
|
+
app = containers.fetch('app')
|
38
|
+
front = containers.fetch('front')
|
39
|
+
front.definition['port_mappings'] << port_mapping(front_port)
|
40
|
+
upload_config(generate_config(app.port))
|
41
|
+
Hako.logger.debug "Uploaded front configuration to s3://#{@s3.bucket}/#{@s3.key(@app.id)}"
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def configure(options)
|
47
|
+
super
|
48
|
+
@options = options
|
49
|
+
@s3 = S3Config.new(@options.fetch('s3'))
|
50
|
+
end
|
51
|
+
|
52
|
+
def link_app
|
53
|
+
'app:app'
|
54
|
+
end
|
55
|
+
|
56
|
+
def port_mapping(front_port)
|
57
|
+
{ container_port: 80, host_port: front_port, protocol: 'tcp' }
|
58
|
+
end
|
59
|
+
|
60
|
+
def generate_config(app_port)
|
61
|
+
Generator.new(@options, app_port).render
|
62
|
+
end
|
63
|
+
|
64
|
+
def upload_config(front_conf)
|
65
|
+
s3_client.put_object(
|
66
|
+
body: front_conf,
|
67
|
+
bucket: @s3.bucket,
|
68
|
+
key: @s3.key(@app.id),
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
def s3_client
|
73
|
+
@s3_client ||= Aws::S3::Client.new(region: @s3.region)
|
74
|
+
end
|
75
|
+
|
76
|
+
class Generator
|
77
|
+
def initialize(options, app_port)
|
78
|
+
@options = options
|
79
|
+
@app_port = app_port
|
80
|
+
end
|
81
|
+
|
82
|
+
def render
|
83
|
+
ERB.new(File.read(nginx_conf_erb), nil, '-').result(binding)
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def listen_spec
|
89
|
+
"app:#{@app_port}"
|
90
|
+
end
|
91
|
+
|
92
|
+
def templates_directory
|
93
|
+
File.expand_path('../../templates', __FILE__)
|
94
|
+
end
|
95
|
+
|
96
|
+
def nginx_conf_erb
|
97
|
+
File.join(templates_directory, 'nginx.conf.erb')
|
98
|
+
end
|
99
|
+
|
100
|
+
def nginx_location_conf_erb
|
101
|
+
File.join(templates_directory, 'nginx.location.conf.erb')
|
102
|
+
end
|
103
|
+
|
104
|
+
def locations
|
105
|
+
locs = @options.fetch('locations', {}).dup
|
106
|
+
locs['/'] ||= {}
|
107
|
+
locs.keys.each do |k|
|
108
|
+
locs[k] = Location.new(locs[k])
|
109
|
+
end
|
110
|
+
locs
|
111
|
+
end
|
112
|
+
|
113
|
+
def client_max_body_size
|
114
|
+
@options.fetch('client_max_body_size', nil)
|
115
|
+
end
|
116
|
+
|
117
|
+
def render_location(listen_spec, location)
|
118
|
+
ERB.new(File.read(nginx_location_conf_erb), nil, '-').result(binding).each_line.map do |line|
|
119
|
+
" #{line}"
|
120
|
+
end.join('')
|
121
|
+
end
|
122
|
+
|
123
|
+
class Location
|
124
|
+
def initialize(config)
|
125
|
+
@config = config
|
126
|
+
end
|
127
|
+
|
128
|
+
def allow_only_from
|
129
|
+
allow = @config.fetch('allow_only_from', nil)
|
130
|
+
if allow
|
131
|
+
allow.flatten
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
data/lib/hako/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hako
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kohei Suzuki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -116,9 +116,6 @@ files:
|
|
116
116
|
- lib/hako/env_providers.rb
|
117
117
|
- lib/hako/env_providers/file.rb
|
118
118
|
- lib/hako/error.rb
|
119
|
-
- lib/hako/front.rb
|
120
|
-
- lib/hako/fronts.rb
|
121
|
-
- lib/hako/fronts/nginx.rb
|
122
119
|
- lib/hako/loader.rb
|
123
120
|
- lib/hako/scheduler.rb
|
124
121
|
- lib/hako/schedulers.rb
|
@@ -128,6 +125,7 @@ files:
|
|
128
125
|
- lib/hako/schedulers/ecs_elb.rb
|
129
126
|
- lib/hako/script.rb
|
130
127
|
- lib/hako/scripts.rb
|
128
|
+
- lib/hako/scripts/nginx_front.rb
|
131
129
|
- lib/hako/templates/nginx.conf.erb
|
132
130
|
- lib/hako/templates/nginx.location.conf.erb
|
133
131
|
- lib/hako/version.rb
|
data/lib/hako/front.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'hako/container'
|
3
|
-
|
4
|
-
module Hako
|
5
|
-
class Front < Container
|
6
|
-
S3Config = Struct.new(:region, :bucket, :prefix) do
|
7
|
-
def initialize(options)
|
8
|
-
self.region = options.fetch('region')
|
9
|
-
self.bucket = options.fetch('bucket')
|
10
|
-
self.prefix = options.fetch('prefix', nil)
|
11
|
-
end
|
12
|
-
|
13
|
-
def key(app_id)
|
14
|
-
if prefix
|
15
|
-
"#{prefix}/#{app_id}.conf"
|
16
|
-
else
|
17
|
-
"#{app_id}.conf"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
attr_reader :s3
|
23
|
-
|
24
|
-
def initialize(*)
|
25
|
-
super
|
26
|
-
@s3 = S3Config.new(@definition.fetch('s3'))
|
27
|
-
end
|
28
|
-
|
29
|
-
def env
|
30
|
-
super.merge(
|
31
|
-
'AWS_DEFAULT_REGION' => @s3.region,
|
32
|
-
'S3_CONFIG_BUCKET' => @s3.bucket,
|
33
|
-
'S3_CONFIG_KEY' => @s3.key(@app.id),
|
34
|
-
)
|
35
|
-
end
|
36
|
-
|
37
|
-
DEFAULT_LINK = ['app:app'].freeze
|
38
|
-
|
39
|
-
def links
|
40
|
-
DEFAULT_LINK + super
|
41
|
-
end
|
42
|
-
|
43
|
-
def extra
|
44
|
-
@definition.fetch('extra', {})
|
45
|
-
end
|
46
|
-
|
47
|
-
def generate_config(_app_port)
|
48
|
-
raise NotImplementedError
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
data/lib/hako/fronts.rb
DELETED
data/lib/hako/fronts/nginx.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'erb'
|
3
|
-
require 'hako/front'
|
4
|
-
|
5
|
-
module Hako
|
6
|
-
module Fronts
|
7
|
-
class Nginx < Front
|
8
|
-
def generate_config(app_port)
|
9
|
-
listen_spec = "app:#{app_port}"
|
10
|
-
ERB.new(File.read(nginx_conf_erb), nil, '-').result(binding)
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def templates_directory
|
16
|
-
File.expand_path('../../templates', __FILE__)
|
17
|
-
end
|
18
|
-
|
19
|
-
def nginx_conf_erb
|
20
|
-
File.join(templates_directory, 'nginx.conf.erb')
|
21
|
-
end
|
22
|
-
|
23
|
-
def nginx_location_conf_erb
|
24
|
-
File.join(templates_directory, 'nginx.location.conf.erb')
|
25
|
-
end
|
26
|
-
|
27
|
-
def locations
|
28
|
-
locs = extra.fetch('locations', {}).dup
|
29
|
-
locs['/'] ||= {}
|
30
|
-
locs.keys.each do |k|
|
31
|
-
locs[k] = Location.new(locs[k])
|
32
|
-
end
|
33
|
-
locs
|
34
|
-
end
|
35
|
-
|
36
|
-
def client_max_body_size
|
37
|
-
extra.fetch('client_max_body_size', nil)
|
38
|
-
end
|
39
|
-
|
40
|
-
def render_location(listen_spec, location)
|
41
|
-
ERB.new(File.read(nginx_location_conf_erb), nil, '-').result(binding).each_line.map do |line|
|
42
|
-
" #{line}"
|
43
|
-
end.join('')
|
44
|
-
end
|
45
|
-
|
46
|
-
class Location
|
47
|
-
def initialize(config)
|
48
|
-
@config = config
|
49
|
-
end
|
50
|
-
|
51
|
-
def allow_only_from
|
52
|
-
allow = @config.fetch('allow_only_from', nil)
|
53
|
-
if allow
|
54
|
-
allow.flatten
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|