comodule 0.0.4 → 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/.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
data/lib/comodule/version.rb
CHANGED
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'comodule'
|
2
|
+
|
3
|
+
namespace :comodule do
|
4
|
+
|
5
|
+
def platform
|
6
|
+
return @platform if @platform
|
7
|
+
platform_name = @args && @args.platform_name
|
8
|
+
env = {}
|
9
|
+
|
10
|
+
['project_root', 'db_host', 'db_password', 'RAILS_ENV', 'env'].each do |env_name|
|
11
|
+
env[env_name.to_sym] = ENV[env_name] if ENV[env_name]
|
12
|
+
end
|
13
|
+
|
14
|
+
@platform = Comodule::Deployment::Platform.new(platform_name, env)
|
15
|
+
end
|
16
|
+
|
17
|
+
task :variables do |cmd, args|
|
18
|
+
@args = args
|
19
|
+
end
|
20
|
+
|
21
|
+
namespace :platform do
|
22
|
+
|
23
|
+
desc 'Create necessary directories and files for the platform'
|
24
|
+
task :create, [:platform_name] => [:environment, :variables] do
|
25
|
+
platform.create
|
26
|
+
end
|
27
|
+
|
28
|
+
desc 'Upload secret files'
|
29
|
+
task :upload_secret_files, [:platform_name] => [:environment, :variables] do
|
30
|
+
platform.upload_secret_files
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "Download secret files"
|
34
|
+
task :download_secret_files, [:platform_name] => [:environment, :variables] do
|
35
|
+
platform.download_secret_files
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "Upload project files"
|
39
|
+
task :upload_project, [:platform_name] => [:environment, :variables] do
|
40
|
+
platform.upload_project
|
41
|
+
end
|
42
|
+
|
43
|
+
desc 'Validate cloudFormation stack'
|
44
|
+
task :validate_template, [:platform_name] => :variables do
|
45
|
+
platform.cloud_formation.validate_template
|
46
|
+
end
|
47
|
+
|
48
|
+
desc 'Create cloudFormation stack'
|
49
|
+
task :create_stack, [:platform_name] => :variables do
|
50
|
+
platform.cloud_formation.create_stack
|
51
|
+
end
|
52
|
+
|
53
|
+
desc 'Delete cloudFormation stack'
|
54
|
+
task :delete_stack, [:platform_name] => :variables do
|
55
|
+
platform.cloud_formation.delete_stack
|
56
|
+
end
|
57
|
+
|
58
|
+
desc 'Provisioning'
|
59
|
+
task :provision, [:platform_name] => :variables do
|
60
|
+
platform.deploy
|
61
|
+
end
|
62
|
+
|
63
|
+
namespace :ssl do
|
64
|
+
|
65
|
+
desc "Describe IAM server certificates"
|
66
|
+
task :describe, [:platform_name] => :variables do
|
67
|
+
platform.ssl.describe
|
68
|
+
end
|
69
|
+
|
70
|
+
desc "Upload IAM server certificate"
|
71
|
+
task :upload, [:platform_name] => :variables do
|
72
|
+
platform.ssl.upload
|
73
|
+
end
|
74
|
+
|
75
|
+
desc "Delete IAM server certificate"
|
76
|
+
task :delete, [:platform_name] => :variables do
|
77
|
+
platform.ssl.delete
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
namespace :test do
|
82
|
+
|
83
|
+
desc 'Test of upload secret files'
|
84
|
+
task :upload_secret_files, [:platform_name] => [:environment, :variables] do
|
85
|
+
platform.upload_secret_files_test
|
86
|
+
end
|
87
|
+
|
88
|
+
desc "Test of download secret files"
|
89
|
+
task :download_secret_files, [:platform_name] => [:environment, :variables] do
|
90
|
+
platform.download_secret_files_test
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -1,7 +1,70 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Comodule::ConfigSupport do
|
4
|
+
describe 'cannot use the name same as a member of Object#methods' do
|
5
|
+
it do
|
6
|
+
hsh = {
|
7
|
+
host: 'example.com',
|
8
|
+
db: {
|
9
|
+
host: 'rds',
|
10
|
+
database: 'app_development',
|
11
|
+
username: 'ec2-user',
|
12
|
+
schedule: {
|
13
|
+
to_json: '08-00-00',
|
14
|
+
}
|
15
|
+
}
|
16
|
+
}
|
17
|
+
expect{Comodule::ConfigSupport::Config.new(hsh)}
|
18
|
+
.to raise_error(ArgumentError)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
4
22
|
describe '::Config' do
|
23
|
+
context '#+' do
|
24
|
+
it 'merge recusive' do
|
25
|
+
config = Comodule::ConfigSupport::Config.new(
|
26
|
+
host: 'example.com',
|
27
|
+
db: {
|
28
|
+
host: 'rds',
|
29
|
+
database: 'app_development',
|
30
|
+
username: 'ec2-user',
|
31
|
+
schedule: {
|
32
|
+
boot: '08-00-00',
|
33
|
+
}
|
34
|
+
}
|
35
|
+
)
|
36
|
+
|
37
|
+
config2 = Comodule::ConfigSupport::Config.new(
|
38
|
+
port: '3000',
|
39
|
+
db: {
|
40
|
+
host: 'rds',
|
41
|
+
password: 'secret',
|
42
|
+
schedule: {
|
43
|
+
shutdown: '22-00-00'
|
44
|
+
}
|
45
|
+
}
|
46
|
+
)
|
47
|
+
|
48
|
+
result = {
|
49
|
+
host: 'example.com',
|
50
|
+
port: '3000',
|
51
|
+
db: {
|
52
|
+
host: 'rds',
|
53
|
+
database: 'app_development',
|
54
|
+
username: 'ec2-user',
|
55
|
+
password: 'secret',
|
56
|
+
schedule: {
|
57
|
+
boot: '08-00-00',
|
58
|
+
shutdown: '22-00-00'
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
config += config2
|
64
|
+
expect(config.to_hash).to eq(result)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
5
68
|
context '#[], #[]=' do
|
6
69
|
it 'like Hash' do
|
7
70
|
config = Comodule::ConfigSupport::Config.new
|
@@ -28,6 +91,31 @@ describe Comodule::ConfigSupport do
|
|
28
91
|
end
|
29
92
|
|
30
93
|
context '#to_hash' do
|
94
|
+
it 'support recursive object' do
|
95
|
+
config = Comodule::ConfigSupport::Config.new(
|
96
|
+
configure_type: :hard,
|
97
|
+
host: 'example.com',
|
98
|
+
port: '3000',
|
99
|
+
db: {
|
100
|
+
host: 'rds',
|
101
|
+
database: 'app_development',
|
102
|
+
username: 'ec2-user',
|
103
|
+
password: 'secret'
|
104
|
+
}
|
105
|
+
)
|
106
|
+
hsh = config.to_hash
|
107
|
+
expect(hsh).to eq({
|
108
|
+
host: 'example.com',
|
109
|
+
port: '3000',
|
110
|
+
db: {
|
111
|
+
host: 'rds',
|
112
|
+
database: 'app_development',
|
113
|
+
username: 'ec2-user',
|
114
|
+
password: 'secret'
|
115
|
+
}
|
116
|
+
})
|
117
|
+
end
|
118
|
+
|
31
119
|
it 'not include :cofigure_type' do
|
32
120
|
config = Comodule::ConfigSupport::Config.new(
|
33
121
|
configure_type: :hard,
|
@@ -44,6 +132,20 @@ describe Comodule::ConfigSupport do
|
|
44
132
|
end
|
45
133
|
|
46
134
|
context '.new' do
|
135
|
+
it 'support block' do
|
136
|
+
config = Comodule::ConfigSupport::Config.new do |config|
|
137
|
+
config.host = 'example.com'
|
138
|
+
config.port = '3000'
|
139
|
+
config.db = {
|
140
|
+
host: 'rds',
|
141
|
+
database: 'ec2-user',
|
142
|
+
password: 'secret'
|
143
|
+
}
|
144
|
+
expect(config.host).to eq('example.com')
|
145
|
+
expect(config.db.host).to eq('rds')
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
47
149
|
it 'can specify each other configure_type to recursive object' do
|
48
150
|
config = Comodule::ConfigSupport::Config.new(
|
49
151
|
configure_type: :hard,
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Comodule::Deployment::Helper::Aws::CloudFormation do
|
4
|
+
include_context 'deployment.platform'
|
5
|
+
|
6
|
+
before do
|
7
|
+
platform.create
|
8
|
+
platform.config.aws_region = "ap-northeast-1"
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#cloud_formation' do
|
12
|
+
subject { platform.cloud_formation.cfn }
|
13
|
+
|
14
|
+
it 'is wrapper of AWS::CloudFormation' do
|
15
|
+
is_expected.to be_an_instance_of(AWS::CloudFormation)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#stack_basename' do
|
20
|
+
subject { platform.cloud_formation.stack_basename }
|
21
|
+
|
22
|
+
context '#config.stack_name_prefix is blank' do
|
23
|
+
|
24
|
+
it do
|
25
|
+
is_expected.to eq("#{platform.project_name}-#{platform.name}")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context '#config.stack_name_prefix is not blank' do
|
30
|
+
before do
|
31
|
+
platform.config.stack_name_prefix = 'stacknameprefix'
|
32
|
+
end
|
33
|
+
|
34
|
+
it do
|
35
|
+
is_expected.to eq("#{platform.config.stack_name_prefix}-#{platform.name}")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
let(:basename) { platform.cloud_formation.stack_basename }
|
41
|
+
|
42
|
+
let(:stacks) do
|
43
|
+
[
|
44
|
+
double('otherstack', name: 'otherstack-20141006'),
|
45
|
+
double('stack1', name: "#{basename}-20140101"),
|
46
|
+
double('stack2', name: "#{basename}-20131231"),
|
47
|
+
double('stack3', name: "#{basename}-20141006"),
|
48
|
+
double('stack4', name: "#{basename}-20140831")
|
49
|
+
]
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#own_stacks' do
|
53
|
+
subject { platform.cloud_formation.own_stacks }
|
54
|
+
|
55
|
+
it 'returns own cloudFormation stacks' do
|
56
|
+
allow(platform.cloud_formation.cfn)
|
57
|
+
.to receive(:stacks).and_return(stacks)
|
58
|
+
is_expected.to eq(stacks[1..-1])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#latest_stack' do
|
63
|
+
subject { platform.cloud_formation.latest_stack }
|
64
|
+
|
65
|
+
it 'returns latest cloudFormation stack' do
|
66
|
+
allow(platform.cloud_formation.cfn)
|
67
|
+
.to receive(:stacks).and_return(stacks)
|
68
|
+
expect(subject.name).to eq("#{basename}-20141006")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Comodule::Deployment::Helper::Aws::S3 do
|
4
|
+
include_context 'deployment.platform'
|
5
|
+
|
6
|
+
before do
|
7
|
+
platform.create
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:bucket_name) { 'comodule-test' }
|
11
|
+
|
12
|
+
describe '#s3' do
|
13
|
+
subject { platform.s3.s3 }
|
14
|
+
|
15
|
+
it 'is wrapper of AWS::S3' do
|
16
|
+
is_expected.to be_an_instance_of(AWS::S3)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#bucket_name' do
|
21
|
+
subject { platform.s3.bucket_name }
|
22
|
+
|
23
|
+
before do
|
24
|
+
platform.config.s3_bucket = bucket_name
|
25
|
+
end
|
26
|
+
|
27
|
+
it '== #config.s3_bucket' do
|
28
|
+
is_expected.to eq(bucket_name)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#bucket' do
|
33
|
+
subject { platform.s3.bucket }
|
34
|
+
|
35
|
+
let(:s3) { double('s3', 'buckets' => double('[]' => bucket_obj, 'create' => bucket_obj)) }
|
36
|
+
let(:bucket_obj) { double('bucket_obj', "exists?" => judge) }
|
37
|
+
|
38
|
+
before do
|
39
|
+
platform.config.s3_bucket = bucket_name
|
40
|
+
platform.s3.instance_variable_set :@s3, s3
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'exists the S3 bucket' do
|
44
|
+
let(:judge) { true }
|
45
|
+
|
46
|
+
it 'returns the S3 bucket' do
|
47
|
+
allow(s3).to receive_message_chain('buckets.[]', bucket_name)
|
48
|
+
allow(bucket_obj).to receive(:exists?).and_return(true)
|
49
|
+
is_expected.to eq(bucket_obj)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'not exists the S3 bucket' do
|
54
|
+
let(:judge) { false }
|
55
|
+
|
56
|
+
it 'create the S3 bucket' do
|
57
|
+
allow(s3).to receive_message_chain('buckets.[]', bucket_name)
|
58
|
+
allow(bucket_obj).to receive(:exists?).and_return(false)
|
59
|
+
allow(s3).to receive_message_chain('buckets.create', bucket_name)
|
60
|
+
is_expected.to eq(bucket_obj)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#local_to_cloud' do
|
66
|
+
subject { platform.s3.local_to_cloud(File.join(platform.secret_config_dir, 'secret.txt')) }
|
67
|
+
|
68
|
+
it "return a path on S3" do
|
69
|
+
is_expected.to eq("#{platform.name}/platform/#{platform.name}/secret_config/secret.txt")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#cloud_to_local' do
|
74
|
+
let(:path) { File.join platform.secret_config_dir, 'secret.txt' }
|
75
|
+
|
76
|
+
subject do
|
77
|
+
s3_path = platform.s3.local_to_cloud(path)
|
78
|
+
platform.s3.cloud_to_local(s3_path)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'return a path in local' do
|
82
|
+
is_expected.to eq(path)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,176 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Comodule::Deployment::Helper::ShellCommand do
|
4
|
+
|
5
|
+
include_context 'deployment.platform'
|
6
|
+
include_context 'deployment.helper.shell_command'
|
7
|
+
|
8
|
+
before do
|
9
|
+
platform.create
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:test_command) { 'ls -la' }
|
13
|
+
|
14
|
+
describe '#dummy' do
|
15
|
+
subject { platform.dummy :`, test_command }
|
16
|
+
|
17
|
+
it 'return message to STDOUT' do
|
18
|
+
expect(platform).to receive(:puts).with(
|
19
|
+
"execute dummy method: `, args: #{[test_command]}"
|
20
|
+
)
|
21
|
+
subject
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#command_or_dummy' do
|
26
|
+
subject { platform.command_or_dummy test_command }
|
27
|
+
|
28
|
+
context 'not #deployment?' do
|
29
|
+
it 'return message to STDOUT' do
|
30
|
+
expect(platform).to receive(:puts).with(
|
31
|
+
"execute dummy method: `, args: #{[test_command]}"
|
32
|
+
)
|
33
|
+
subject
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context '#deployment?' do
|
38
|
+
before do
|
39
|
+
platform.env = :staging
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'execute shell command' do
|
43
|
+
expect(platform).to receive(:`).with(test_command)
|
44
|
+
subject
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#chown' do
|
50
|
+
subject { platform.chown }
|
51
|
+
|
52
|
+
context 'config.chown' do
|
53
|
+
context 'has a command' do
|
54
|
+
before do
|
55
|
+
platform.config.chown = test_command
|
56
|
+
end
|
57
|
+
|
58
|
+
it '#command_or_dummy receives the command' do
|
59
|
+
expect(platform).to receive(:command_or_dummy).with(
|
60
|
+
"chown #{test_command}"
|
61
|
+
)
|
62
|
+
subject
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'has some commands' do
|
67
|
+
let(:commands) do
|
68
|
+
[
|
69
|
+
'ec2-user:ec2-user /home/ec2-user/projects',
|
70
|
+
'ec2-user:ec2-user /etc/nginx/nginx.conf',
|
71
|
+
'ec2-user:ec2-user /home/ec2-user/db-backup'
|
72
|
+
]
|
73
|
+
end
|
74
|
+
|
75
|
+
before do
|
76
|
+
platform.config.chown = commands
|
77
|
+
end
|
78
|
+
|
79
|
+
it '#command_or_dummy receives those commands' do
|
80
|
+
commands.each do |cmd|
|
81
|
+
expect(platform).to receive(:command_or_dummy).with("chown #{cmd}")
|
82
|
+
end
|
83
|
+
subject
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe '#crontab' do
|
90
|
+
subject { platform.crontab }
|
91
|
+
|
92
|
+
context 'exists a file' do
|
93
|
+
context 'in #common_crontab_dir' do
|
94
|
+
before do
|
95
|
+
be_crontab_files :common_crontab_dir, ['batch.rb']
|
96
|
+
end
|
97
|
+
|
98
|
+
it_behaves_like 'crontab messages', ['batch.rb']
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'in #crontab_dir' do
|
102
|
+
before do
|
103
|
+
be_crontab_files :crontab_dir, ['batch.rb']
|
104
|
+
end
|
105
|
+
|
106
|
+
it_behaves_like 'crontab messages', ['batch.rb']
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'in #secret_crontab_dir' do
|
110
|
+
before do
|
111
|
+
be_crontab_files :secret_crontab_dir, ['batch.rb']
|
112
|
+
end
|
113
|
+
|
114
|
+
it_behaves_like 'crontab messages', ['batch.rb']
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'exists some files' do
|
119
|
+
commands1 = ['batch.rb', 'batch-2.rb', 'batch-3.rb']
|
120
|
+
commands2 = ['script.rb', 'script-2.rb', 'script-3.rb']
|
121
|
+
commands3 = ['exec.rb', 'exec-2.rb', 'exec-3.rb']
|
122
|
+
|
123
|
+
before do
|
124
|
+
be_crontab_files :common_crontab_dir, commands1
|
125
|
+
be_crontab_files :crontab_dir, commands2
|
126
|
+
be_crontab_files :secret_crontab_dir, commands3
|
127
|
+
end
|
128
|
+
|
129
|
+
it_behaves_like 'crontab messages', commands1 + commands2 + commands3
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe '#shell_script' do
|
134
|
+
subject { platform.shell_script }
|
135
|
+
|
136
|
+
context 'exists a file' do
|
137
|
+
context 'in #common_shell_script_dir' do
|
138
|
+
before do
|
139
|
+
be_shell_script_files :common_shell_script_dir, ['script.rb']
|
140
|
+
end
|
141
|
+
|
142
|
+
it_behaves_like 'shell script messages', ['script.rb']
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'in #shell_script_dir' do
|
146
|
+
before do
|
147
|
+
be_shell_script_files :shell_script_dir, ['script.rb']
|
148
|
+
end
|
149
|
+
|
150
|
+
it_behaves_like 'shell script messages', ['script.rb']
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'in #secret_shell_script_dir' do
|
154
|
+
before do
|
155
|
+
be_shell_script_files :secret_shell_script_dir, ['script.rb']
|
156
|
+
end
|
157
|
+
|
158
|
+
it_behaves_like 'shell script messages', ['script.rb']
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context 'exists some files' do
|
163
|
+
scripts1 = ['scripts1-1.rb', 'scripts1-2.rb', 'scripts1-3.rb']
|
164
|
+
scripts2 = ['scripts2-1.rb', 'scripts2-2.rb', 'scripts2-3.rb']
|
165
|
+
scripts3 = ['scripts3-1.rb', 'scripts3-2.rb', 'scripts3-3.rb']
|
166
|
+
|
167
|
+
before do
|
168
|
+
be_shell_script_files :common_shell_script_dir, scripts1
|
169
|
+
be_shell_script_files :shell_script_dir, scripts2
|
170
|
+
be_shell_script_files :secret_shell_script_dir, scripts3
|
171
|
+
end
|
172
|
+
|
173
|
+
it_behaves_like 'shell script messages', scripts1 + scripts2 + scripts3
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|