comodule 0.0.4 → 0.1.0
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 +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +0 -2
- data/README.md +115 -43
- data/comodule.gemspec +4 -2
- data/copy_to_rails.sh +7 -0
- data/lib/comodule.rb +32 -2
- data/lib/comodule/config_support.rb +95 -18
- data/lib/comodule/deployment.rb +2 -0
- data/lib/comodule/deployment/base.rb +186 -0
- data/lib/comodule/deployment/helper.rb +9 -0
- data/lib/comodule/deployment/helper/aws.rb +96 -0
- data/lib/comodule/deployment/helper/aws/base.rb +14 -0
- data/lib/comodule/deployment/helper/aws/cloud_formation.rb +146 -0
- data/lib/comodule/deployment/helper/aws/ec2.rb +37 -0
- data/lib/comodule/deployment/helper/aws/rds.rb +46 -0
- data/lib/comodule/deployment/helper/aws/s3.rb +52 -0
- data/lib/comodule/deployment/helper/aws/ssl.rb +111 -0
- data/lib/comodule/deployment/helper/base.rb +18 -0
- data/lib/comodule/deployment/helper/shell_command.rb +76 -0
- data/lib/comodule/deployment/helper/system_utility.rb +80 -0
- data/lib/comodule/deployment/helper/uploader.rb +155 -0
- data/lib/comodule/deployment/platform.rb +156 -0
- data/lib/comodule/deployment/platform/default_files/.gitignore.erb +5 -0
- data/lib/comodule/deployment/platform/default_files/aws_config.yml.erb +2 -0
- data/lib/comodule/version.rb +1 -1
- data/lib/tasks/comodule.rake +94 -0
- data/spec/comodule/config_support_spec.rb +102 -0
- data/spec/comodule/deployment/helper/aws/cloud_formation_spec.rb +71 -0
- data/spec/comodule/deployment/helper/aws/s3_spec.rb +85 -0
- data/spec/comodule/deployment/helper/shell_command_spec.rb +176 -0
- data/spec/comodule/deployment/helper/system_utility_spec.rb +250 -0
- data/spec/comodule/deployment/helper/uploader_spec.rb +274 -0
- data/spec/comodule/deployment/platform_spec.rb +310 -0
- data/spec/comodule_spec.rb +1 -1
- data/spec/rails/experiment/.gitignore +16 -0
- data/spec/rails/experiment/Gemfile +43 -0
- data/spec/rails/experiment/README.rdoc +28 -0
- data/spec/rails/experiment/Rakefile +6 -0
- data/spec/rails/experiment/app/assets/images/.keep +0 -0
- data/spec/rails/experiment/app/assets/javascripts/application.js +16 -0
- data/spec/rails/experiment/app/assets/javascripts/experiences.js.coffee +3 -0
- data/spec/rails/experiment/app/assets/stylesheets/application.css +15 -0
- data/spec/rails/experiment/app/assets/stylesheets/experiences.css.scss +3 -0
- data/spec/rails/experiment/app/assets/stylesheets/scaffolds.css.scss +69 -0
- data/spec/rails/experiment/app/controllers/application_controller.rb +5 -0
- data/spec/rails/experiment/app/controllers/concerns/.keep +0 -0
- data/spec/rails/experiment/app/controllers/experiences_controller.rb +74 -0
- data/spec/rails/experiment/app/helpers/application_helper.rb +2 -0
- data/spec/rails/experiment/app/helpers/experiences_helper.rb +2 -0
- data/spec/rails/experiment/app/mailers/.keep +0 -0
- data/spec/rails/experiment/app/models/.keep +0 -0
- data/spec/rails/experiment/app/models/concerns/.keep +0 -0
- data/spec/rails/experiment/app/models/experience.rb +2 -0
- data/spec/rails/experiment/app/views/experiences/_form.html.slim +12 -0
- data/spec/rails/experiment/app/views/experiences/edit.html.slim +8 -0
- data/spec/rails/experiment/app/views/experiences/index.html.slim +21 -0
- data/spec/rails/experiment/app/views/experiences/index.json.jbuilder +4 -0
- data/spec/rails/experiment/app/views/experiences/new.html.slim +5 -0
- data/spec/rails/experiment/app/views/experiences/show.html.slim +9 -0
- data/spec/rails/experiment/app/views/experiences/show.json.jbuilder +1 -0
- data/spec/rails/experiment/app/views/layouts/application.html.erb +14 -0
- data/spec/rails/experiment/bin/bundle +3 -0
- data/spec/rails/experiment/bin/rails +8 -0
- data/spec/rails/experiment/bin/rake +8 -0
- data/spec/rails/experiment/bin/spring +18 -0
- data/spec/rails/experiment/config.ru +4 -0
- data/spec/rails/experiment/config/application.rb +23 -0
- data/spec/rails/experiment/config/boot.rb +4 -0
- data/spec/rails/experiment/config/database.yml +25 -0
- data/spec/rails/experiment/config/environment.rb +5 -0
- data/spec/rails/experiment/config/environments/development.rb +37 -0
- data/spec/rails/experiment/config/environments/production.rb +78 -0
- data/spec/rails/experiment/config/environments/test.rb +39 -0
- data/spec/rails/experiment/config/experiment_unicorn.rb +104 -0
- data/spec/rails/experiment/config/initializers/assets.rb +8 -0
- data/spec/rails/experiment/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails/experiment/config/initializers/cookies_serializer.rb +3 -0
- data/spec/rails/experiment/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/rails/experiment/config/initializers/inflections.rb +16 -0
- data/spec/rails/experiment/config/initializers/mime_types.rb +4 -0
- data/spec/rails/experiment/config/initializers/session_store.rb +3 -0
- data/spec/rails/experiment/config/initializers/wrap_parameters.rb +14 -0
- data/spec/rails/experiment/config/locales/en.yml +23 -0
- data/spec/rails/experiment/config/routes.rb +59 -0
- data/spec/rails/experiment/config/secrets.yml +22 -0
- data/spec/rails/experiment/db/migrate/20141004050218_create_experiences.rb +9 -0
- data/spec/rails/experiment/db/schema.rb +22 -0
- data/spec/rails/experiment/db/seeds.rb +7 -0
- data/spec/rails/experiment/lib/assets/.keep +0 -0
- data/spec/rails/experiment/lib/tasks/.keep +0 -0
- data/spec/rails/experiment/log/.keep +0 -0
- data/spec/rails/experiment/platform/.gitignore +5 -0
- data/spec/rails/experiment/platform/ami/cloud_formation/.keep +0 -0
- data/spec/rails/experiment/platform/ami/cloud_formation/template.json.erb +138 -0
- data/spec/rails/experiment/platform/ami/config.yml +5 -0
- data/spec/rails/experiment/platform/ami/config/.keep +0 -0
- data/spec/rails/experiment/platform/cloud_formation/.keep +0 -0
- data/spec/rails/experiment/platform/config.yml +18 -0
- data/spec/rails/experiment/platform/config/.keep +0 -0
- data/spec/rails/experiment/platform/config/nginx/conf.d/default.conf.erb +46 -0
- data/spec/rails/experiment/platform/config/nginx/nginx.conf.erb +53 -0
- data/spec/rails/experiment/platform/deployment/cloud_formation/.keep +0 -0
- data/spec/rails/experiment/platform/deployment/cloud_formation/template.json.erb +107 -0
- data/spec/rails/experiment/platform/deployment/config.yml +16 -0
- data/spec/rails/experiment/platform/deployment/config/.keep +0 -0
- data/spec/rails/experiment/public/404.html +67 -0
- data/spec/rails/experiment/public/422.html +67 -0
- data/spec/rails/experiment/public/500.html +66 -0
- data/spec/rails/experiment/public/favicon.ico +0 -0
- data/spec/rails/experiment/public/robots.txt +5 -0
- data/spec/rails/experiment/test/controllers/.keep +0 -0
- data/spec/rails/experiment/test/controllers/experiences_controller_test.rb +49 -0
- data/spec/rails/experiment/test/fixtures/.keep +0 -0
- data/spec/rails/experiment/test/fixtures/experiences.yml +7 -0
- data/spec/rails/experiment/test/helpers/.keep +0 -0
- data/spec/rails/experiment/test/helpers/experiences_helper_test.rb +4 -0
- data/spec/rails/experiment/test/integration/.keep +0 -0
- data/spec/rails/experiment/test/mailers/.keep +0 -0
- data/spec/rails/experiment/test/models/.keep +0 -0
- data/spec/rails/experiment/test/models/experience_test.rb +7 -0
- data/spec/rails/experiment/test/test_helper.rb +10 -0
- data/spec/rails/experiment/vendor/assets/javascripts/.keep +0 -0
- data/spec/rails/experiment/vendor/assets/stylesheets/.keep +0 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/support/deployment/helper/shell_command_support.rb +34 -0
- data/spec/support/deployment/helper/uploader_support.rb +21 -0
- data/spec/support/deployment/platform_support.rb +32 -0
- metadata +262 -21
- data/lib/comodule/customize_class/hash_custom.rb +0 -20
- data/spec/comodule/customize_class/hash_custom_spec.rb +0 -32
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
require 'aws-sdk'
|
|
2
|
+
|
|
3
|
+
module Comodule::Deployment::Helper::Aws
|
|
4
|
+
|
|
5
|
+
def self.included(receiver)
|
|
6
|
+
receiver.send :include, InstanceMethods, CloudFormation, S3, Ec2, Ssl, Rds
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
module InstanceMethods
|
|
10
|
+
def aws
|
|
11
|
+
@aws ||= ::Comodule::Deployment::Helper::Aws::Service.new(self)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class Service
|
|
16
|
+
include ::Comodule::Deployment::Helper::Base
|
|
17
|
+
|
|
18
|
+
def initialize(platform)
|
|
19
|
+
self.owner = platform
|
|
20
|
+
|
|
21
|
+
@aws_sdk_object = {}
|
|
22
|
+
@access_credentials = access_credentials || {}
|
|
23
|
+
@method_map = {}
|
|
24
|
+
::AWS.constants.each do |const_name|
|
|
25
|
+
const = ::AWS.const_get(const_name)
|
|
26
|
+
if defined?(const.new)
|
|
27
|
+
@method_map[const_name.to_s.underscore.to_sym] = const
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def access_credentials
|
|
33
|
+
config.aws_access_credentials || {}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def search_credential_directive(aws_resource_name, directive)
|
|
37
|
+
(access_credentials[aws_resource_name] && access_credentials[aws_resource_name][directive]) ||
|
|
38
|
+
(access_credentials[:common] && access_credentials[:common][directive]) ||
|
|
39
|
+
access_credentials[directive] ||
|
|
40
|
+
config["aws_#{directive}".to_sym]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def access_key_id(aws_resource_name)
|
|
44
|
+
search_credential_directive(aws_resource_name, :access_key_id)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def secret_access_key(aws_resource_name)
|
|
48
|
+
search_credential_directive(aws_resource_name, :secret_access_key)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def region(aws_resource_name)
|
|
52
|
+
search_credential_directive(aws_resource_name, :region)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def validate_credential(aws_resource_name, iam)
|
|
56
|
+
case aws_resource_name
|
|
57
|
+
when :cloud_formation, :rds, :auto_scaling
|
|
58
|
+
if !iam || !iam[:region]
|
|
59
|
+
raise ArgumentError, "Please specify aws_access_credentials.#{aws_resource_name}.region on your config.yml."
|
|
60
|
+
end
|
|
61
|
+
when :cloud_front, :s3
|
|
62
|
+
iam.delete(:region)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
iam
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def method_missing(method_name)
|
|
69
|
+
if @method_map[method_name]
|
|
70
|
+
return @aws_sdk_object[method_name] if @aws_sdk_object[method_name]
|
|
71
|
+
|
|
72
|
+
iam = {}
|
|
73
|
+
|
|
74
|
+
key_id = access_key_id(method_name)
|
|
75
|
+
secret = secret_access_key(method_name)
|
|
76
|
+
region = region(method_name)
|
|
77
|
+
iam[:access_key_id] = key_id if key_id
|
|
78
|
+
iam[:secret_access_key] = secret if secret
|
|
79
|
+
iam[:region] = region if region && region.present?
|
|
80
|
+
|
|
81
|
+
iam = (@access_credentials[method_name] || @access_credentials[:common] || {}).to_hash.merge(iam)
|
|
82
|
+
|
|
83
|
+
validate_credential(method_name, iam)
|
|
84
|
+
if !iam.empty?
|
|
85
|
+
@aws_sdk_object[method_name] = @method_map[method_name].new(iam)
|
|
86
|
+
else
|
|
87
|
+
@aws_sdk_object[method_name] = @method_map[method_name].new
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
return @aws_sdk_object[method_name]
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
raise ArgumentError, "#{self.class.name} was missing AWS class #{method_name}."
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Comodule::Deployment::Helper::Aws::Base
|
|
2
|
+
|
|
3
|
+
def self.included(receiver)
|
|
4
|
+
receiver.send :include, ::Comodule::Deployment::Helper::Base
|
|
5
|
+
receiver.send :include, InstanceMethods
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
module InstanceMethods
|
|
9
|
+
|
|
10
|
+
def aws
|
|
11
|
+
owner.aws
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
module Comodule::Deployment::Helper::Aws::CloudFormation
|
|
2
|
+
|
|
3
|
+
def self.included(receiver)
|
|
4
|
+
receiver.send :include, InstanceMethods
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
module InstanceMethods
|
|
8
|
+
def cloud_formation
|
|
9
|
+
@cloud_formation ||= ::Comodule::Deployment::Helper::Aws::CloudFormation::Service.new(self)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class Service
|
|
14
|
+
include ::Comodule::Deployment::Helper::Aws::Base
|
|
15
|
+
|
|
16
|
+
def cfn
|
|
17
|
+
@cfn ||= aws.cloud_formation
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def stack_basename
|
|
21
|
+
stack_name = []
|
|
22
|
+
stack_name << (config.stack_name_prefix || owner.project_name)
|
|
23
|
+
stack_name << owner.name
|
|
24
|
+
stack_name.join(?-)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def own_stacks
|
|
28
|
+
cfn.stacks.find_all { |stack| stack.name =~ /#{stack_basename}/ }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def latest_stack
|
|
32
|
+
filter = -> stack { stack.name.match(/[0-9]*$/)[0].to_i }
|
|
33
|
+
own_stacks.max { |a,b| filter[a] <=> filter[b] }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def create_stack(&block)
|
|
37
|
+
if config.upload_secret_files
|
|
38
|
+
puts 'Upload secret files'
|
|
39
|
+
owner.upload_secret_files
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
if config.upload_project
|
|
43
|
+
puts 'Upload project'
|
|
44
|
+
owner.upload_project
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
stack_name = [stack_basename, Time.now.strftime("%Y%m%d")].join(?-)
|
|
48
|
+
|
|
49
|
+
template = validate_template(&block)
|
|
50
|
+
|
|
51
|
+
stack = cfn.stacks.create(stack_name, template)
|
|
52
|
+
|
|
53
|
+
puts "Progress of creation stack: #{stack.name}"
|
|
54
|
+
|
|
55
|
+
status = stack_status_watch(stack)
|
|
56
|
+
|
|
57
|
+
puts "\n!!! #{status} !!!\n"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def delete_stack
|
|
61
|
+
stack = latest_stack
|
|
62
|
+
|
|
63
|
+
if !stack || !stack.exists?
|
|
64
|
+
puts "Stack:/#{stack_basename}-[0-9]*/ is not found.\n"
|
|
65
|
+
exit
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
print "You are going to delete stack #{stack.name}. Are you sure? [N/y] "
|
|
69
|
+
confirm = STDIN.gets
|
|
70
|
+
unless confirm =~ /^y(es)?$/
|
|
71
|
+
puts "\nAbort!\n"
|
|
72
|
+
exit
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
stack.delete
|
|
76
|
+
|
|
77
|
+
puts "Progress of deletion stack: #{stack.name}"
|
|
78
|
+
|
|
79
|
+
status = stack_status_watch(stack)
|
|
80
|
+
|
|
81
|
+
puts "\n!!! #{status} !!!\n"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def stack_status_watch(stack, interval=10)
|
|
85
|
+
begin
|
|
86
|
+
status = stack.status
|
|
87
|
+
rescue
|
|
88
|
+
return 'Missing stack'
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
first_status = status
|
|
92
|
+
before_status = ""
|
|
93
|
+
|
|
94
|
+
while status == first_status
|
|
95
|
+
if status == before_status
|
|
96
|
+
before_status, status = status, ?.
|
|
97
|
+
else
|
|
98
|
+
before_status = status
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
print status
|
|
102
|
+
|
|
103
|
+
sleep interval
|
|
104
|
+
|
|
105
|
+
begin
|
|
106
|
+
status = stack.status
|
|
107
|
+
rescue
|
|
108
|
+
status = "Missing stack"
|
|
109
|
+
break
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
status
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def validate_template(&block)
|
|
117
|
+
template = cloud_formation_template(&block)
|
|
118
|
+
|
|
119
|
+
template_path = File.join(owner.test_cloud_formation_dir, 'template.json')
|
|
120
|
+
|
|
121
|
+
File.open(template_path, 'w') do |file|
|
|
122
|
+
file.write template
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
result = cfn.validate_template(template)
|
|
126
|
+
|
|
127
|
+
puts "Validation result:"
|
|
128
|
+
result.each do |key, msg|
|
|
129
|
+
puts " #{key}: #{msg}"
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
template
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def cloud_formation_template
|
|
136
|
+
if block_given?
|
|
137
|
+
yield config
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
file = File.join(owner.cloud_formation_dir, 'template.json.erb')
|
|
141
|
+
common_file = File.join(owner.common_cloud_formation_dir, 'template.json.erb')
|
|
142
|
+
|
|
143
|
+
owner.render( File.file?(file) ? file : common_file )
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module Comodule::Deployment::Helper::Aws::Ec2
|
|
2
|
+
|
|
3
|
+
def self.included(receiver)
|
|
4
|
+
receiver.send :include, InstanceMethods
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
module InstanceMethods
|
|
8
|
+
def ec2
|
|
9
|
+
@ec2 ||= ::Comodule::Deployment::Helper::Aws::Ec2::Service.new(self)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class Service
|
|
14
|
+
include ::Comodule::Deployment::Helper::Aws::Base
|
|
15
|
+
|
|
16
|
+
def ec2
|
|
17
|
+
@ec2 ||= aws.ec2
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def own_images
|
|
21
|
+
ec2.images.with_owner('self')
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def latest_ami
|
|
25
|
+
images = own_images
|
|
26
|
+
if config.ec2 && config.ec2.ami && config.ec2.ami.prefix
|
|
27
|
+
images = images.find_all { |ami| ami.name =~ /^#{config.ec2.ami.prefix}/ }
|
|
28
|
+
|
|
29
|
+
filter = -> ami { ami.name.match(/[0-9]*$/)[0].to_i }
|
|
30
|
+
images = images.sort do |a, b|
|
|
31
|
+
filter[b] <=> filter[a]
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
images.first
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module Comodule::Deployment::Helper::Aws::Rds
|
|
2
|
+
|
|
3
|
+
def self.included(receiver)
|
|
4
|
+
receiver.send :include, InstanceMethods
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
module InstanceMethods
|
|
8
|
+
def rds
|
|
9
|
+
@rds ||= ::Comodule::Deployment::Helper::Aws::Rds::Service.new(self)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class Service
|
|
14
|
+
include ::Comodule::Deployment::Helper::Aws::Base
|
|
15
|
+
|
|
16
|
+
def db(db_instance_identifier)
|
|
17
|
+
::Comodule::Deployment::Helper::Aws::Rds::Db.new(owner, db_instance_identifier)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def latest_automated_snapshot
|
|
21
|
+
if config.db && config.db.master && !config.db.snapshot_identifier
|
|
22
|
+
config.db.snapshot_identifier = db(config.db.master).latest_automated_snapshot
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
class Db
|
|
28
|
+
include ::Comodule::Deployment::Helper::Aws::Base
|
|
29
|
+
|
|
30
|
+
attr_accessor :db
|
|
31
|
+
|
|
32
|
+
def initialize(platform, db_instance_identifier)
|
|
33
|
+
self.owner = platform
|
|
34
|
+
self.db = aws.rds.db_instances[db_instance_identifier]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def latest_automated_snapshot
|
|
38
|
+
snapshot =
|
|
39
|
+
db.snapshots.with_type('automated').sort do |a, b|
|
|
40
|
+
b.created_at <=> a.created_at
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
snapshot.first.db_snapshot_identifier
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
module Comodule::Deployment::Helper::Aws::S3
|
|
2
|
+
|
|
3
|
+
def self.included(receiver)
|
|
4
|
+
receiver.send :include, InstanceMethods
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
module InstanceMethods
|
|
8
|
+
def s3
|
|
9
|
+
@s3 ||= ::Comodule::Deployment::Helper::Aws::S3::Service.new(self)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class Service
|
|
14
|
+
include ::Comodule::Deployment::Helper::Aws::Base
|
|
15
|
+
|
|
16
|
+
def s3
|
|
17
|
+
@s3 ||= aws.s3
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def bucket_name
|
|
21
|
+
@bucket_name ||= config.s3_bucket
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def bucket
|
|
25
|
+
return @bucket if @bucket
|
|
26
|
+
|
|
27
|
+
bucket_obj = s3.buckets[bucket_name]
|
|
28
|
+
@bucket =
|
|
29
|
+
if bucket_obj.exists?
|
|
30
|
+
bucket_obj
|
|
31
|
+
else
|
|
32
|
+
s3.buckets.create(bucket_name)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def local_to_cloud(local_path)
|
|
37
|
+
local_path.sub(%r|#{owner.project_root}/|, "#{owner.name}/")
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def cloud_to_local(s3_path)
|
|
41
|
+
s3_path.sub(%r|#{owner.name}/|, "#{owner.project_root}/")
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def public_url(s3_path)
|
|
45
|
+
s3.bucket[s3_path].public_url secure: true
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def local_to_public_url(local_path)
|
|
49
|
+
public_url local_to_cloud(local_path)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
module Comodule::Deployment::Helper::Aws::Ssl
|
|
2
|
+
|
|
3
|
+
def self.included(receiver)
|
|
4
|
+
receiver.send :include, InstanceMethods
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
module InstanceMethods
|
|
8
|
+
def ssl
|
|
9
|
+
@ssl ||= ::Comodule::Deployment::Helper::Aws::Ssl::Service.new(self)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class Service
|
|
14
|
+
include ::Comodule::Deployment::Helper::Aws::Base
|
|
15
|
+
|
|
16
|
+
def iam
|
|
17
|
+
aws.iam
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def describe
|
|
21
|
+
puts
|
|
22
|
+
iam.server_certificates.each do |cert|
|
|
23
|
+
inspect_certificate cert
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def delete
|
|
28
|
+
name = config.ssl.name
|
|
29
|
+
cert = iam.server_certificates[name]
|
|
30
|
+
puts "I am going to delete this server certificate #{name}. Are you sure? [N/y] "
|
|
31
|
+
confirm = STDIN.gets
|
|
32
|
+
unless confirm =~ /^y(es)?$/
|
|
33
|
+
puts "\nAbort!\n"
|
|
34
|
+
return
|
|
35
|
+
end
|
|
36
|
+
puts cert.delete
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def upload
|
|
40
|
+
body = File.open(owner.file_path(config.ssl.dir, config.ssl.body_file)).read
|
|
41
|
+
chain = File.open(owner.file_path(config.ssl.dir, config.ssl.chain_file)).read
|
|
42
|
+
key = File.open(owner.file_path(config.ssl.dir, config.ssl.key_file)).read
|
|
43
|
+
puts "body:"
|
|
44
|
+
puts body
|
|
45
|
+
puts
|
|
46
|
+
puts "chain:"
|
|
47
|
+
puts chain
|
|
48
|
+
puts
|
|
49
|
+
puts "key"
|
|
50
|
+
puts key
|
|
51
|
+
puts
|
|
52
|
+
puts "AWS IAM server certificate name: #{config.ssl.name}"
|
|
53
|
+
puts "I am going to upload this server certificate to AWS IAM. Are you sure? [N/y] "
|
|
54
|
+
confirm = STDIN.gets
|
|
55
|
+
unless confirm =~ /^y(es)?$/
|
|
56
|
+
puts "\nAbort!\n"
|
|
57
|
+
return
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
cert = iam.server_certificates.create(
|
|
61
|
+
certificate_body: body,
|
|
62
|
+
name: config.ssl.name,
|
|
63
|
+
path: config.ssl.path || ?/,
|
|
64
|
+
private_key: key,
|
|
65
|
+
certificate_chain: chain
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
unless cert
|
|
69
|
+
'Failed!'
|
|
70
|
+
return
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
puts
|
|
74
|
+
puts "Success:"
|
|
75
|
+
inspect_certificate cert
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def inspect_certificate(cert)
|
|
79
|
+
inspect_certificate_summary cert
|
|
80
|
+
inspect_certificate_body cert
|
|
81
|
+
inspect_certificate_chain cert
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def inspect_certificate_summary(cert)
|
|
85
|
+
puts "arn: #{cert.arn}"
|
|
86
|
+
puts "id: #{cert.id}"
|
|
87
|
+
puts "name: #{cert.name}"
|
|
88
|
+
puts "path: #{cert.path}"
|
|
89
|
+
puts "upload_date: #{cert.upload_date}"
|
|
90
|
+
puts
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def inspect_certificate_body(cert)
|
|
94
|
+
puts "body:"
|
|
95
|
+
puts cert.certificate_body
|
|
96
|
+
puts
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def inspect_certificate_chain(cert)
|
|
100
|
+
puts "chain:"
|
|
101
|
+
puts cert.certificate_chain
|
|
102
|
+
puts
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def find
|
|
106
|
+
iam.server_certificates.find do |cert|
|
|
107
|
+
cert.name == config.ssl.name
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|