tsudura 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +65 -2
- data/lib/tsudura/aws/ami.rb +26 -11
- data/lib/tsudura/aws/auto_scale.rb +1 -1
- data/lib/tsudura/aws/launch_config.rb +21 -11
- data/lib/tsudura/runners/runner_module.rb +1 -1
- data/lib/tsudura/version.rb +1 -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: 0a0470a3c4aa12624b45c467c4db3780c8d68992
|
4
|
+
data.tar.gz: e4915ac392c3cf88bef730316c755e57a66bdb5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8806a7f55ff2b141f035fae551536bc31def8581535705836aa944efb841559d76c36c6c6769ac05854bb4edf06bdb5df9021577c8b043b9c9ba85016eec1b4
|
7
|
+
data.tar.gz: 0faaf307e0dd09e71a2128b03897b3e55494d880284f234231515125313c989dc292ced44a69ab88e716fc46e155a722e4af3fdc07a095f0e8d4d2aea94293a3
|
data/README.md
CHANGED
@@ -3,10 +3,12 @@
|
|
3
3
|
# WARNING
|
4
4
|
|
5
5
|
This gem is alpha version.
|
6
|
+
このgemはまだアルファ版です。
|
6
7
|
|
7
8
|
# Tsudura
|
8
9
|
|
9
|
-
|
10
|
+
Yamlに記述した設定を元にAnsible Playbookをsshで実行し、AWSのAmiの作成、LaunchConfigの作成、AutoScalingGroupに紐づくLaunchConfigの入れ替えを行うコマンドラインツールです。
|
11
|
+
Packer + Ansibleを使い、自分が足りないと思った機能を埋めるために作成しました。
|
10
12
|
|
11
13
|
## Installation
|
12
14
|
|
@@ -16,7 +18,68 @@ install it yourself as:
|
|
16
18
|
|
17
19
|
## Usage
|
18
20
|
|
19
|
-
|
21
|
+
`build`コマンドを使用します。
|
22
|
+
|
23
|
+
```sh
|
24
|
+
$ tsudura build example.yml
|
25
|
+
```
|
26
|
+
|
27
|
+
### 設定ファイル
|
28
|
+
|
29
|
+
packerで言う設定を記述するjsonをtsuduraではyamlに記述します。
|
30
|
+
[spec/samples/yamls](https://github.com/onigra/tsudura/tree/master/spec/samples/yamls)にテストで使用しているサンプルのyamlがありますので、参考になると思います。
|
31
|
+
また、yamlはERBの記法が使用できるようにしてあります。
|
32
|
+
|
33
|
+
#### required
|
34
|
+
|
35
|
+
- `service`: 扱うリソースの名前空間です。作成されたリソースにprefixとして付与されます。
|
36
|
+
- `region`: インスタンスを作成するRegionを指定します。
|
37
|
+
- `security_group_id`: インスタンスに設定するSecurityGroupIDを指定します。
|
38
|
+
- `subnet_id`: インスタンスに設定するSubnetIDを指定します。
|
39
|
+
- `image_id`: インスタンスを作成する際のAmiのIDを指定します。
|
40
|
+
- `key_name`: インスタンスを作成する際のKeyPairの名前を指定します。
|
41
|
+
- `instance_type`: インスタンスを作成、LaunchConfigを作成する際のInstanceTypeを指定します。
|
42
|
+
- `playbook_path`: 実行するAnsiblePlaybookのPathを指定します。
|
43
|
+
- `inventory_file`: Ansibleを実行する際のInventoryFileのPathを指定します。
|
44
|
+
- `owner`: Amiを作成する際に指定するOwnerのIDを指定します。
|
45
|
+
|
46
|
+
#### options
|
47
|
+
|
48
|
+
- `vault_password`: AnsibleVaultを使用していた場合、実行する際のVaultPasswordを指定します。
|
49
|
+
- `mode`: 後述する実行モードを指定します。
|
50
|
+
- `user_data_script`: LaunchConfigを作成する際にUserDataScriptを指定します。
|
51
|
+
- `auto_scaling_group_name`: 新しく作成したLaunchConfigを紐づけるAutoScalingGroupを指定します。
|
52
|
+
|
53
|
+
### モードについて
|
54
|
+
|
55
|
+
#### NormalMode
|
56
|
+
|
57
|
+
デフォルト。何も指定しないとこれになる。
|
58
|
+
|
59
|
+
- Amiの作成
|
60
|
+
- LaunchConfigの作成
|
61
|
+
- AutoScalingGroupの更新
|
62
|
+
|
63
|
+
```yaml
|
64
|
+
mode: normal
|
65
|
+
```
|
66
|
+
|
67
|
+
#### PackerMode
|
68
|
+
|
69
|
+
- Amiの作成
|
70
|
+
|
71
|
+
```yaml
|
72
|
+
mode: packer
|
73
|
+
```
|
74
|
+
|
75
|
+
#### PackerPlusMode
|
76
|
+
|
77
|
+
- Amiの作成
|
78
|
+
- LaunchConfigの作成
|
79
|
+
|
80
|
+
```yaml
|
81
|
+
mode: packer_plus
|
82
|
+
```
|
20
83
|
|
21
84
|
## Development
|
22
85
|
|
data/lib/tsudura/aws/ami.rb
CHANGED
@@ -15,19 +15,13 @@ module Tsudura::Aws
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def deregister
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
unless not_use_images.empty?
|
19
|
+
not_use_images.each do |image_id|
|
20
|
+
ec2.deregister_image(image_id: image_id)
|
21
|
+
end
|
22
|
+
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def get_old_image(images)
|
26
|
-
old_image_id = nil
|
27
|
-
images.each_page { |i| old_image_id = i.images.map(&:image_id).reject { |id| id == @new_image_id }.first }
|
28
|
-
old_image_id
|
29
|
-
end
|
30
|
-
|
31
25
|
private
|
32
26
|
|
33
27
|
def create_ami
|
@@ -52,5 +46,26 @@ module Tsudura::Aws
|
|
52
46
|
def ec2
|
53
47
|
@ec2 ||= ::Aws::EC2::Client.new(region: @config[:region])
|
54
48
|
end
|
49
|
+
|
50
|
+
def launch_config
|
51
|
+
@launch_config ||= ::Aws::AutoScaling::Client.new(region: @config[:region])
|
52
|
+
end
|
53
|
+
|
54
|
+
def not_use_images
|
55
|
+
@not_use_images ||= all_images - available_images
|
56
|
+
end
|
57
|
+
|
58
|
+
def all_images
|
59
|
+
ec2.describe_images(
|
60
|
+
owners: ["#{@config[:owner]}"],
|
61
|
+
filters: [ { name: "name", values: ["#{@config[:service]}-#{short_env}*"] }]
|
62
|
+
)[:images].map(&:image_id)
|
63
|
+
end
|
64
|
+
|
65
|
+
def available_images
|
66
|
+
launch_config.describe_launch_configurations[:launch_configurations]
|
67
|
+
.select { |i| i[:launch_configuration_name] =~ /#{@config[:service]}-#{short_env}/ }
|
68
|
+
.map(&:image_id).uniq
|
69
|
+
end
|
55
70
|
end
|
56
71
|
end
|
@@ -9,7 +9,7 @@ module Tsudura::Aws
|
|
9
9
|
|
10
10
|
def update
|
11
11
|
autoscaling.update_auto_scaling_group(
|
12
|
-
auto_scaling_group_name:
|
12
|
+
auto_scaling_group_name: @config[:auto_scaling_group_name],
|
13
13
|
launch_configuration_name: "#{@config[:service]}-#{short_env}-#{@timestamp}",
|
14
14
|
)
|
15
15
|
end
|
@@ -20,23 +20,33 @@ module Tsudura::Aws
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def delete
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
tmp = []
|
28
|
-
|
29
|
-
autoscaling.describe_launch_configurations.each_page do |i|
|
30
|
-
tmp << i.launch_configurations.select { |item| item.launch_configuration_name =~ /#{@config[:service]}-#{short_env}/ }
|
23
|
+
unless unavailable_launch_configurations.empty?
|
24
|
+
unavailable_launch_configurations.each do |launch_configuration_name|
|
25
|
+
autoscaling.delete_launch_configuration(launch_configuration_name: launch_configuration_name)
|
26
|
+
end
|
31
27
|
end
|
32
|
-
|
33
|
-
tmp.flatten.reject { |obj| obj.launch_configuration_name == @new_launch_config }.map(&:launch_configuration_name).first
|
34
28
|
end
|
35
29
|
|
36
30
|
private
|
37
|
-
|
31
|
+
|
38
32
|
def autoscaling
|
39
33
|
@autoscaling ||= ::Aws::AutoScaling::Client.new(region: @config[:region])
|
40
34
|
end
|
35
|
+
|
36
|
+
def unavailable_launch_configurations
|
37
|
+
@unavailable_launch_configurations ||= all_launch_configurations - available_launch_configurations
|
38
|
+
end
|
39
|
+
|
40
|
+
def available_launch_configurations
|
41
|
+
autoscaling.describe_auto_scaling_groups[:auto_scaling_groups]
|
42
|
+
.select { |i| i[:launch_configuration_name] =~ /#{@config[:service]}-#{short_env}/ }
|
43
|
+
.map(&:launch_configuration_name).uniq
|
44
|
+
end
|
45
|
+
|
46
|
+
def all_launch_configurations
|
47
|
+
autoscaling.describe_launch_configurations[:launch_configurations]
|
48
|
+
.select { |i| i[:launch_configuration_name] =~ /#{@config[:service]}-#{short_env}/ }
|
49
|
+
.map(&:launch_configuration_name)
|
50
|
+
end
|
41
51
|
end
|
42
52
|
end
|
data/lib/tsudura/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tsudura
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- onigra
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|