ecs-easy-cluster 0.0.5 → 0.0.6
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 +2 -0
- data/README.md +5 -1
- data/lib/ecs/easy/cluster.rb +1 -1
- data/lib/ecs/easy/cluster/base.rb +6 -6
- data/lib/ecs/easy/cluster/version.rb +1 -1
- data/lib/ecs/easy/instance.rb +25 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f43b098142b1ec41091702d773f503ac1f9cde1
|
4
|
+
data.tar.gz: f212ffa392b6fc9c39f43b9d2eb6657484d9968f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25bab6267329d2bb178e677ba832fe52fb683bb325dae65e4a910772e69710dce1b13cf875935b78054e22c04f9dc2a5cbdcaa553aee3c946e0381001e78ee32
|
7
|
+
data.tar.gz: 07e5b1a9a28842e0ce540146fda934a64d7c3730b3b2faf1bbe900e279603f6e85fdb103f370aa7cd3131954272f32d9625a3de38e32deff8c387b2dd2238ec0
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -19,7 +19,7 @@ Or install it yourself as:
|
|
19
19
|
|
20
20
|
## Usage
|
21
21
|
|
22
|
-
```
|
22
|
+
```ruby
|
23
23
|
require "ecs/easy/cluster"
|
24
24
|
|
25
25
|
#
|
@@ -41,6 +41,10 @@ instance = Ecs::Easy::Instance.new do |i|
|
|
41
41
|
i.vpc = "vpc-00000000"
|
42
42
|
i.image_id = "ami-00000000"
|
43
43
|
i.security_group = "sg-00000000"
|
44
|
+
# Currently user_data allows only /bin/bash
|
45
|
+
i.user_data = [
|
46
|
+
"echo 'xxxxxxxx' >> /home/ec2-user/.ssh/authorized_keys\n",
|
47
|
+
]
|
44
48
|
end
|
45
49
|
|
46
50
|
#
|
data/lib/ecs/easy/cluster.rb
CHANGED
@@ -11,7 +11,7 @@ require "ecs/easy/instance"
|
|
11
11
|
# c.region = ""
|
12
12
|
# end
|
13
13
|
# instance = Ecs::Easy::Instance.new do |i|
|
14
|
-
# i.
|
14
|
+
# i.type = "t2.nano"
|
15
15
|
# i.keypair = "your-keypair"
|
16
16
|
# i.azs = "ap-northeast-1a,ap-northeast-1c"
|
17
17
|
# i.subnets = "subnet-00000000,subnet-11111111"
|
@@ -1,9 +1,6 @@
|
|
1
1
|
module Ecs::Easy::Cluster
|
2
2
|
class Base
|
3
3
|
|
4
|
-
TEMPLATE_PATH = File.expand_path("../config/cloudformation_template.json", __FILE__)
|
5
|
-
TEMPLATE_BODY = File.read( TEMPLATE_PATH )
|
6
|
-
|
7
4
|
attr_reader :name, :configure, :ecs_client, :stack_name, :cfn_client
|
8
5
|
attr_accessor :instance, :min_instances, :max_instances
|
9
6
|
|
@@ -88,9 +85,10 @@ module Ecs::Easy::Cluster
|
|
88
85
|
ecs_client.create_cluster( cluster_name: name )
|
89
86
|
|
90
87
|
params = instance.cfn_parameters( name, "AsgMaxSize" => min_instances.to_s)
|
88
|
+
template_body = instance.template_body
|
91
89
|
cfn_client.create_stack(
|
92
90
|
stack_name: stack_name,
|
93
|
-
template_body:
|
91
|
+
template_body: template_body,
|
94
92
|
parameters: params,
|
95
93
|
capabilities: ["CAPABILITY_IAM"],
|
96
94
|
on_failure: "DELETE",
|
@@ -116,9 +114,10 @@ module Ecs::Easy::Cluster
|
|
116
114
|
size = (num_instances+1 <= max_instances) ? num_instances+1 : max_instances
|
117
115
|
|
118
116
|
params = instance.cfn_parameters( name, "AsgMaxSize" => size.to_s)
|
117
|
+
template_body = instance.template_body
|
119
118
|
cfn_client.update_stack(
|
120
119
|
stack_name: stack_name,
|
121
|
-
template_body:
|
120
|
+
template_body: template_body,
|
122
121
|
parameters: params,
|
123
122
|
capabilities: ["CAPABILITY_IAM"],
|
124
123
|
)
|
@@ -142,9 +141,10 @@ module Ecs::Easy::Cluster
|
|
142
141
|
# TODO: Support idling check of container instances
|
143
142
|
def shrink!
|
144
143
|
params = instance.cfn_parameters( name, "AsgMaxSize" => min_instances.to_s)
|
144
|
+
template_body = instance.template_body
|
145
145
|
cfn_client.update_stack(
|
146
146
|
stack_name: stack_name,
|
147
|
-
template_body:
|
147
|
+
template_body: template_body,
|
148
148
|
parameters: params,
|
149
149
|
capabilities: ["CAPABILITY_IAM"],
|
150
150
|
)
|
data/lib/ecs/easy/instance.rb
CHANGED
@@ -2,13 +2,17 @@ module Ecs
|
|
2
2
|
module Easy
|
3
3
|
class Instance
|
4
4
|
|
5
|
+
TEMPLATE_PATH = File.expand_path("../cluster/config/cloudformation_template.json", __FILE__)
|
6
|
+
TEMPLATE_BODY = File.read( TEMPLATE_PATH )
|
7
|
+
|
5
8
|
attr_accessor :type,
|
6
9
|
:keypair,
|
7
10
|
:azs, # availability zones
|
8
11
|
:subnets,
|
9
12
|
:vpc,
|
10
13
|
:image_id,
|
11
|
-
:security_group
|
14
|
+
:security_group,
|
15
|
+
:user_data
|
12
16
|
|
13
17
|
def initialize **params
|
14
18
|
params.each do |k,v|
|
@@ -17,6 +21,26 @@ module Ecs
|
|
17
21
|
yield( self ) if block_given?
|
18
22
|
end
|
19
23
|
|
24
|
+
def custom_user_data
|
25
|
+
default_user_data = [
|
26
|
+
"#!/bin/bash\n",
|
27
|
+
"echo ECS_CLUSTER=",
|
28
|
+
{
|
29
|
+
"Ref" => "EcsCluster"
|
30
|
+
},
|
31
|
+
" >> /etc/ecs/ecs.config\n"
|
32
|
+
]
|
33
|
+
default_user_data.concat(user_data)
|
34
|
+
end
|
35
|
+
|
36
|
+
def template_body
|
37
|
+
return TEMPLATE_BODY if user_data.nil? or user_data.empty?
|
38
|
+
body = JSON.parse( TEMPLATE_BODY )
|
39
|
+
body["Resources"]["EcsInstanceLc"]["Properties"]["UserData"]["Fn::Base64"]["Fn::Join"][1] = custom_user_data
|
40
|
+
body["Resources"]["EcsInstanceLcWithoutKeyPair"]["Properties"]["UserData"]["Fn::Base64"]["Fn::Join"][1] = custom_user_data
|
41
|
+
return JSON.pretty_generate( body )
|
42
|
+
end
|
43
|
+
|
20
44
|
# Generate the parameters for cloudformation
|
21
45
|
def cfn_parameters( cluster_name, params={} )
|
22
46
|
base_params = [
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ecs-easy-cluster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- metheglin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|