automan 2.3.5 → 2.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +0 -5
- data/automan.gemspec +3 -3
- data/lib/automan.rb +0 -1
- data/lib/automan/base.rb +3 -7
- data/lib/automan/beanstalk/deployer.rb +1 -1
- data/lib/automan/beanstalk/package.rb +1 -1
- data/lib/automan/beanstalk/router.rb +1 -1
- data/lib/automan/cli/snapper.rb +23 -3
- data/lib/automan/cli/stacker.rb +0 -19
- data/lib/automan/cloudformation/launcher.rb +3 -6
- data/lib/automan/cloudformation/replacer.rb +1 -1
- data/lib/automan/cloudformation/terminator.rb +1 -1
- data/lib/automan/ec2/image.rb +3 -3
- data/lib/automan/mixins/aws_caller.rb +7 -21
- data/lib/automan/rds/snapshot.rb +25 -35
- data/lib/automan/s3/downloader.rb +1 -10
- data/lib/automan/version.rb +1 -1
- data/spec/beanstalk/application_spec.rb +17 -17
- data/spec/beanstalk/configuration_spec.rb +24 -24
- data/spec/beanstalk/deployer_spec.rb +65 -65
- data/spec/beanstalk/router_spec.rb +19 -18
- data/spec/beanstalk/terminator_spec.rb +16 -16
- data/spec/beanstalk/uploader_spec.rb +13 -13
- data/spec/beanstalk/version_spec.rb +10 -8
- data/spec/cloudformation/launcher_spec.rb +65 -63
- data/spec/cloudformation/replacer_spec.rb +10 -10
- data/spec/cloudformation/terminator_spec.rb +23 -23
- data/spec/cloudformation/uploader_spec.rb +13 -13
- data/spec/ec2/image_spec.rb +55 -55
- data/spec/ec2/instance_spec.rb +17 -17
- data/spec/mixins/aws_caller_spec.rb +9 -9
- data/spec/mixins/utils_spec.rb +28 -27
- data/spec/rds/snapshot_spec.rb +46 -44
- metadata +9 -22
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/.travis.yml +0 -5
- data/lib/automan/elasticache/router.rb +0 -79
- data/spec/elasticache/router_spec.rb +0 -29
- data/templates/stacker/.env.example +0 -14
- data/templates/stacker/.gitignore +0 -2
- data/templates/stacker/.ruby-gemset.tt +0 -1
- data/templates/stacker/.ruby-version +0 -1
- data/templates/stacker/Gemfile +0 -4
- data/templates/stacker/bin/%app_name%.tt +0 -62
- data/templates/stacker/bin/launch_%app_name%.sh.tt +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba8bf0ad1d6385060e00b45ab199391f2520c179
|
4
|
+
data.tar.gz: 54e997202865573a99b4b21005869e79a3374977
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af5c94a4677e630eca5ef7e9d2d4fb47b306b7e7dec0ffaa23246f57009855947b6df6378b31748cb671a7110ed1051b7bbd1b76ac6be857e6f2675f38755713
|
7
|
+
data.tar.gz: a5ca5a4b040037645bd92541bc4e3c1c6800ca6faa3539b28f6cdd7854b192f2c7159a91a3afc39f62eaac25d37f5f52c450c7d45a700a3152f51e1c58362b91
|
data/Rakefile
CHANGED
data/automan.gemspec
CHANGED
@@ -19,9 +19,9 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.add_development_dependency "bundler", "~> 1.3"
|
21
21
|
spec.add_development_dependency "rake"
|
22
|
-
spec.add_development_dependency "rspec-core", "~>
|
23
|
-
spec.add_development_dependency "rspec-mocks", "~>
|
24
|
-
spec.add_development_dependency "rspec-expectations", "~>
|
22
|
+
spec.add_development_dependency "rspec-core", "~> 2.12.2"
|
23
|
+
spec.add_development_dependency "rspec-mocks", "~> 2.12.2"
|
24
|
+
spec.add_development_dependency "rspec-expectations", "~> 2.12.1"
|
25
25
|
spec.add_dependency "aws-sdk", "< 2.0"
|
26
26
|
spec.add_dependency "thor"
|
27
27
|
spec.add_dependency "json"
|
data/lib/automan.rb
CHANGED
@@ -19,7 +19,6 @@ require 'automan/cloudformation/terminator'
|
|
19
19
|
require 'automan/cloudformation/replacer'
|
20
20
|
require 'automan/cloudformation/uploader'
|
21
21
|
require 'automan/cloudformation/errors'
|
22
|
-
require 'automan/elasticache/router'
|
23
22
|
require 'automan/rds/snapshot'
|
24
23
|
require 'automan/rds/errors'
|
25
24
|
require 'automan/ec2/instance'
|
data/lib/automan/base.rb
CHANGED
@@ -12,9 +12,11 @@ module Automan
|
|
12
12
|
|
13
13
|
include Automan::Mixins::AwsCaller
|
14
14
|
|
15
|
-
def initialize(options=
|
15
|
+
def initialize(options=nil)
|
16
16
|
$stdout.sync = true
|
17
17
|
@logger = Logger.new(STDOUT)
|
18
|
+
@log_aws_calls = false
|
19
|
+
#@wait = Wait.new(rescuer: WaitRescuer.new, logger: @logger)
|
18
20
|
|
19
21
|
if !options.nil?
|
20
22
|
options.each_pair do |k,v|
|
@@ -22,12 +24,6 @@ module Automan
|
|
22
24
|
send(accessor, v) if respond_to? accessor
|
23
25
|
end
|
24
26
|
end
|
25
|
-
|
26
|
-
aws_options = {}
|
27
|
-
if options[:log_aws]
|
28
|
-
aws_options[:logger] = @logger
|
29
|
-
end
|
30
|
-
configure_aws(aws_options)
|
31
27
|
end
|
32
28
|
|
33
29
|
def self.add_option(*args)
|
@@ -13,7 +13,7 @@ module Automan::Beanstalk
|
|
13
13
|
|
14
14
|
# verify local package exists
|
15
15
|
unless File.exists? source
|
16
|
-
raise
|
16
|
+
raise MissingPackageFile, "package file #{source} does not exist"
|
17
17
|
end
|
18
18
|
|
19
19
|
logger.info "Uploading #{source} to #{destination}"
|
data/lib/automan/cli/snapper.rb
CHANGED
@@ -37,9 +37,8 @@ module Automan::Cli
|
|
37
37
|
exit 1
|
38
38
|
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
s = Automan::RDS::Snapshot.new(aws_opts)
|
40
|
+
s = Automan::RDS::Snapshot.new(options)
|
41
|
+
s.log_aws_calls = true
|
43
42
|
s.prune_snapshots if options[:prune]
|
44
43
|
s.create
|
45
44
|
end
|
@@ -75,5 +74,26 @@ module Automan::Cli
|
|
75
74
|
Automan::RDS::Snapshot.new(options).latest
|
76
75
|
end
|
77
76
|
|
77
|
+
desc "count", "return the number of snapshots"
|
78
|
+
|
79
|
+
option :environment,
|
80
|
+
aliases: "-e",
|
81
|
+
desc: "environment of database to snapshot"
|
82
|
+
|
83
|
+
option :database,
|
84
|
+
aliases: "-d",
|
85
|
+
desc: "name of the database to snapshot"
|
86
|
+
|
87
|
+
def count
|
88
|
+
|
89
|
+
if options[:database].nil? && options[:environment].nil?
|
90
|
+
puts "Must specify either database or environment"
|
91
|
+
help "count"
|
92
|
+
exit 1
|
93
|
+
end
|
94
|
+
|
95
|
+
Automan::RDS::Snapshot.new(options).count_snapshots
|
96
|
+
end
|
97
|
+
|
78
98
|
end
|
79
99
|
end
|
data/lib/automan/cli/stacker.rb
CHANGED
@@ -102,24 +102,5 @@ module Automan::Cli
|
|
102
102
|
h = Automan::Cloudformation::Launcher.new(options).parse_template_parameters
|
103
103
|
say JSON.pretty_generate h
|
104
104
|
end
|
105
|
-
|
106
|
-
include Thor::Actions
|
107
|
-
def self.source_root
|
108
|
-
File.join(File.dirname(__FILE__),'..','..', '..')
|
109
|
-
end
|
110
|
-
|
111
|
-
desc "project APP_NAME", "create stacker project"
|
112
|
-
|
113
|
-
attr_reader :app_name
|
114
|
-
|
115
|
-
def project(app_name)
|
116
|
-
@app_name = app_name
|
117
|
-
|
118
|
-
say "\nCreating stacker project: #{app_name}\n", :yellow
|
119
|
-
directory 'templates/stacker', app_name
|
120
|
-
[app_name, "launch_#{app_name}.sh"].each do |file|
|
121
|
-
chmod File.join(app_name, 'bin', file), 0755
|
122
|
-
end
|
123
|
-
end
|
124
105
|
end
|
125
106
|
end
|
@@ -16,7 +16,7 @@ module Automan::Cloudformation
|
|
16
16
|
|
17
17
|
include Automan::Mixins::Utils
|
18
18
|
|
19
|
-
def initialize(options=
|
19
|
+
def initialize(options=nil)
|
20
20
|
@wait_for_completion = false
|
21
21
|
super
|
22
22
|
@wait = Wait.new({
|
@@ -148,8 +148,6 @@ module Automan::Cloudformation
|
|
148
148
|
|
149
149
|
logger.info "updating stack #{name}"
|
150
150
|
|
151
|
-
no_updates_needed = false
|
152
|
-
|
153
151
|
# if cfn determines that no updates are to be performed,
|
154
152
|
# it raises a ValidationError
|
155
153
|
begin
|
@@ -159,11 +157,10 @@ module Automan::Cloudformation
|
|
159
157
|
raise e
|
160
158
|
else
|
161
159
|
logger.info e.message
|
162
|
-
no_updates_needed = true
|
163
160
|
end
|
164
161
|
end
|
165
162
|
|
166
|
-
if
|
163
|
+
if wait_for_completion
|
167
164
|
logger.info "waiting for stack #{name} to update"
|
168
165
|
wait_until { stack_update_complete? }
|
169
166
|
end
|
@@ -196,4 +193,4 @@ module Automan::Cloudformation
|
|
196
193
|
end
|
197
194
|
end
|
198
195
|
|
199
|
-
end
|
196
|
+
end
|
data/lib/automan/ec2/image.rb
CHANGED
@@ -7,7 +7,7 @@ module Automan::Ec2
|
|
7
7
|
|
8
8
|
include Automan::Mixins::Utils
|
9
9
|
|
10
|
-
def initialize(options=
|
10
|
+
def initialize(options=nil)
|
11
11
|
super
|
12
12
|
@wait = Wait.new({
|
13
13
|
delay: 5,
|
@@ -45,7 +45,7 @@ module Automan::Ec2
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def default_image_name
|
48
|
-
stime = Time.
|
48
|
+
stime = Time.new.iso8601.gsub(/:/, '-')
|
49
49
|
return name + "-" + stime
|
50
50
|
end
|
51
51
|
|
@@ -134,4 +134,4 @@ module Automan::Ec2
|
|
134
134
|
end
|
135
135
|
|
136
136
|
end
|
137
|
-
end
|
137
|
+
end
|
@@ -8,20 +8,14 @@ module Automan
|
|
8
8
|
ENV['AWS_ACCOUNT_ID']
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
sts: sts,
|
18
|
-
role_arn: ENV['AWS_ROLE'],
|
19
|
-
role_session_name: "automan-aws-sdk"
|
20
|
-
)
|
21
|
-
options[:credential_provider] = provider
|
11
|
+
attr_reader :log_aws_calls
|
12
|
+
def log_aws_calls=(value)
|
13
|
+
if value == true
|
14
|
+
AWS.config(logger: @logger)
|
15
|
+
else
|
16
|
+
AWS.config(logger: nil)
|
22
17
|
end
|
23
|
-
|
24
|
-
AWS.config(options)
|
18
|
+
@log_aws_calls = value
|
25
19
|
end
|
26
20
|
|
27
21
|
attr_writer :eb
|
@@ -108,14 +102,6 @@ module Automan
|
|
108
102
|
@rds
|
109
103
|
end
|
110
104
|
|
111
|
-
attr_writer :ec
|
112
|
-
def ec
|
113
|
-
if @ec.nil?
|
114
|
-
@ec = AWS::ElastiCache.new
|
115
|
-
end
|
116
|
-
@ec
|
117
|
-
end
|
118
|
-
|
119
105
|
attr_writer :ec2
|
120
106
|
def ec2
|
121
107
|
if @ec2.nil?
|
data/lib/automan/rds/snapshot.rb
CHANGED
@@ -12,7 +12,7 @@ module Automan::RDS
|
|
12
12
|
|
13
13
|
attr_accessor :max_snapshots
|
14
14
|
|
15
|
-
def initialize(options=
|
15
|
+
def initialize(options=nil)
|
16
16
|
@prune = true
|
17
17
|
@wait_for_completion = false
|
18
18
|
super
|
@@ -33,8 +33,6 @@ module Automan::RDS
|
|
33
33
|
|
34
34
|
include Automan::Mixins::Utils
|
35
35
|
|
36
|
-
# TODO move this and dependecies to an RDS utils class
|
37
|
-
# so we can re-use it
|
38
36
|
def find_db
|
39
37
|
db = nil
|
40
38
|
if !database.nil?
|
@@ -65,9 +63,7 @@ module Automan::RDS
|
|
65
63
|
end
|
66
64
|
|
67
65
|
def snapshot_count
|
68
|
-
|
69
|
-
rds.db_instances[database].snapshots.count
|
70
|
-
end
|
66
|
+
rds.db_instances[find_db.id].snapshots.count
|
71
67
|
end
|
72
68
|
|
73
69
|
def create
|
@@ -97,8 +93,8 @@ module Automan::RDS
|
|
97
93
|
snap = db.create_snapshot(myname)
|
98
94
|
|
99
95
|
if prune == true
|
100
|
-
logger.info "Setting snapshot to be prunable
|
101
|
-
|
96
|
+
logger.info "Setting snapshot to be prunable"
|
97
|
+
set_prunable(snap)
|
102
98
|
end
|
103
99
|
|
104
100
|
if wait_for_completion == true
|
@@ -124,7 +120,7 @@ module Automan::RDS
|
|
124
120
|
|
125
121
|
def default_snapshot_name(db)
|
126
122
|
env = db_environment db
|
127
|
-
stime = Time.new.
|
123
|
+
stime = Time.new.iso8601.gsub(/:/,'-')
|
128
124
|
|
129
125
|
return env + "-" + stime
|
130
126
|
end
|
@@ -149,10 +145,10 @@ module Automan::RDS
|
|
149
145
|
end
|
150
146
|
|
151
147
|
# tag with CanPrune
|
152
|
-
def
|
148
|
+
def set_prunable(snapshot)
|
153
149
|
opts = {
|
154
150
|
resource_name: snapshot_arn(snapshot),
|
155
|
-
tags: [ {key: 'CanPrune', value: 'yes'}
|
151
|
+
tags: [ {key: 'CanPrune', value: 'yes'} ]
|
156
152
|
}
|
157
153
|
response = rds.client.add_tags_to_resource opts
|
158
154
|
|
@@ -189,15 +185,6 @@ module Automan::RDS
|
|
189
185
|
tagged_can_prune?(snapshot) && available?(snapshot) && manual?(snapshot)
|
190
186
|
end
|
191
187
|
|
192
|
-
def is_env?(snapshot,environment)
|
193
|
-
tagged_env?(snapshot,environment) && available?(snapshot) && manual?(snapshot)
|
194
|
-
end
|
195
|
-
|
196
|
-
def tagged_env?(snapshot,environment)
|
197
|
-
arn = snapshot_arn(snapshot)
|
198
|
-
tags(arn)['Environment'] == environment
|
199
|
-
end
|
200
|
-
|
201
188
|
def tagged_can_prune?(snapshot)
|
202
189
|
arn = snapshot_arn(snapshot)
|
203
190
|
tags(arn)['CanPrune'] == 'yes'
|
@@ -217,12 +204,14 @@ module Automan::RDS
|
|
217
204
|
end
|
218
205
|
|
219
206
|
def get_all_snapshots
|
220
|
-
rds.
|
207
|
+
rds.db_instances[find_db.id].snapshots
|
221
208
|
end
|
222
209
|
|
223
210
|
def prunable_snapshots
|
224
|
-
|
225
|
-
|
211
|
+
AWS.memoize do
|
212
|
+
snapshots = get_all_snapshots
|
213
|
+
snapshots.select { |s| can_prune?(s) }
|
214
|
+
end
|
226
215
|
end
|
227
216
|
|
228
217
|
def oldest_prunable_snapshot
|
@@ -246,22 +235,23 @@ module Automan::RDS
|
|
246
235
|
end
|
247
236
|
end
|
248
237
|
|
249
|
-
def
|
238
|
+
def count_snapshots
|
250
239
|
log_options
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
if is_env?(onesnap,environment)
|
258
|
-
envsnaps.push(onesnap)
|
259
|
-
end
|
240
|
+
db = find_db
|
241
|
+
if db.nil?
|
242
|
+
logger.info "Database not found"
|
243
|
+
else
|
244
|
+
logger.info "Number of snapshots for database #{db.id} is #{snapshot_count}"
|
245
|
+
logger.info "Number of prunable snapshots for database #{db.id} is #{prunable_snapshots.count}"
|
260
246
|
end
|
247
|
+
end
|
261
248
|
|
262
|
-
|
249
|
+
def latest
|
250
|
+
log_options
|
251
|
+
db = find_db
|
252
|
+
logger.info "Finding most recent snapshot for #{db.id}"
|
253
|
+
s = db.snapshots.sort_by {|i| i.created_at }.last
|
263
254
|
logger.info "Most recent snapshot is #{s.id}"
|
264
|
-
s.id
|
265
255
|
end
|
266
256
|
end
|
267
257
|
end
|
@@ -9,7 +9,7 @@ module Automan::S3
|
|
9
9
|
def download
|
10
10
|
log_options
|
11
11
|
|
12
|
-
logger.info "
|
12
|
+
logger.info "uploading #{localfile} to #{s3file}"
|
13
13
|
|
14
14
|
bucket, key = parse_s3_path s3file
|
15
15
|
|
@@ -18,16 +18,7 @@ module Automan::S3
|
|
18
18
|
file.write(chunk)
|
19
19
|
end
|
20
20
|
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def read
|
24
|
-
log_options
|
25
|
-
|
26
|
-
logger.info "returning contents of #{s3file} as string"
|
27
|
-
|
28
|
-
bucket, key = parse_s3_path s3file
|
29
21
|
|
30
|
-
s3.buckets[bucket].objects[key].read
|
31
22
|
end
|
32
23
|
|
33
24
|
end
|
data/lib/automan/version.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require "automan"
|
2
2
|
|
3
3
|
describe Automan::Beanstalk::Application do
|
4
|
-
it {
|
5
|
-
it {
|
6
|
-
it {
|
4
|
+
it { should respond_to :name }
|
5
|
+
it { should respond_to :create }
|
6
|
+
it { should respond_to :delete }
|
7
7
|
|
8
8
|
describe '#create' do
|
9
|
-
subject() do
|
9
|
+
subject(:a) do
|
10
10
|
AWS.stub!
|
11
11
|
a = Automan::Beanstalk::Application.new
|
12
12
|
a.logger = Logger.new('/dev/null')
|
@@ -14,20 +14,20 @@ describe Automan::Beanstalk::Application do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it "does not create if the application already exists" do
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
a.stub(:application_exists?).and_return(true)
|
18
|
+
a.should_not_receive(:create_application)
|
19
|
+
a.create
|
20
20
|
end
|
21
21
|
|
22
22
|
it "does create if the application doesn't exist" do
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
a.stub(:application_exists?).and_return(false)
|
24
|
+
a.should_receive(:create_application)
|
25
|
+
a.create
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
describe '#delete' do
|
30
|
-
subject() do
|
30
|
+
subject(:a) do
|
31
31
|
AWS.stub!
|
32
32
|
a = Automan::Beanstalk::Application.new
|
33
33
|
a.logger = Logger.new('/dev/null')
|
@@ -35,15 +35,15 @@ describe Automan::Beanstalk::Application do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it "does delete if the application already exists" do
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
a.stub(:application_exists?).and_return(true)
|
39
|
+
a.should_receive(:delete_application)
|
40
|
+
a.delete
|
41
41
|
end
|
42
42
|
|
43
43
|
it "does not delete if the application doesn't exist" do
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
a.stub(:application_exists?).and_return(false)
|
45
|
+
a.should_not_receive(:delete_application)
|
46
|
+
a.delete
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|