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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 79863dc07a8eab32cf0fceccdf7551ce5e2dccd2
4
- data.tar.gz: 466d0dd80e222094cc0041f414e81bb113fb50c3
3
+ metadata.gz: 9f43b098142b1ec41091702d773f503ac1f9cde1
4
+ data.tar.gz: f212ffa392b6fc9c39f43b9d2eb6657484d9968f
5
5
  SHA512:
6
- metadata.gz: b63e90c6af6f3dff5b65f622f6e7f3af1c922292c1dc8a18aa9e57810a4a413707f0e564dea18bd101b7e6238f99b5e78b5fb6ea799db24b0fd3d03023fcacf9
7
- data.tar.gz: 42c45c024ccc3feb0b64893159d2ced1e005b11ee44aca55fccad644b3a4d446f1a1fbf561dcbda60f8a637562928f4a12d30b5975b2197d94a5c52178f49b6e
6
+ metadata.gz: 25bab6267329d2bb178e677ba832fe52fb683bb325dae65e4a910772e69710dce1b13cf875935b78054e22c04f9dc2a5cbdcaa553aee3c946e0381001e78ee32
7
+ data.tar.gz: 07e5b1a9a28842e0ce540146fda934a64d7c3730b3b2faf1bbe900e279603f6e85fdb103f370aa7cd3131954272f32d9625a3de38e32deff8c387b2dd2238ec0
data/.gitignore CHANGED
@@ -20,3 +20,5 @@ tmp
20
20
  *.o
21
21
  *.a
22
22
  mkmf.log
23
+
24
+ README.private.md
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
  #
@@ -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.instance_type = "t2.nano"
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: 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: 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: TEMPLATE_BODY,
147
+ template_body: template_body,
148
148
  parameters: params,
149
149
  capabilities: ["CAPABILITY_IAM"],
150
150
  )
@@ -1,7 +1,7 @@
1
1
  module Ecs
2
2
  module Easy
3
3
  module Cluster
4
- VERSION = "0.0.5"
4
+ VERSION = "0.0.6"
5
5
  end
6
6
  end
7
7
  end
@@ -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.5
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-01-27 00:00:00.000000000 Z
11
+ date: 2017-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk