automan 2.1.2
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 +7 -0
- data/.gitignore +17 -0
- data/.rvmrc +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +29 -0
- data/Rakefile +6 -0
- data/automan.gemspec +30 -0
- data/bin/baker +4 -0
- data/bin/mover +4 -0
- data/bin/scanner +4 -0
- data/bin/snapper +4 -0
- data/bin/stacker +4 -0
- data/bin/stalker +4 -0
- data/lib/automan.rb +27 -0
- data/lib/automan/base.rb +64 -0
- data/lib/automan/beanstalk/application.rb +74 -0
- data/lib/automan/beanstalk/configuration.rb +137 -0
- data/lib/automan/beanstalk/deployer.rb +193 -0
- data/lib/automan/beanstalk/errors.rb +22 -0
- data/lib/automan/beanstalk/package.rb +39 -0
- data/lib/automan/beanstalk/router.rb +102 -0
- data/lib/automan/beanstalk/terminator.rb +60 -0
- data/lib/automan/beanstalk/uploader.rb +58 -0
- data/lib/automan/beanstalk/version.rb +100 -0
- data/lib/automan/chef/uploader.rb +30 -0
- data/lib/automan/cli/baker.rb +63 -0
- data/lib/automan/cli/base.rb +14 -0
- data/lib/automan/cli/mover.rb +47 -0
- data/lib/automan/cli/scanner.rb +24 -0
- data/lib/automan/cli/snapper.rb +78 -0
- data/lib/automan/cli/stacker.rb +106 -0
- data/lib/automan/cli/stalker.rb +279 -0
- data/lib/automan/cloudformation/errors.rb +40 -0
- data/lib/automan/cloudformation/launcher.rb +196 -0
- data/lib/automan/cloudformation/replacer.rb +102 -0
- data/lib/automan/cloudformation/terminator.rb +61 -0
- data/lib/automan/cloudformation/uploader.rb +57 -0
- data/lib/automan/ec2/errors.rb +4 -0
- data/lib/automan/ec2/image.rb +137 -0
- data/lib/automan/ec2/instance.rb +83 -0
- data/lib/automan/mixins/aws_caller.rb +115 -0
- data/lib/automan/mixins/utils.rb +18 -0
- data/lib/automan/rds/errors.rb +7 -0
- data/lib/automan/rds/snapshot.rb +244 -0
- data/lib/automan/s3/downloader.rb +25 -0
- data/lib/automan/s3/uploader.rb +20 -0
- data/lib/automan/version.rb +3 -0
- data/lib/automan/wait_rescuer.rb +17 -0
- data/spec/beanstalk/application_spec.rb +49 -0
- data/spec/beanstalk/configuration_spec.rb +98 -0
- data/spec/beanstalk/deployer_spec.rb +162 -0
- data/spec/beanstalk/package_spec.rb +9 -0
- data/spec/beanstalk/router_spec.rb +65 -0
- data/spec/beanstalk/terminator_spec.rb +67 -0
- data/spec/beanstalk/uploader_spec.rb +53 -0
- data/spec/beanstalk/version_spec.rb +60 -0
- data/spec/chef/uploader_spec.rb +9 -0
- data/spec/cloudformation/launcher_spec.rb +240 -0
- data/spec/cloudformation/replacer_spec.rb +58 -0
- data/spec/cloudformation/templates/worker_role.json +337 -0
- data/spec/cloudformation/terminator_spec.rb +63 -0
- data/spec/cloudformation/uploader_spec.rb +50 -0
- data/spec/ec2/image_spec.rb +158 -0
- data/spec/ec2/instance_spec.rb +57 -0
- data/spec/mixins/aws_caller_spec.rb +39 -0
- data/spec/mixins/utils_spec.rb +44 -0
- data/spec/rds/snapshot_spec.rb +152 -0
- metadata +278 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
require 'automan'
|
|
2
|
+
|
|
3
|
+
module Automan::Beanstalk
|
|
4
|
+
class Version < Automan::Base
|
|
5
|
+
add_option :application, :label
|
|
6
|
+
|
|
7
|
+
include Automan::Mixins::Utils
|
|
8
|
+
|
|
9
|
+
def versions
|
|
10
|
+
logger.info "listing versions for #{application}"
|
|
11
|
+
|
|
12
|
+
opts = {
|
|
13
|
+
application_name: application
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
response = eb.describe_application_versions opts
|
|
17
|
+
|
|
18
|
+
unless response.successful?
|
|
19
|
+
raise RequestFailedError "describe_application_versions failed: #{response.error}"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
response.data[:application_versions]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def exists?
|
|
26
|
+
versions.each do |v|
|
|
27
|
+
if v[:application_name] == application && v[:version_label] == label
|
|
28
|
+
return true
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
return false
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def create(package)
|
|
36
|
+
logger.info "creating version #{label}"
|
|
37
|
+
|
|
38
|
+
bucket, key = parse_s3_path(package)
|
|
39
|
+
opts = {
|
|
40
|
+
application_name: application,
|
|
41
|
+
version_label: label,
|
|
42
|
+
source_bundle: {
|
|
43
|
+
s3_bucket: bucket,
|
|
44
|
+
s3_key: key
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
response = eb.create_application_version opts
|
|
49
|
+
|
|
50
|
+
unless response.successful?
|
|
51
|
+
raise RequestFailedError, "create_application_version failed: #{response.error}"
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def delete_by_label(version_label)
|
|
56
|
+
logger.info "deleting version #{version_label} for application #{application}"
|
|
57
|
+
|
|
58
|
+
opts = {
|
|
59
|
+
application_name: application,
|
|
60
|
+
version_label: version_label,
|
|
61
|
+
delete_source_bundle: true
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
begin
|
|
65
|
+
response = eb.delete_application_version opts
|
|
66
|
+
unless response.successful?
|
|
67
|
+
raise RequestFailedError, "delete_application_version failed #{response.error}"
|
|
68
|
+
end
|
|
69
|
+
rescue AWS::ElasticBeanstalk::Errors::SourceBundleDeletionFailure => e
|
|
70
|
+
logger.warn e.message
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def delete
|
|
75
|
+
log_options
|
|
76
|
+
|
|
77
|
+
delete_by_label label
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def cull_versions(max_versions)
|
|
81
|
+
log_options
|
|
82
|
+
|
|
83
|
+
my_versions = versions
|
|
84
|
+
if my_versions.size <= max_versions
|
|
85
|
+
return
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
to_cull = my_versions.size - max_versions
|
|
89
|
+
logger.info "culling oldest #{to_cull} versions"
|
|
90
|
+
|
|
91
|
+
condemned = my_versions.sort_by {|v| v[:date_created] }[0..to_cull-1]
|
|
92
|
+
|
|
93
|
+
condemned.each do |i|
|
|
94
|
+
delete_by_label i[:version_label]
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'automan'
|
|
2
|
+
require 'zlib'
|
|
3
|
+
require 'archive/tar/minitar'
|
|
4
|
+
include Archive::Tar
|
|
5
|
+
|
|
6
|
+
module Automan::Chef
|
|
7
|
+
class Uploader < Automan::Base
|
|
8
|
+
add_option :repopath, :s3path, :chefver, :tempdir
|
|
9
|
+
|
|
10
|
+
def upload
|
|
11
|
+
log_options
|
|
12
|
+
|
|
13
|
+
logger.info "packaging #{repopath} to #{tempdir}"
|
|
14
|
+
tgz = Zlib::GzipWriter.new(File.open("#{tempdir}/chef-repo.tgz", 'wb'))
|
|
15
|
+
Minitar.pack(repopath, tgz)
|
|
16
|
+
|
|
17
|
+
versions = ["#{chefver}", "latest"]
|
|
18
|
+
versions.each do |version|
|
|
19
|
+
options = {
|
|
20
|
+
localfile: "#{tempdir}/chef-repo.tgz",
|
|
21
|
+
s3file: "#{s3path}/#{version}/chef-repo.tgz"
|
|
22
|
+
}
|
|
23
|
+
s = Automan::S3::Uploader.new options
|
|
24
|
+
s.upload
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require 'thor'
|
|
2
|
+
require 'automan'
|
|
3
|
+
|
|
4
|
+
module Automan::Cli
|
|
5
|
+
class Baker < Thor
|
|
6
|
+
def self.exit_on_failure?
|
|
7
|
+
return true
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
desc "create", "create an image"
|
|
11
|
+
|
|
12
|
+
option :instance,
|
|
13
|
+
aliases: "-i",
|
|
14
|
+
desc: "instance to image",
|
|
15
|
+
required: true
|
|
16
|
+
|
|
17
|
+
option :name,
|
|
18
|
+
aliases: "-n",
|
|
19
|
+
desc: "what to name the image",
|
|
20
|
+
required: true
|
|
21
|
+
|
|
22
|
+
option :prune,
|
|
23
|
+
aliases: "-p",
|
|
24
|
+
type: :boolean,
|
|
25
|
+
default: true,
|
|
26
|
+
desc: "delete AMIs older than 30 days"
|
|
27
|
+
|
|
28
|
+
def create
|
|
29
|
+
|
|
30
|
+
s = Automan::Ec2::Image.new(options)
|
|
31
|
+
s.create
|
|
32
|
+
s.prune_amis if options[:prune]
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
desc "upload", "upload a chef repo"
|
|
36
|
+
|
|
37
|
+
option :repopath,
|
|
38
|
+
aliases: "-r",
|
|
39
|
+
desc: "path to chef repo",
|
|
40
|
+
required: true
|
|
41
|
+
|
|
42
|
+
option :s3path,
|
|
43
|
+
aliases: "-s",
|
|
44
|
+
desc: "s3 path to chef artifacts",
|
|
45
|
+
required: true
|
|
46
|
+
|
|
47
|
+
option :chefver,
|
|
48
|
+
aliases: "-c",
|
|
49
|
+
desc: "chef version",
|
|
50
|
+
required: true
|
|
51
|
+
|
|
52
|
+
option :tempdir,
|
|
53
|
+
aliases: "-t",
|
|
54
|
+
desc: "temporary directory",
|
|
55
|
+
required: true
|
|
56
|
+
|
|
57
|
+
def upload
|
|
58
|
+
|
|
59
|
+
s = Automan::Chef::Uploader.new(options)
|
|
60
|
+
s.upload
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require 'thor'
|
|
2
|
+
require 'automan'
|
|
3
|
+
|
|
4
|
+
module Automan::Cli
|
|
5
|
+
class Mover < Thor
|
|
6
|
+
def self.exit_on_failure?
|
|
7
|
+
return true
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
desc "upload", "upload a file"
|
|
11
|
+
|
|
12
|
+
option :localfile,
|
|
13
|
+
aliases: "-l",
|
|
14
|
+
desc: "local file",
|
|
15
|
+
required: true
|
|
16
|
+
|
|
17
|
+
option :s3file,
|
|
18
|
+
aliases: "-s",
|
|
19
|
+
desc: "s3 file",
|
|
20
|
+
required: true
|
|
21
|
+
|
|
22
|
+
def upload
|
|
23
|
+
|
|
24
|
+
s = Automan::S3::Uploader.new(options)
|
|
25
|
+
s.upload
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
desc "download", "download a file"
|
|
29
|
+
|
|
30
|
+
option :localfile,
|
|
31
|
+
aliases: "-l",
|
|
32
|
+
desc: "local file",
|
|
33
|
+
required: true
|
|
34
|
+
|
|
35
|
+
option :s3file,
|
|
36
|
+
aliases: "-s",
|
|
37
|
+
desc: "s3 file",
|
|
38
|
+
required: true
|
|
39
|
+
|
|
40
|
+
def download
|
|
41
|
+
|
|
42
|
+
s = Automan::S3::Downloader.new(options)
|
|
43
|
+
s.download
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'automan'
|
|
2
|
+
|
|
3
|
+
module Automan::Cli
|
|
4
|
+
class Scanner < Base
|
|
5
|
+
|
|
6
|
+
desc "show-instances", "Show instance ips and passwords for an environment"
|
|
7
|
+
|
|
8
|
+
option :environment,
|
|
9
|
+
required: true,
|
|
10
|
+
aliases: "-e",
|
|
11
|
+
default: "dev1",
|
|
12
|
+
desc: "Show instances from this environment"
|
|
13
|
+
|
|
14
|
+
option :private_key_file,
|
|
15
|
+
required: true,
|
|
16
|
+
aliases: "-p",
|
|
17
|
+
desc: "Path to private key to use when decrypting windows password"
|
|
18
|
+
|
|
19
|
+
def show_instances
|
|
20
|
+
i = Automan::Ec2::Instance.new(options)
|
|
21
|
+
i.show_env
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
require 'automan'
|
|
2
|
+
require 'time'
|
|
3
|
+
|
|
4
|
+
module Automan::Cli
|
|
5
|
+
class Snapper < Base
|
|
6
|
+
|
|
7
|
+
desc "create", "create a snapshot"
|
|
8
|
+
|
|
9
|
+
option :environment,
|
|
10
|
+
aliases: "-e",
|
|
11
|
+
desc: "environment of database to snapshot"
|
|
12
|
+
|
|
13
|
+
option :database,
|
|
14
|
+
aliases: "-d",
|
|
15
|
+
desc: "name of the database to snapshot"
|
|
16
|
+
|
|
17
|
+
option :name,
|
|
18
|
+
aliases: "-n",
|
|
19
|
+
desc: "what to name the snapshot"
|
|
20
|
+
|
|
21
|
+
option :prune,
|
|
22
|
+
aliases: "-p",
|
|
23
|
+
type: :boolean,
|
|
24
|
+
default: true,
|
|
25
|
+
desc: "make this snapshot prunable and delete other prunable snapshots older than 30 days"
|
|
26
|
+
|
|
27
|
+
option :wait_for_completion,
|
|
28
|
+
aliases: "-w",
|
|
29
|
+
type: :boolean,
|
|
30
|
+
default: false,
|
|
31
|
+
desc: "wait until snapshot is finished before exiting script"
|
|
32
|
+
|
|
33
|
+
def create
|
|
34
|
+
if options[:database].nil? && options[:environment].nil?
|
|
35
|
+
puts "Must specify either database or environment"
|
|
36
|
+
help "create"
|
|
37
|
+
exit 1
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
s = Automan::RDS::Snapshot.new(options)
|
|
41
|
+
s.log_aws_calls = true
|
|
42
|
+
s.prune_snapshots if options[:prune]
|
|
43
|
+
s.create
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
desc "delete", "delete a snapshot"
|
|
47
|
+
|
|
48
|
+
option :name,
|
|
49
|
+
required: true,
|
|
50
|
+
aliases: "-n",
|
|
51
|
+
desc: "name of snapshot to delete"
|
|
52
|
+
|
|
53
|
+
def delete
|
|
54
|
+
Automan::RDS::Snapshot.new(options).delete
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
desc "latest", "find the most recent snapshot"
|
|
58
|
+
|
|
59
|
+
option :database,
|
|
60
|
+
aliases: "-d",
|
|
61
|
+
desc: "name of the database to snapshot"
|
|
62
|
+
|
|
63
|
+
option :environment,
|
|
64
|
+
aliases: "-e",
|
|
65
|
+
desc: "environment of database to snapshot"
|
|
66
|
+
|
|
67
|
+
def latest
|
|
68
|
+
if options[:database].nil? && options[:environment].nil?
|
|
69
|
+
puts "Must specify either database or environment"
|
|
70
|
+
help "latest"
|
|
71
|
+
exit 1
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
Automan::RDS::Snapshot.new(options).latest
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
require 'automan'
|
|
2
|
+
require 'json'
|
|
3
|
+
|
|
4
|
+
module Automan::Cli
|
|
5
|
+
class Stacker < Base
|
|
6
|
+
|
|
7
|
+
desc "launch", "launches a cloudformation stack"
|
|
8
|
+
|
|
9
|
+
option :name,
|
|
10
|
+
required: true,
|
|
11
|
+
aliases: "-n",
|
|
12
|
+
desc: "name of the stack"
|
|
13
|
+
|
|
14
|
+
option :template,
|
|
15
|
+
required: true,
|
|
16
|
+
aliases: "-t",
|
|
17
|
+
desc: "path to template file (s3://bucket/template or local file)"
|
|
18
|
+
|
|
19
|
+
option :disable_rollback,
|
|
20
|
+
type: :boolean,
|
|
21
|
+
default: false,
|
|
22
|
+
desc: "set to true to disable rollback of failed stacks"
|
|
23
|
+
|
|
24
|
+
option :enable_update,
|
|
25
|
+
type: :boolean,
|
|
26
|
+
default: false,
|
|
27
|
+
desc: "set to true to update existing stack"
|
|
28
|
+
|
|
29
|
+
option :manifest,
|
|
30
|
+
aliases: "-m",
|
|
31
|
+
desc: "s3 path to manifest file containing version and package location"
|
|
32
|
+
|
|
33
|
+
option :parameters,
|
|
34
|
+
type: :hash,
|
|
35
|
+
default: {},
|
|
36
|
+
aliases: "-p",
|
|
37
|
+
desc: "stack parameters (e.g. -p Environment:dev InstanceType:m1.small)"
|
|
38
|
+
|
|
39
|
+
option :wait_for_completion,
|
|
40
|
+
aliases: "-w",
|
|
41
|
+
type: :boolean,
|
|
42
|
+
default: false,
|
|
43
|
+
desc: "wait until stack launches/updates before exiting script"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def launch
|
|
47
|
+
Automan::Cloudformation::Launcher.new(options).launch_or_update
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
desc "terminate", "terminate stack"
|
|
51
|
+
|
|
52
|
+
option :name,
|
|
53
|
+
required: true,
|
|
54
|
+
aliases: "-n",
|
|
55
|
+
desc: "name of the stack"
|
|
56
|
+
|
|
57
|
+
option :wait_for_completion,
|
|
58
|
+
aliases: "-w",
|
|
59
|
+
type: :boolean,
|
|
60
|
+
default: false,
|
|
61
|
+
desc: "wait until stack terminates before exiting script"
|
|
62
|
+
|
|
63
|
+
def terminate
|
|
64
|
+
Automan::Cloudformation::Terminator.new(options).terminate
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
desc "replace-instances", "terminate and replace running asg instances"
|
|
68
|
+
|
|
69
|
+
option :name,
|
|
70
|
+
required: true,
|
|
71
|
+
aliases: "-n",
|
|
72
|
+
desc: "name of the stack"
|
|
73
|
+
|
|
74
|
+
def replace_instances
|
|
75
|
+
Automan::Cloudformation::Replacer.new(options).replace_instances
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
desc "upload-templates", "validate and upload cloudformation templates"
|
|
79
|
+
|
|
80
|
+
option :template_files,
|
|
81
|
+
required: true,
|
|
82
|
+
aliases: "-t",
|
|
83
|
+
desc: "single or globbed templates"
|
|
84
|
+
|
|
85
|
+
option :s3_path,
|
|
86
|
+
required: true,
|
|
87
|
+
aliases: "-p",
|
|
88
|
+
desc: "s3 path to folder to drop the templates"
|
|
89
|
+
|
|
90
|
+
def upload_templates
|
|
91
|
+
Automan::Cloudformation::Uploader.new(options).upload_templates
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
desc "params", "print output from validate_template"
|
|
95
|
+
|
|
96
|
+
option :template,
|
|
97
|
+
required: true,
|
|
98
|
+
aliases: "-t",
|
|
99
|
+
desc: "path to template file (s3://bucket/template or local file)"
|
|
100
|
+
|
|
101
|
+
def params
|
|
102
|
+
h = Automan::Cloudformation::Launcher.new(options).parse_template_parameters
|
|
103
|
+
say JSON.pretty_generate h
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|