autocanary24 0.1.0.pre.alpha2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -9
- data/docs/autocanary_0_100.png +0 -0
- data/docs/autocanary_100_0.png +0 -0
- data/docs/autocanary_100_none.png +0 -0
- data/docs/autocanary_20_80.png +0 -0
- data/docs/autocanary_50_50.png +0 -0
- data/docs/autocanary_80_20.png +0 -0
- data/docs/autocanary_drawio.xml +2 -0
- data/docs/autocanary_none_100.png +0 -0
- data/examples/README.md +49 -0
- data/examples/Rakefile +68 -12
- data/examples/asg-stack.json +10 -2
- data/examples/base-stack.json +2 -2
- data/lib/autocanary24/client.rb +32 -17
- data/lib/autocanary24/configuration.rb +1 -1
- data/lib/autocanary24/version.rb +1 -1
- metadata +12 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8cf4cb43f616b217f59cdd35f148e9e7747e5fd
|
4
|
+
data.tar.gz: a1733265748fc179e835b7fc062f24b90146b35f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b60821bc03cad2bd04ec1be8a8adb5e6657e8c6b6be3e9ac159df47c7154bd36435520307ea085b105203dbffe119d669743813e280b92a4bb70eafc718921e1
|
7
|
+
data.tar.gz: 8f7c432d4b3333059a77a468eebb9b4eda13d40599f89fb65926090caba4622fa56072615529c513aeccefb37b3b3e8506f37ba149605c7a082b1e1e9f700fba
|
data/README.md
CHANGED
@@ -24,33 +24,45 @@ Or install it yourself as:
|
|
24
24
|
|
25
25
|
## Usage
|
26
26
|
|
27
|
+
Prerequisite: Deploy the base stack before
|
28
|
+
|
27
29
|
Initialize the client, e.g. in your `Rakefile` and deploy your stack:
|
28
30
|
|
29
31
|
```ruby
|
30
|
-
#
|
31
|
-
|
32
|
+
# Configure the AutoCanary24 Client
|
32
33
|
ac = AutoCanary24::Client.new({
|
33
34
|
keep_inactive_stack: false,
|
34
|
-
|
35
|
-
|
35
|
+
keep_instances_balanced: false,
|
36
|
+
scaling_instance_percent: 50
|
37
|
+
})
|
38
|
+
```
|
36
39
|
|
40
|
+
The available configuration:
|
41
|
+
- `keep_inactive_stack`: If `true` the inactive stack gets not deleted.
|
42
|
+
Default is `false`
|
43
|
+
- `keep_instances_balanced`: If `true` a instance from current stack gets removed whenever a new instance from the new stack is added. If `false` first all new instances are created and afterwards the old instances gets removed.
|
44
|
+
Default is `false`
|
45
|
+
- `scaling_instance_percent`: Percent of instances which are added at once (depends on the actual number of instances, read from desired).
|
46
|
+
Default is `100`
|
47
|
+
- `wait_timeout`: Timeout in seconds to wait for checking AWS operations are done before do a rollback.
|
48
|
+
Default is `300`
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
# Execute the deployment
|
37
52
|
ac.deploy_stack(parent_stack_name, template, parameters, tags, deployment_check)
|
38
53
|
```
|
39
54
|
|
55
|
+
The available parameters:
|
40
56
|
- `parent_stack_name`: the name of the 'base' stack. In addition `AutoStacker24` will read the output parameters of an existing stack and merge them to the given parameters.
|
41
57
|
- `template`: is either the template json data itself or the name of a file containing the template body
|
42
58
|
- `parameters`: specify the input parameter as a simple ruby hash. It gets converted to the
|
43
59
|
cumbersome AWS format automatically.
|
44
60
|
The template body will be validated and optionally preprocessed.
|
45
61
|
- `tags`: Optional. Key-value pairs to associate with this stack.
|
46
|
-
-
|
62
|
+
- `deployment_check`: Optional. A `lambda` which is executed whenever new instances are added to the ELB. If `true` AutoCanary continues, if `false` it will rollback to the current stack.
|
47
63
|
|
48
64
|
> For more information about stacked CloudFormation stacks visit [AutoStacker24](https://github.com/autoscout24/autostacker24).
|
49
65
|
|
50
|
-
The available configuration:
|
51
|
-
- `keep_inactive_stack`: If `true` the inactive stack gets not deleted. Default is `false`
|
52
|
-
- `keep_instances_balanced`: If `true` a instance from current stack gets removed whenever a new instance from the new stack is added. If `false` first all new instances are created and afterwards the old instances gets removed.
|
53
|
-
- `scaling_instance_percent`: Percent of instances which are added at once (depends on the actual number of instances, read from desired)
|
54
66
|
|
55
67
|
|
56
68
|
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,2 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<mxfile userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36" version="5.4.0.6" editor="www.draw.io" type="google"><diagram>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</diagram></mxfile>
|
Binary file
|
data/examples/README.md
CHANGED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Examples
|
2
|
+
|
3
|
+
This folder contains 4 different examples how AutoCanary24 can be used. You should have set the AWS credentials before you execute them.
|
4
|
+
|
5
|
+
## 1) Switch complete stacks at once not keeping the inactive stack
|
6
|
+
|
7
|
+
How to run: `rake sample_1`
|
8
|
+
|
9
|
+
| Steps | |
|
10
|
+
| :------------- | :------------- |
|
11
|
+
| Initial state: All the traffic goes to blue stack | <img src="../docs/autocanary_100_none.png" height="150" /> |
|
12
|
+
| Green stack is created | <img src="../docs/autocanary_100_0.png" height="150" /> |
|
13
|
+
| Green stack gets all the traffic | <img src="../docs/autocanary_0_100.png" height="150" /> |
|
14
|
+
| Blue stack will be deleted | <img src="../docs/autocanary_none_100.png" height="150" /> |
|
15
|
+
|
16
|
+
## 2) Switch complete stacks at once keeping the inactive stack
|
17
|
+
|
18
|
+
How to run: `rake sample_2`
|
19
|
+
|
20
|
+
| Steps | |
|
21
|
+
| :------------- | :------------- |
|
22
|
+
| Initial state: All the traffic goes to blue stack | <img src="../docs/autocanary_100_none.png" height="150" /> |
|
23
|
+
| Green stack is created | <img src="../docs/autocanary_100_0.png" height="150" /> |
|
24
|
+
| Green stack gets all the traffic. Blue stack will not be deleted | <img src="../docs/autocanary_0_100.png" height="150" /> |
|
25
|
+
|
26
|
+
## 3) Switch incrementally the stacks keeping the inactive stack
|
27
|
+
|
28
|
+
How to run: `rake sample_3`
|
29
|
+
|
30
|
+
| Steps | |
|
31
|
+
| :------------- | :------------- |
|
32
|
+
| Initial state: All the traffic goes to blue stack | <img src="../docs/autocanary_100_0.png" height="150" /> |
|
33
|
+
| Green stack gets some traffic | <img src="../docs/autocanary_80_20.png" height="150" /> |
|
34
|
+
| Green stack gets more traffic | <img src="../docs/autocanary_50_50.png" height="150" /> |
|
35
|
+
| Green stack gets even more traffic | <img src="../docs/autocanary_20_80.png" height="150" /> |
|
36
|
+
| Final state: All the traffic goes to green stack | <img src="../docs/autocanary_0_100.png" height="150" /> |
|
37
|
+
|
38
|
+
|
39
|
+
## 4) Switch incrementally the stacks and rollback
|
40
|
+
|
41
|
+
How to run: `rake sample_4`
|
42
|
+
|
43
|
+
| Steps | |
|
44
|
+
| :------------- | :------------- |
|
45
|
+
| Initial state: All the traffic goes to blue stack | <img src="../docs/autocanary_100_none.png" height="150" /> |
|
46
|
+
| Green stack is created | <img src="../docs/autocanary_100_0.png" height="150" /> |
|
47
|
+
| Green stack gets some traffic | <img src="../docs/autocanary_80_20.png" height="150" /> |
|
48
|
+
| Green stack gets more traffic | <img src="../docs/autocanary_50_50.png" height="150" /> |
|
49
|
+
| Rollback: All the traffic goes again to blue stack | <img src="../docs/autocanary_100_0.png" height="150" /> |
|
data/examples/Rakefile
CHANGED
@@ -1,29 +1,85 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require_relative
|
1
|
+
require 'aws-sdk-core'
|
2
|
+
require 'autostacker24'
|
3
|
+
require_relative '../lib/autocanary24/client'
|
4
4
|
|
5
5
|
STACK_NAME = 'autocanary24-example'
|
6
6
|
BASE_TEMPLATE = 'base-stack.json'
|
7
7
|
ASG_TEMPLATE = 'asg-stack.json'
|
8
|
+
ASG_PARAMETER = { MinimumNumberOfServers: 5, MaximumNumberOfServers: 5 }
|
9
|
+
TAGS = [ { key: 'Name', value: STACK_NAME } ]
|
8
10
|
|
9
|
-
|
11
|
+
desc 'switch complete stacks at once not keeping the inactive stack'
|
12
|
+
task :sample_1 do
|
13
|
+
puts 'executing sample_1: switch complete stacks at once not keeping the inactive stack'
|
10
14
|
|
11
15
|
# 1) Create the base stack which includes at least the ELB
|
12
|
-
|
13
|
-
Stacker.create_or_update_stack(STACK_NAME, BASE_TEMPLATE, base_parameters)
|
16
|
+
Stacker.create_or_update_stack(STACK_NAME, BASE_TEMPLATE, {}, nil, TAGS)
|
14
17
|
|
15
18
|
# 2) Create the stack which includes the ASG
|
16
19
|
client = AutoCanary24::Client.new({
|
17
|
-
:keep_inactive_stack
|
20
|
+
:keep_inactive_stack => false,
|
21
|
+
:keep_instances_balanced => false,
|
22
|
+
:scaling_instance_percent => 100
|
18
23
|
})
|
24
|
+
client.deploy_stack(STACK_NAME, ASG_TEMPLATE, ASG_PARAMETER, TAGS)
|
25
|
+
end
|
26
|
+
|
27
|
+
desc 'switch complete stacks at once keeping the inactive stack'
|
28
|
+
task :sample_2 do
|
29
|
+
puts 'executing sample_2: switch complete stacks at once keeping the inactive stack'
|
19
30
|
|
20
|
-
|
21
|
-
|
31
|
+
# 1) Create the base stack which includes at least the ELB
|
32
|
+
Stacker.create_or_update_stack(STACK_NAME, BASE_TEMPLATE, {}, nil, TAGS)
|
22
33
|
|
34
|
+
# 2) Create the stack which includes the ASG
|
35
|
+
client = AutoCanary24::Client.new({
|
36
|
+
:keep_inactive_stack => true,
|
37
|
+
:keep_instances_balanced => false,
|
38
|
+
:scaling_instance_percent => 100
|
39
|
+
})
|
40
|
+
client.deploy_stack(STACK_NAME, ASG_TEMPLATE, ASG_PARAMETER, TAGS)
|
41
|
+
end
|
42
|
+
|
43
|
+
desc 'switch incrementally the stacks keeping the inactive stack'
|
44
|
+
task :sample_3 do
|
45
|
+
puts 'executing sample_3: switch incrementally the stacks keeping the inactive stack'
|
46
|
+
|
47
|
+
# 1) Create the base stack which includes at least the ELB
|
48
|
+
Stacker.create_or_update_stack(STACK_NAME, BASE_TEMPLATE, {}, nil, TAGS)
|
49
|
+
|
50
|
+
# 2) Create the stack which includes the ASG
|
51
|
+
client = AutoCanary24::Client.new({
|
52
|
+
:keep_inactive_stack => true,
|
53
|
+
:keep_instances_balanced => true,
|
54
|
+
:scaling_instance_percent => 20
|
55
|
+
})
|
56
|
+
client.deploy_stack(STACK_NAME, ASG_TEMPLATE, ASG_PARAMETER, TAGS)
|
57
|
+
end
|
58
|
+
|
59
|
+
desc 'switch incrementally the stacks and rollback'
|
60
|
+
task :sample_4 do
|
61
|
+
puts 'executing sample_4: switch incrementally the stacks and rollback'
|
62
|
+
|
63
|
+
# 1) Create the base stack which includes at least the ELB
|
64
|
+
Stacker.create_or_update_stack(STACK_NAME, BASE_TEMPLATE, {}, nil, TAGS)
|
65
|
+
|
66
|
+
# 2) Create the stack which includes the ASG
|
67
|
+
client = AutoCanary24::Client.new({
|
68
|
+
:keep_inactive_stack => true,
|
69
|
+
:keep_instances_balanced => true,
|
70
|
+
:scaling_instance_percent => 20
|
71
|
+
})
|
72
|
+
deployment_check = lambda { |stacks, elb, new_attached_instances|
|
73
|
+
# break during the switch from blue to green in the third iteration
|
74
|
+
!(stacks[:stack_to_create].stack_name == "#{STACK_NAME}-G" && new_attached_instances.length > 2)
|
75
|
+
}
|
76
|
+
client.deploy_stack(STACK_NAME, ASG_TEMPLATE, ASG_PARAMETER, TAGS, deployment_check)
|
23
77
|
end
|
24
78
|
|
25
79
|
task :cleanup do
|
26
|
-
|
27
|
-
|
28
|
-
Stacker.delete_stack(
|
80
|
+
puts 'executing cleanup'
|
81
|
+
|
82
|
+
Stacker.delete_stack("#{STACK_NAME}-B") unless Stacker.find_stack("#{STACK_NAME}-B").nil?
|
83
|
+
Stacker.delete_stack("#{STACK_NAME}-G") unless Stacker.find_stack("#{STACK_NAME}-G").nil?
|
84
|
+
Stacker.delete_stack(STACK_NAME) unless Stacker.find_stack(STACK_NAME).nil?
|
29
85
|
end
|
data/examples/asg-stack.json
CHANGED
@@ -14,6 +14,14 @@
|
|
14
14
|
"Default" : "t2.nano",
|
15
15
|
"AllowedValues" : [ "t1.micro", "t2.nano", "t2.micro", "t2.small", "t2.medium", "t2.large", "m1.small", "m1.medium", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "m3.medium", "m3.large", "m3.xlarge", "m3.2xlarge", "m4.large", "m4.xlarge", "m4.2xlarge", "m4.4xlarge", "m4.10xlarge", "c1.medium", "c1.xlarge", "c3.large", "c3.xlarge", "c3.2xlarge", "c3.4xlarge", "c3.8xlarge", "c4.large", "c4.xlarge", "c4.2xlarge", "c4.4xlarge", "c4.8xlarge", "g2.2xlarge", "g2.8xlarge", "r3.large", "r3.xlarge", "r3.2xlarge", "r3.4xlarge", "r3.8xlarge", "i2.xlarge", "i2.2xlarge", "i2.4xlarge", "i2.8xlarge", "d2.xlarge", "d2.2xlarge", "d2.4xlarge", "d2.8xlarge", "hi1.4xlarge", "hs1.8xlarge", "cr1.8xlarge", "cc2.8xlarge", "cg1.4xlarge"],
|
16
16
|
"ConstraintDescription" : "must be a valid EC2 instance type."
|
17
|
+
},
|
18
|
+
"MinimumNumberOfServers": {
|
19
|
+
"Description": "Minimum number of servers to have in the autoscaling group",
|
20
|
+
"Type": "Number"
|
21
|
+
},
|
22
|
+
"MaximumNumberOfServers": {
|
23
|
+
"Description": "Maximum number of servers to have in the autoscaling group",
|
24
|
+
"Type": "Number"
|
17
25
|
}
|
18
26
|
},
|
19
27
|
|
@@ -162,8 +170,8 @@
|
|
162
170
|
"Properties" : {
|
163
171
|
"AvailabilityZones" : { "Fn::GetAZs" : ""},
|
164
172
|
"LaunchConfigurationName" : { "Ref" : "LaunchConfig" },
|
165
|
-
"MinSize" : "
|
166
|
-
"MaxSize" : "
|
173
|
+
"MinSize" : "@MinimumNumberOfServers",
|
174
|
+
"MaxSize" : "@MaximumNumberOfServers",
|
167
175
|
"HealthCheckGracePeriod" : "600",
|
168
176
|
"HealthCheckType" : "ELB"
|
169
177
|
},
|
data/examples/base-stack.json
CHANGED
data/lib/autocanary24/client.rb
CHANGED
@@ -12,7 +12,7 @@ module AutoCanary24
|
|
12
12
|
@configuration = Configuration.new(params) #params.fetch(:configuration, Configuration::new(params))
|
13
13
|
end
|
14
14
|
|
15
|
-
def deploy_stack(parent_stack_name, template, parameters, tags = nil, deployment_check = lambda { |stacks, elb,
|
15
|
+
def deploy_stack(parent_stack_name, template, parameters, tags = nil, deployment_check = lambda { |stacks, elb, new_attached_instances| true })
|
16
16
|
begin
|
17
17
|
write_log(parent_stack_name, "Starting the deployment")
|
18
18
|
write_log(parent_stack_name, "Using the following configuration #{@configuration.inspect}")
|
@@ -33,8 +33,15 @@ module AutoCanary24
|
|
33
33
|
|
34
34
|
rescue Exception => e
|
35
35
|
write_log(parent_stack_name, "Unexpected exception #{e}")
|
36
|
+
raise "Deployment failed"
|
36
37
|
end
|
37
|
-
|
38
|
+
|
39
|
+
if failed
|
40
|
+
raise "Deployment failed because of rollback"
|
41
|
+
else
|
42
|
+
write_log(parent_stack_name, "Deployment finished")
|
43
|
+
end
|
44
|
+
|
38
45
|
end
|
39
46
|
|
40
47
|
private
|
@@ -86,30 +93,34 @@ module AutoCanary24
|
|
86
93
|
instances_to_toggle = (desired / 100.0 * @configuration.scaling_instance_percent).round
|
87
94
|
instances_to_toggle = 1 if (instances_to_toggle < 1)
|
88
95
|
|
89
|
-
|
90
|
-
|
96
|
+
instances_to_attach = stacks[:stack_to_create].get_instance_ids
|
97
|
+
instances_to_detach = stacks[:stack_to_delete].nil? ? [] : stacks[:stack_to_delete].get_instance_ids
|
91
98
|
|
92
99
|
missing = desired
|
93
100
|
while missing > 0
|
94
101
|
|
95
102
|
write_log(stacks[:stack_to_create].stack_name, "Adding #{instances_to_toggle} instances (#{desired-missing+instances_to_toggle}/#{desired})")
|
96
103
|
|
104
|
+
already_attached_instances = instances_to_attach[0, desired-missing+instances_to_toggle]
|
105
|
+
already_detached_instances = instances_to_detach[0, desired-missing]
|
106
|
+
|
97
107
|
begin
|
98
|
-
stacks[:stack_to_create].attach_instances_to_elb_and_wait(elb,
|
99
|
-
rescue
|
100
|
-
|
108
|
+
stacks[:stack_to_create].attach_instances_to_elb_and_wait(elb, instances_to_attach[desired-missing, instances_to_toggle])
|
109
|
+
rescue Exception => e
|
110
|
+
write_log(stacks[:stack_to_create].stack_name, "Unexpected exception: #{e}")
|
111
|
+
rollback(stacks, elb, already_attached_instances, already_detached_instances)
|
101
112
|
return true
|
102
113
|
end
|
103
114
|
|
104
|
-
unless deployment_check.call(stacks, elb,
|
105
|
-
rollback(stacks, elb,
|
115
|
+
unless deployment_check.call(stacks, elb, already_attached_instances)
|
116
|
+
rollback(stacks, elb, already_attached_instances, already_detached_instances)
|
106
117
|
return true
|
107
118
|
end
|
108
119
|
|
109
120
|
if @configuration.keep_instances_balanced && !stacks[:stack_to_delete].nil?
|
110
121
|
begin
|
111
|
-
write_log(stacks[:stack_to_delete].stack_name, "Removing #{instances_to_toggle} instances (#{
|
112
|
-
stacks[:stack_to_delete].detach_instances_from_elb(elb,
|
122
|
+
write_log(stacks[:stack_to_delete].stack_name, "Removing #{instances_to_toggle} instances (#{instances_to_detach[desired-missing, instances_to_toggle]})")
|
123
|
+
stacks[:stack_to_delete].detach_instances_from_elb(elb, instances_to_detach[desired-missing, instances_to_toggle])
|
113
124
|
rescue Exception => e
|
114
125
|
write_log(stacks[:stack_to_delete].stack_name, "WARNING: #{e}")
|
115
126
|
end
|
@@ -130,10 +141,11 @@ module AutoCanary24
|
|
130
141
|
end
|
131
142
|
end
|
132
143
|
|
133
|
-
def rollback(stacks, elb,
|
144
|
+
def rollback(stacks, elb, already_attached_instances, already_detached_instances)
|
145
|
+
write_log("", "Rollback triggered")
|
134
146
|
begin
|
135
|
-
stacks[:stack_to_create].detach_instances_from_elb(elb,
|
136
|
-
stacks[:stack_to_delete].attach_instances_to_elb_and_wait(elb,
|
147
|
+
stacks[:stack_to_create].detach_instances_from_elb(elb, already_attached_instances)
|
148
|
+
stacks[:stack_to_delete].attach_instances_to_elb_and_wait(elb, already_detached_instances)
|
137
149
|
rescue Exception => e
|
138
150
|
write_log("", "ROLLBACK FAILED: #{e}")
|
139
151
|
end
|
@@ -141,10 +153,13 @@ module AutoCanary24
|
|
141
153
|
|
142
154
|
def after_switch(stacks, keep_inactive_stack)
|
143
155
|
stacks[:stack_to_create].resume_asg_processes
|
144
|
-
stacks[:stack_to_delete].resume_asg_processes unless stacks[:stack_to_delete].nil?
|
145
156
|
|
146
|
-
|
147
|
-
|
157
|
+
unless stacks[:stack_to_delete].nil?
|
158
|
+
stacks[:stack_to_delete].resume_asg_processes
|
159
|
+
|
160
|
+
unless keep_inactive_stack
|
161
|
+
delete_stack(stacks[:stack_to_delete].stack_name)
|
162
|
+
end
|
148
163
|
end
|
149
164
|
end
|
150
165
|
|
@@ -6,7 +6,7 @@ module AutoCanary24
|
|
6
6
|
attr_accessor :keep_instances_balanced
|
7
7
|
# Percent of instances which are added at once (depends on the actual number of instances, read from desired)
|
8
8
|
attr_accessor :scaling_instance_percent
|
9
|
-
# Timeout to wait for checking AWS operations are done before do a rollback
|
9
|
+
# Timeout in seconds to wait for checking AWS operations are done before do a rollback
|
10
10
|
attr_accessor :wait_timeout
|
11
11
|
|
12
12
|
def initialize(**params)
|
data/lib/autocanary24/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: autocanary24
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Philipp Garbe
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: autostacker24
|
@@ -98,6 +98,14 @@ files:
|
|
98
98
|
- autocanary24.gemspec
|
99
99
|
- bin/console
|
100
100
|
- bin/setup
|
101
|
+
- docs/autocanary_0_100.png
|
102
|
+
- docs/autocanary_100_0.png
|
103
|
+
- docs/autocanary_100_none.png
|
104
|
+
- docs/autocanary_20_80.png
|
105
|
+
- docs/autocanary_50_50.png
|
106
|
+
- docs/autocanary_80_20.png
|
107
|
+
- docs/autocanary_drawio.xml
|
108
|
+
- docs/autocanary_none_100.png
|
101
109
|
- examples/.bundle/config
|
102
110
|
- examples/Gemfile
|
103
111
|
- examples/Gemfile.lock
|
@@ -125,9 +133,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
133
|
version: '0'
|
126
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
135
|
requirements:
|
128
|
-
- - "
|
136
|
+
- - ">="
|
129
137
|
- !ruby/object:Gem::Version
|
130
|
-
version:
|
138
|
+
version: '0'
|
131
139
|
requirements: []
|
132
140
|
rubyforge_project:
|
133
141
|
rubygems_version: 2.4.5.1
|