ruby_yacht 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/.rdoc_options +8 -2
- data/.rspec +1 -0
- data/.travis.yml +17 -1
- data/Gemfile.lock +18 -2
- data/README.md +28 -10
- data/bin/ruby_yacht +5 -0
- data/doc/TODO.md +1 -20
- data/doc/configuration.md +104 -21
- data/doc/configuration_sample.rb +19 -8
- data/doc/contributing.md +28 -5
- data/doc/plugins.md +105 -45
- data/lib/ruby_yacht/dsl/app.rb +14 -18
- data/lib/ruby_yacht/dsl/configuration.rb +51 -32
- data/lib/ruby_yacht/dsl/database.rb +24 -8
- data/lib/ruby_yacht/dsl/dsl.rb +32 -4
- data/lib/ruby_yacht/dsl/hook.rb +182 -48
- data/lib/ruby_yacht/dsl/project.rb +20 -14
- data/lib/ruby_yacht/dsl/server_type.rb +14 -31
- data/lib/ruby_yacht/dsl/web_server.rb +87 -0
- data/lib/ruby_yacht/dsl.rb +1 -0
- data/lib/ruby_yacht/images/app/Dockerfile.erb +17 -6
- data/lib/ruby_yacht/images/app/before_startup.bash.erb +5 -3
- data/lib/ruby_yacht/images/app/startup.bash.erb +5 -2
- data/lib/ruby_yacht/images/app-dependencies/Dockerfile.erb +7 -11
- data/lib/ruby_yacht/images/database/Dockerfile.erb +7 -18
- data/lib/ruby_yacht/images/database/startup.bash.erb +1 -1
- data/lib/ruby_yacht/images/web/Dockerfile.erb +25 -19
- data/lib/ruby_yacht/plugins/mysql.rb +18 -8
- data/lib/ruby_yacht/{images/web → plugins/nginx/scripts}/add_app.rb +5 -5
- data/lib/ruby_yacht/{images/web → plugins/nginx/scripts}/add_project.rb +3 -3
- data/lib/ruby_yacht/plugins/nginx.rb +28 -0
- data/lib/ruby_yacht/plugins/rails/scripts/build_new_app.rb +10 -0
- data/lib/ruby_yacht/plugins/rails/scripts/update_rails_config.rb +6 -1
- data/lib/ruby_yacht/plugins/rails.rb +34 -19
- data/lib/ruby_yacht/plugins.rb +2 -1
- data/lib/ruby_yacht/runner/build_images.rb +87 -73
- data/lib/ruby_yacht/runner/checkout.rb +1 -1
- data/lib/ruby_yacht/runner/command.rb +13 -1
- data/lib/ruby_yacht/runner/create_new_project.rb +91 -0
- data/lib/ruby_yacht/runner/help.rb +1 -1
- data/lib/ruby_yacht/runner/run_containers.rb +17 -21
- data/lib/ruby_yacht/runner/runner.rb +27 -2
- data/lib/ruby_yacht/runner/services.rb +15 -10
- data/lib/ruby_yacht/runner/shell.rb +1 -1
- data/lib/ruby_yacht/runner/update_hosts.rb +16 -11
- data/lib/ruby_yacht/runner.rb +1 -0
- data/log/.gitkeep +0 -0
- data/ruby_yacht.gemspec +4 -2
- data/spec/docker/Dockerfile +19 -3
- data/spec/docker/install_gems.bash +5 -0
- data/spec/docker/run.bash +44 -0
- data/spec/docker/startup.bash +10 -0
- data/spec/dsl/app_spec.rb +66 -38
- data/spec/dsl/configuration_spec.rb +236 -30
- data/spec/dsl/database_spec.rb +103 -4
- data/spec/dsl/dsl_spec.rb +46 -3
- data/spec/dsl/hook_spec.rb +278 -57
- data/spec/dsl/project_spec.rb +75 -45
- data/spec/dsl/server_type_spec.rb +52 -12
- data/spec/dsl/web_server_spec.rb +160 -0
- data/spec/fixtures/apollo-new-project-config +20 -0
- data/spec/fixtures/app-dependencies-dockerfile-generic +4 -7
- data/spec/fixtures/app-dependencies-dockerfile-generic-with-library-install +6 -10
- data/spec/fixtures/app-dependencies-dockerfile-rails +9 -11
- data/spec/fixtures/app-dependencies-dockerfile-with-no-repository +20 -0
- data/spec/fixtures/database-dockerfile +1 -1
- data/spec/fixtures/database-dockerfile-mysql +3 -3
- data/spec/fixtures/database-dockerfile-rails +5 -4
- data/spec/fixtures/database-dockerfile-rails-with-no-repository +27 -0
- data/spec/fixtures/database-dockerfile-with-seed-hooks +3 -3
- data/spec/fixtures/database-startup-mysql +2 -1
- data/spec/fixtures/mars-before-startup +2 -2
- data/spec/fixtures/mars-before-startup-rails +5 -4
- data/spec/fixtures/mars-before-startup-with-before-startup-hooks +5 -4
- data/spec/fixtures/mars-before-startup-with-custom-file-copy +3 -3
- data/spec/fixtures/mars-before-startup-with-no-repository +3 -0
- data/spec/fixtures/mars-dockerfile +3 -2
- data/spec/fixtures/mars-dockerfile-rails +6 -5
- data/spec/fixtures/mars-dockerfile-rails-with-no-repository +32 -0
- data/spec/fixtures/mars-dockerfile-with-after-checkout-hooks +5 -4
- data/spec/fixtures/mars-dockerfile-with-before-startup-hooks +5 -4
- data/spec/fixtures/mars-dockerfile-with-custom-file-copy +4 -3
- data/spec/fixtures/mars-dockerfile-with-local-database +4 -2
- data/spec/fixtures/mars-dockerfile-with-no-repository +22 -0
- data/spec/fixtures/mars-dockerfile-with-remote-database +4 -2
- data/spec/fixtures/mars-startup +2 -2
- data/spec/fixtures/mars-startup-rails +2 -2
- data/spec/fixtures/mars-startup-rails-with-no-repository +5 -0
- data/spec/fixtures/mars-startup-with-no-repository +4 -0
- data/spec/fixtures/web-dockerfile +18 -11
- data/spec/fixtures/web-dockerfile-jupiter +28 -0
- data/spec/fixtures/web-dockerfile-nginx +38 -0
- data/spec/fixtures/web-dockerfile-with-eponymous-app +16 -10
- data/spec/fixtures/web-dockerfile-with-primary-app +16 -10
- data/spec/integration/build_images_spec.rb +210 -0
- data/spec/integration/build_spec.rb +23 -0
- data/spec/integration/checkout_spec.rb +94 -0
- data/spec/integration/create_new_project_spec.rb +50 -0
- data/spec/integration/implode_spec.rb +20 -0
- data/spec/integration/run.rb +93 -0
- data/spec/integration/run_containers_spec.rb +279 -0
- data/spec/integration/services_spec.rb +99 -0
- data/spec/integration/shell_spec.rb +31 -0
- data/spec/integration/update_hosts_spec.rb +35 -0
- data/spec/plugins/mysql_spec.rb +18 -1
- data/spec/plugins/nginx_spec.rb +66 -0
- data/spec/plugins/rails_spec.rb +61 -89
- data/spec/runner/build_images_spec.rb +111 -58
- data/spec/runner/command_spec.rb +55 -3
- data/spec/runner/create_new_project_spec.rb +93 -0
- data/spec/runner/help_spec.rb +5 -1
- data/spec/runner/run_containers_spec.rb +22 -10
- data/spec/runner/runner_spec.rb +31 -4
- data/spec/runner/services_spec.rb +32 -4
- data/spec/runner/update_hosts_spec.rb +2 -1
- data/spec/spec_helper.rb +16 -1
- data/spec/support/integration_helpers.rb +76 -0
- data/spec/support/test_project.rb +15 -3
- metadata +97 -14
- data/spec/docker/build.bash +0 -10
- data/spec/fixtures/deploy-dockerfile +0 -2
- data/spec/fixtures/multi-project-web-dockerfile +0 -25
- /data/lib/ruby_yacht/{images/web → plugins/nginx/scripts}/app_config.erb +0 -0
- /data/lib/ruby_yacht/{images/web → plugins/nginx/scripts}/index.html.erb +0 -0
- /data/lib/ruby_yacht/{images/web → plugins/nginx/scripts}/index_config.erb +0 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RubyYacht::Runner::UpdateHosts, :integration do
|
4
|
+
include IntegrationHelpers
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
configure_project
|
8
|
+
end
|
9
|
+
|
10
|
+
before do
|
11
|
+
run_command 'update_hosts'
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
restore_hosts_file
|
16
|
+
end
|
17
|
+
|
18
|
+
it "puts the domains for the apps in the hosts file" do
|
19
|
+
results = File.read('/etc/hosts').split("\n")
|
20
|
+
expect(results).to include '127.0.0.1 apollo.johnbrownlee.com'
|
21
|
+
expect(results).to include '127.0.0.1 mars.apollo.johnbrownlee.com'
|
22
|
+
expect(results).to include '127.0.0.1 saturn.apollo.johnbrownlee.com'
|
23
|
+
end
|
24
|
+
|
25
|
+
it "puts an old copy in the backup" do
|
26
|
+
timestamp = Time.now.utc.strftime('%Y%m%d%H')
|
27
|
+
file = Dir["/etc/hosts.#{timestamp}*.backup"].last
|
28
|
+
expect(file).not_to be_nil
|
29
|
+
results = File.read(file).split("\n")
|
30
|
+
expect(results.count).to be > 0
|
31
|
+
expect(results).not_to include 'apollo.johnbrownlee.com'
|
32
|
+
expect(results).not_to include 'mars.apollo.johnbrownlee.com'
|
33
|
+
expect(results).not_to include 'saturn.apollo.johnbrownlee.com'
|
34
|
+
end
|
35
|
+
end
|
data/spec/plugins/mysql_spec.rb
CHANGED
@@ -10,6 +10,23 @@ describe RubyYacht::Plugins::MySQL do
|
|
10
10
|
expect(RubyYacht.configuration.server_types.map(&:name)).to include :mysql
|
11
11
|
end
|
12
12
|
|
13
|
+
it "sets a default for port of 3306" do
|
14
|
+
RubyYacht.configure do
|
15
|
+
project :apollo do
|
16
|
+
system_prefix :apollo
|
17
|
+
repository "github.com"
|
18
|
+
|
19
|
+
mysql_database :apollo do
|
20
|
+
host "localhost"
|
21
|
+
username "apollo"
|
22
|
+
password "test"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
expect(RubyYacht.configuration.projects.first.databases.first.port).to eq 3306
|
28
|
+
end
|
29
|
+
|
13
30
|
describe "building images" do
|
14
31
|
subject { RubyYacht::Runner::BuildImages.new }
|
15
32
|
include DockerCommandSpec
|
@@ -28,13 +45,13 @@ describe RubyYacht::Plugins::MySQL do
|
|
28
45
|
RubyYacht.configure do
|
29
46
|
project :apollo do
|
30
47
|
system_prefix :apollo
|
31
|
-
domain "apollo.test.com"
|
32
48
|
repository "github.com"
|
33
49
|
|
34
50
|
mysql_database :apollo do
|
35
51
|
host "localhost"
|
36
52
|
username "apollo"
|
37
53
|
password "test"
|
54
|
+
port 3306
|
38
55
|
end
|
39
56
|
|
40
57
|
generic_app :mars do
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RubyYacht::Plugins::Nginx do
|
4
|
+
before do
|
5
|
+
RubyYacht.configuration.clear
|
6
|
+
RubyYacht::Plugins::Nginx.load
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'creates a server type called nginx' do
|
10
|
+
server_type = RubyYacht.configuration.server_types.first
|
11
|
+
expect(server_type.name).to eq :nginx
|
12
|
+
expect(server_type.container_type).to eq :web
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "building images" do
|
16
|
+
subject { RubyYacht::Runner::BuildImages.new }
|
17
|
+
include DockerCommandSpec
|
18
|
+
|
19
|
+
before do
|
20
|
+
RubyYacht.configuration.clear
|
21
|
+
described_class.load
|
22
|
+
|
23
|
+
RubyYacht.configure do
|
24
|
+
server_type :generic do
|
25
|
+
container_type :app
|
26
|
+
baseline_image 'ubuntu'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
RubyYacht.configure do
|
31
|
+
project :apollo do
|
32
|
+
system_prefix :apollo
|
33
|
+
repository "github.com"
|
34
|
+
|
35
|
+
generic_app :mars
|
36
|
+
generic_app :saturn
|
37
|
+
|
38
|
+
nginx_web_server do
|
39
|
+
domain 'apollo.test.com'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "builds all the images for the project" do
|
46
|
+
docker.fail_unexpected_commands!
|
47
|
+
docker.expect "network create apollo 2> /dev/null"
|
48
|
+
docker.expect "build -t apollo-generic-app-dependencies tmp"
|
49
|
+
docker.expect "build -t apollo-mars tmp"
|
50
|
+
docker.expect "build -t apollo-saturn tmp"
|
51
|
+
docker.expect "build -t apollo-web tmp"
|
52
|
+
subject.run
|
53
|
+
end
|
54
|
+
|
55
|
+
it "generates the dockerfiles for the web server" do
|
56
|
+
docker.expect "build -t apollo-web tmp" do
|
57
|
+
files = Dir[File.join("tmp", "*")].sort
|
58
|
+
expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/add_app.rb', 'tmp/add_project.rb', 'tmp/app_config.erb', 'tmp/index.html.erb', 'tmp/index_config.erb']
|
59
|
+
dockerfile = File.read(File.join('tmp', 'Dockerfile'))
|
60
|
+
expected = File.read(File.join('spec', 'fixtures', 'web-dockerfile-nginx'))
|
61
|
+
expect(dockerfile).to eq expected
|
62
|
+
end
|
63
|
+
subject.run
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/spec/plugins/rails_spec.rb
CHANGED
@@ -4,6 +4,18 @@ describe RubyYacht::Plugins::Rails do
|
|
4
4
|
before do
|
5
5
|
RubyYacht.configuration.clear
|
6
6
|
described_class.load
|
7
|
+
|
8
|
+
@project = RubyYacht::Project.new
|
9
|
+
RubyYacht.configuration.projects << @project
|
10
|
+
|
11
|
+
@app = RubyYacht::App.new
|
12
|
+
@app.server_type = :rails
|
13
|
+
@app.database_name = :test_db
|
14
|
+
@project.apps = [@app]
|
15
|
+
|
16
|
+
@database = RubyYacht::Database.new
|
17
|
+
@database.name = :test_db
|
18
|
+
@project.databases = [@database]
|
7
19
|
end
|
8
20
|
|
9
21
|
def configure_project(options = {})
|
@@ -13,7 +25,6 @@ describe RubyYacht::Plugins::Rails do
|
|
13
25
|
RubyYacht.configure do
|
14
26
|
project :test_project do
|
15
27
|
system_prefix :test_project
|
16
|
-
domain 'test.com'
|
17
28
|
repository 'github.com'
|
18
29
|
rails_secret_key_base(options[:secret_key_base]) if options[:secret_key_base]
|
19
30
|
rails_environment(options[:environment]) if options[:environment]
|
@@ -53,89 +64,6 @@ describe RubyYacht::Plugins::Rails do
|
|
53
64
|
expect(project.rails_excluded_gem_groups).to eq []
|
54
65
|
end
|
55
66
|
|
56
|
-
it "sets an environment variables for the RAILS_ENV" do
|
57
|
-
@project = RubyYacht::Project.new
|
58
|
-
@project.rails_environment = 'staging'
|
59
|
-
variables = RubyYacht.configuration.find_server_type(:rails).environment_variables
|
60
|
-
variable = variables.find { |v| v[:name] == 'RAILS_ENV' }
|
61
|
-
|
62
|
-
expect(variable).not_to be_nil
|
63
|
-
expect(variable[:image]).to eq :app_dependencies
|
64
|
-
expect(instance_eval(&variable[:block])).to eq 'staging'
|
65
|
-
end
|
66
|
-
|
67
|
-
it "sets an environment variable for the SECRET_KEY_BASE" do
|
68
|
-
@project = RubyYacht::Project.new
|
69
|
-
@project.rails_secret_key_base = 'abc'
|
70
|
-
variables = RubyYacht.configuration.find_server_type(:rails).environment_variables
|
71
|
-
variable = variables.find { |v| v[:name] == 'SECRET_KEY_BASE' }
|
72
|
-
|
73
|
-
expect(variable).not_to be_nil
|
74
|
-
expect(variable[:image]).to eq :app
|
75
|
-
expect(instance_eval(&variable[:block])).to eq 'abc'
|
76
|
-
end
|
77
|
-
|
78
|
-
it "sets an environment variable for the EXCLUDED_GEM_GROUPS" do
|
79
|
-
@project = RubyYacht::Project.new
|
80
|
-
@project.rails_excluded_gem_groups = %w(assets doc)
|
81
|
-
variables = RubyYacht.configuration.find_server_type(:rails).environment_variables
|
82
|
-
variable = variables.find { |v| v[:name] == 'EXCLUDED_GEM_GROUPS' }
|
83
|
-
|
84
|
-
expect(variable).not_to be_nil
|
85
|
-
expect(variable[:image]).to eq :app_dependencies
|
86
|
-
expect(instance_eval(&variable[:block])).to eq 'assets doc'
|
87
|
-
end
|
88
|
-
|
89
|
-
context "with no gem groups excluded" do
|
90
|
-
it "sets an empty string for the EXCLUDED_GEM_GROUPS environment variable" do
|
91
|
-
@project = RubyYacht::Project.new
|
92
|
-
@project.rails_excluded_gem_groups = []
|
93
|
-
variables = RubyYacht.configuration.find_server_type(:rails).environment_variables
|
94
|
-
variable = variables.find { |v| v[:name] == 'EXCLUDED_GEM_GROUPS' }
|
95
|
-
|
96
|
-
expect(variable).not_to be_nil
|
97
|
-
expect(variable[:image]).to eq :app_dependencies
|
98
|
-
expect(instance_eval(&variable[:block])).to eq '""'
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
it "creates a during-install-libraries hook for installing the gems" do
|
103
|
-
hooks = RubyYacht.configuration.fetch_hooks(event_time: :during, event_type: :install_libraries)
|
104
|
-
expect(hooks.count).to eq 1
|
105
|
-
expect(hooks[0].command).to eq '/var/docker/install_gems.rb'
|
106
|
-
expect(hooks[0].server_type).to eq :rails
|
107
|
-
end
|
108
|
-
|
109
|
-
it "creates an after-build-checkout hook for cleaning the gems" do
|
110
|
-
hooks = RubyYacht.configuration.fetch_hooks(event_time: :after, event_type: :build_checkout)
|
111
|
-
expect(hooks.count).to eq 1
|
112
|
-
expect(hooks[0].command).to eq 'bundle install --clean'
|
113
|
-
expect(hooks[0].server_type).to eq :rails
|
114
|
-
end
|
115
|
-
|
116
|
-
it "creates a during-load-seeds hook for loading the seeds" do
|
117
|
-
hooks = RubyYacht.configuration.fetch_hooks(event_time: :during, event_type: :load_database_seeds)
|
118
|
-
expect(hooks.count).to eq 1
|
119
|
-
expect(hooks[0].command).to eq '/var/docker/load_seeds.rb'
|
120
|
-
expect(hooks[0].server_type).to eq :rails
|
121
|
-
end
|
122
|
-
|
123
|
-
it "creates before-startup hooks for updating the config and preparing the app for launch" do
|
124
|
-
hooks = RubyYacht.configuration.fetch_hooks(event_time: :before, event_type: :startup)
|
125
|
-
expect(hooks.count).to eq 2
|
126
|
-
expect(hooks[0].command).to eq '/var/docker/update_rails_config.rb'
|
127
|
-
expect(hooks[0].server_type).to eq :rails
|
128
|
-
expect(hooks[1].command).to eq '/var/docker/prepare_rails_for_launch.rb'
|
129
|
-
expect(hooks[1].server_type).to eq :rails
|
130
|
-
end
|
131
|
-
|
132
|
-
it "creates a during-startup hook for starting the server" do
|
133
|
-
hooks = RubyYacht.configuration.fetch_hooks(event_time: :during, event_type: :startup)
|
134
|
-
expect(hooks.count).to eq 1
|
135
|
-
expect(hooks[0].command).to eq 'rails s -b 0.0.0.0 -p $APP_PORT -e $RAILS_ENV'
|
136
|
-
expect(hooks[0].server_type).to eq :rails
|
137
|
-
end
|
138
|
-
|
139
67
|
describe "building images" do
|
140
68
|
subject { RubyYacht::Runner::BuildImages.new }
|
141
69
|
include DockerCommandSpec
|
@@ -149,12 +77,15 @@ describe RubyYacht::Plugins::Rails do
|
|
149
77
|
container_type :database
|
150
78
|
baseline_image 'ubuntu'
|
151
79
|
end
|
80
|
+
server_type :nginx do
|
81
|
+
container_type :web
|
82
|
+
baseline_image 'ubuntu'
|
83
|
+
end
|
152
84
|
end
|
153
85
|
|
154
86
|
RubyYacht.configure do
|
155
87
|
project :apollo do
|
156
88
|
system_prefix :apollo
|
157
|
-
domain "apollo.test.com"
|
158
89
|
repository "github.com"
|
159
90
|
rails_secret_key_base 'abc'
|
160
91
|
|
@@ -162,6 +93,7 @@ describe RubyYacht::Plugins::Rails do
|
|
162
93
|
host "db.test.com"
|
163
94
|
username "apollo"
|
164
95
|
password "test"
|
96
|
+
port 1234
|
165
97
|
end
|
166
98
|
|
167
99
|
rails_app :mars do
|
@@ -173,6 +105,10 @@ describe RubyYacht::Plugins::Rails do
|
|
173
105
|
repository_name 'brownleej/saturn'
|
174
106
|
database_name :apollo
|
175
107
|
end
|
108
|
+
|
109
|
+
nginx_web_server do
|
110
|
+
domain 'apollo.test.com'
|
111
|
+
end
|
176
112
|
end
|
177
113
|
end
|
178
114
|
end
|
@@ -190,7 +126,7 @@ describe RubyYacht::Plugins::Rails do
|
|
190
126
|
it "generates the dockerfile for the app dependencies" do
|
191
127
|
docker.expect("build -t apollo-rails-app-dependencies tmp") do
|
192
128
|
files = Dir[File.join("tmp", "*")].sort
|
193
|
-
expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/install_gems.rb']
|
129
|
+
expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/id_rsa', 'tmp/install_gems.rb']
|
194
130
|
dockerfile = File.read(File.join('tmp', 'Dockerfile'))
|
195
131
|
expected = File.read(File.join('spec', 'fixtures', 'app-dependencies-dockerfile-rails'))
|
196
132
|
expect(dockerfile).to eq expected
|
@@ -201,7 +137,7 @@ describe RubyYacht::Plugins::Rails do
|
|
201
137
|
it "generates the dockerfiles for the apps" do
|
202
138
|
docker.expect("build -t apollo-mars tmp") do
|
203
139
|
files = Dir[File.join("tmp", "*")].sort
|
204
|
-
expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/before_startup.bash', 'tmp/before_startup.bash.erb', 'tmp/checkout.bash', 'tmp/prepare_rails_for_launch.rb', 'tmp/startup.bash', 'tmp/startup.bash.erb', 'tmp/update_rails_config.rb']
|
140
|
+
expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/before_startup.bash', 'tmp/before_startup.bash.erb', 'tmp/build_new_app.rb', 'tmp/checkout.bash', 'tmp/prepare_rails_for_launch.rb', 'tmp/startup.bash', 'tmp/startup.bash.erb', 'tmp/update_rails_config.rb']
|
205
141
|
dockerfile = File.read(File.join('tmp', 'Dockerfile'))
|
206
142
|
expected = File.read(File.join('spec', 'fixtures', 'mars-dockerfile-rails'))
|
207
143
|
expect(dockerfile).to eq expected
|
@@ -230,7 +166,7 @@ describe RubyYacht::Plugins::Rails do
|
|
230
166
|
it "generates the dockerfiles for the web server" do
|
231
167
|
docker.expect "build -t apollo-web tmp" do
|
232
168
|
files = Dir[File.join("tmp", "*")].sort
|
233
|
-
expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb'
|
169
|
+
expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb']
|
234
170
|
dockerfile = File.read(File.join('tmp', 'Dockerfile'))
|
235
171
|
expected = File.read(File.join('spec', 'fixtures', 'web-dockerfile'))
|
236
172
|
expect(dockerfile).to eq expected
|
@@ -246,7 +182,7 @@ describe RubyYacht::Plugins::Rails do
|
|
246
182
|
it "generates the dockerfiles for the database server" do
|
247
183
|
docker.expect "build -t apollo-database tmp" do
|
248
184
|
files = Dir[File.join("tmp", "*")].sort
|
249
|
-
expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/checkout.bash', 'tmp/
|
185
|
+
expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/checkout.bash', 'tmp/load_seeds.rb', 'tmp/startup.bash', 'tmp/startup.bash.erb']
|
250
186
|
dockerfile = File.read(File.join('tmp', 'Dockerfile'))
|
251
187
|
expected = File.read(File.join('spec', 'fixtures', 'database-dockerfile-rails'))
|
252
188
|
expect(dockerfile).to eq expected
|
@@ -254,5 +190,41 @@ describe RubyYacht::Plugins::Rails do
|
|
254
190
|
subject.run
|
255
191
|
end
|
256
192
|
end
|
193
|
+
|
194
|
+
context "with no repository" do
|
195
|
+
before do
|
196
|
+
RubyYacht.configuration.projects.first.apps.first.repository_name = nil
|
197
|
+
RubyYacht.configuration.projects.first.databases.first.host = 'localhost'
|
198
|
+
end
|
199
|
+
|
200
|
+
it "generates the dockerfiles for the app server" do
|
201
|
+
docker.expect "build -t apollo-mars tmp" do
|
202
|
+
files = Dir[File.join("tmp", "*")].sort
|
203
|
+
expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/before_startup.bash', 'tmp/before_startup.bash.erb', 'tmp/build_new_app.rb', 'tmp/checkout.bash', 'tmp/prepare_rails_for_launch.rb', 'tmp/startup.bash', 'tmp/startup.bash.erb', 'tmp/update_rails_config.rb']
|
204
|
+
file = File.read(File.join('tmp', 'Dockerfile'))
|
205
|
+
expected = File.read(File.join('spec', 'fixtures', 'mars-dockerfile-rails-with-no-repository'))
|
206
|
+
expect(file).to eq expected
|
207
|
+
end
|
208
|
+
subject.run
|
209
|
+
end
|
210
|
+
|
211
|
+
it "generates the startup script for the app server" do
|
212
|
+
docker.expect "build -t apollo-mars tmp" do
|
213
|
+
file = File.read(File.join('tmp', 'startup.bash'))
|
214
|
+
expected = File.read(File.join('spec', 'fixtures', 'mars-startup-rails-with-no-repository'))
|
215
|
+
expect(file).to eq expected
|
216
|
+
end
|
217
|
+
subject.run
|
218
|
+
end
|
219
|
+
|
220
|
+
it "generates a dockerfile for the database server" do
|
221
|
+
docker.expect "build -t apollo-database tmp" do
|
222
|
+
file = File.read(File.join('tmp', 'Dockerfile'))
|
223
|
+
expected = File.read(File.join('spec', 'fixtures', 'database-dockerfile-rails-with-no-repository'))
|
224
|
+
expect(file).to eq expected
|
225
|
+
end
|
226
|
+
subject.run
|
227
|
+
end
|
228
|
+
end
|
257
229
|
end
|
258
230
|
end
|
@@ -16,14 +16,14 @@ describe RubyYacht::Runner::BuildImages do
|
|
16
16
|
docker.expect "build -t apollo-debian-app-dependencies tmp"
|
17
17
|
docker.expect "build -t apollo-mars tmp"
|
18
18
|
docker.expect "build -t apollo-saturn tmp"
|
19
|
-
docker.expect "build -t apollo-
|
19
|
+
docker.expect "build -t apollo-nginx tmp"
|
20
20
|
subject.run
|
21
21
|
end
|
22
22
|
|
23
23
|
it "generates the dockerfile for the app dependencies" do
|
24
24
|
docker.expect("build -t apollo-generic-app-dependencies tmp") do
|
25
25
|
files = Dir[File.join("tmp", "*")].sort
|
26
|
-
expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb']
|
26
|
+
expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/id_rsa']
|
27
27
|
dockerfile = File.read(File.join('tmp', 'Dockerfile'))
|
28
28
|
expected = File.read(File.join('spec', 'fixtures', 'app-dependencies-dockerfile-generic'))
|
29
29
|
expect(dockerfile).to eq expected
|
@@ -61,9 +61,9 @@ describe RubyYacht::Runner::BuildImages do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
it "generates the dockerfiles for the web server" do
|
64
|
-
docker.expect "build -t apollo-
|
64
|
+
docker.expect "build -t apollo-nginx tmp" do
|
65
65
|
files = Dir[File.join("tmp", "*")].sort
|
66
|
-
expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb'
|
66
|
+
expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb']
|
67
67
|
dockerfile = File.read(File.join('tmp', 'Dockerfile'))
|
68
68
|
expected = File.read(File.join('spec', 'fixtures', 'web-dockerfile'))
|
69
69
|
expect(dockerfile).to eq expected
|
@@ -90,6 +90,7 @@ describe RubyYacht::Runner::BuildImages do
|
|
90
90
|
database.container_label = 'mysql'
|
91
91
|
database.username = 'apollo'
|
92
92
|
database.password = 'test'
|
93
|
+
database.port = 1234
|
93
94
|
database.host = 'localhost'
|
94
95
|
RubyYacht.configuration.projects.first.databases << database
|
95
96
|
RubyYacht.configuration.projects.first.apps.first.database_name = 'apollo'
|
@@ -127,8 +128,8 @@ describe RubyYacht::Runner::BuildImages do
|
|
127
128
|
before do
|
128
129
|
script_folder = self.script_folder
|
129
130
|
RubyYacht.configure do
|
130
|
-
add_hooks
|
131
|
-
during(:load_database_seeds) { run_script 'hook1.rb' }
|
131
|
+
add_hooks script_folder: script_folder, container_type: :database do
|
132
|
+
during(:load_database_seeds) { run_script :ruby, 'hook1.rb' }
|
132
133
|
end
|
133
134
|
end
|
134
135
|
end
|
@@ -161,6 +162,7 @@ describe RubyYacht::Runner::BuildImages do
|
|
161
162
|
database.username = 'apollo'
|
162
163
|
database.password = 'test'
|
163
164
|
database.host = 'db1.test.com'
|
165
|
+
database.port = 3306
|
164
166
|
RubyYacht.configuration.projects.first.databases << database
|
165
167
|
RubyYacht.configuration.projects.first.apps.first.database_name = 'apollo'
|
166
168
|
end
|
@@ -183,43 +185,10 @@ describe RubyYacht::Runner::BuildImages do
|
|
183
185
|
docker.expect "build -t apollo-debian-app-dependencies tmp"
|
184
186
|
docker.expect "build -t apollo-mars tmp"
|
185
187
|
docker.expect "build -t apollo-saturn tmp"
|
186
|
-
docker.expect "build -t apollo-
|
188
|
+
docker.expect "build -t apollo-nginx tmp"
|
187
189
|
subject.run
|
188
190
|
end
|
189
191
|
end
|
190
|
-
|
191
|
-
context "with an id_rsa key" do
|
192
|
-
let(:id_file_path) { File.join(ENV['HOME'], '.ssh', 'id_rsa') }
|
193
|
-
let(:missing_id_file) { !File.exist?(id_file_path) }
|
194
|
-
before do
|
195
|
-
if missing_id_file
|
196
|
-
FileUtils.mkdir_p(File.dirname(id_file_path))
|
197
|
-
File.open(id_file_path, 'w') do |file|
|
198
|
-
file.write('test')
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
it "copies the id_rsa key to the app-dependencies container" do
|
204
|
-
docker.expect "build -t apollo-generic-app-dependencies tmp" do
|
205
|
-
files = Dir[File.join("tmp", "*")].sort
|
206
|
-
expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/id_rsa']
|
207
|
-
expect(File.read('tmp/id_rsa')).to eq File.read(id_file_path)
|
208
|
-
end
|
209
|
-
|
210
|
-
subject.run
|
211
|
-
end
|
212
|
-
|
213
|
-
it "returns true" do
|
214
|
-
expect(subject.run).to be_truthy
|
215
|
-
end
|
216
|
-
|
217
|
-
after do
|
218
|
-
if missing_id_file
|
219
|
-
FileUtils.rm(id_file_path)
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end
|
223
192
|
|
224
193
|
context "with an app set up as the primary app" do
|
225
194
|
before do
|
@@ -227,9 +196,9 @@ describe RubyYacht::Runner::BuildImages do
|
|
227
196
|
end
|
228
197
|
|
229
198
|
it "includes that app as the primary in the web server dockerfile" do
|
230
|
-
docker.expect "build -t apollo-
|
199
|
+
docker.expect "build -t apollo-nginx tmp" do
|
231
200
|
files = Dir[File.join("tmp", "*")].sort
|
232
|
-
expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb'
|
201
|
+
expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb']
|
233
202
|
dockerfile = File.read(File.join('tmp', 'Dockerfile'))
|
234
203
|
expected = File.read(File.join('spec', 'fixtures', 'web-dockerfile-with-primary-app'))
|
235
204
|
expect(dockerfile).to eq expected
|
@@ -250,14 +219,14 @@ describe RubyYacht::Runner::BuildImages do
|
|
250
219
|
docker.expect "build -t apollo-debian-app-dependencies tmp"
|
251
220
|
docker.expect "build -t apollo tmp"
|
252
221
|
docker.expect "build -t apollo-saturn tmp"
|
253
|
-
docker.expect "build -t apollo-
|
222
|
+
docker.expect "build -t apollo-nginx tmp"
|
254
223
|
subject.run
|
255
224
|
end
|
256
225
|
|
257
226
|
it "includes that app as the primary in the web server dockerfile" do
|
258
|
-
docker.expect "build -t apollo-
|
227
|
+
docker.expect "build -t apollo-nginx tmp" do
|
259
228
|
files = Dir[File.join("tmp", "*")].sort
|
260
|
-
expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb'
|
229
|
+
expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb']
|
261
230
|
dockerfile = File.read(File.join('tmp', 'Dockerfile'))
|
262
231
|
expected = File.read(File.join('spec', 'fixtures', 'web-dockerfile-with-eponymous-app'))
|
263
232
|
expect(dockerfile).to eq expected
|
@@ -278,19 +247,31 @@ describe RubyYacht::Runner::BuildImages do
|
|
278
247
|
docker.expect "build -t apollo-debian-app-dependencies tmp"
|
279
248
|
docker.expect "build -t apollo-mars tmp"
|
280
249
|
docker.expect "build -t apollo-saturn tmp"
|
250
|
+
docker.expect "build -t apollo-nginx tmp"
|
281
251
|
docker.expect "build -t jupiter-debian-app-dependencies tmp"
|
282
252
|
docker.expect "build -t jupiter-venus tmp"
|
283
253
|
docker.expect "build -t jupiter-saturn tmp"
|
284
|
-
docker.expect "build -t
|
254
|
+
docker.expect "build -t jupiter-web tmp"
|
285
255
|
subject.run
|
286
256
|
end
|
287
257
|
|
288
|
-
it "generates
|
289
|
-
docker.expect "build -t apollo-
|
258
|
+
it "generates a normal dockerfile for the first project's web server" do
|
259
|
+
docker.expect "build -t apollo-nginx tmp" do
|
290
260
|
files = Dir[File.join("tmp", "*")].sort
|
291
|
-
expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb'
|
261
|
+
expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb']
|
292
262
|
dockerfile = File.read(File.join('tmp', 'Dockerfile'))
|
293
|
-
expected = File.read(File.join('spec', 'fixtures', '
|
263
|
+
expected = File.read(File.join('spec', 'fixtures', 'web-dockerfile'))
|
264
|
+
expect(dockerfile).to eq expected
|
265
|
+
end
|
266
|
+
subject.run
|
267
|
+
end
|
268
|
+
|
269
|
+
it "generates a dockerfile for the second project's web server" do
|
270
|
+
docker.expect "build -t jupiter-web tmp" do
|
271
|
+
files = Dir[File.join("tmp", "*")].sort
|
272
|
+
expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb']
|
273
|
+
dockerfile = File.read(File.join('tmp', 'Dockerfile'))
|
274
|
+
expected = File.read(File.join('spec', 'fixtures', 'web-dockerfile-jupiter'))
|
294
275
|
expect(dockerfile).to eq expected
|
295
276
|
end
|
296
277
|
subject.run
|
@@ -306,9 +287,9 @@ describe RubyYacht::Runner::BuildImages do
|
|
306
287
|
before do
|
307
288
|
script_folder = self.script_folder
|
308
289
|
RubyYacht.configure do
|
309
|
-
add_hooks
|
310
|
-
before(:startup) { run_script 'hook1.rb' }
|
311
|
-
before(:startup) { run_script 'hook2.rb' }
|
290
|
+
add_hooks script_folder: script_folder, container_type: :app do
|
291
|
+
before(:startup) { run_script :ruby, 'hook1.rb' }
|
292
|
+
before(:startup) { run_script :ruby, 'hook2.rb' }
|
312
293
|
end
|
313
294
|
end
|
314
295
|
end
|
@@ -346,8 +327,8 @@ describe RubyYacht::Runner::BuildImages do
|
|
346
327
|
before do
|
347
328
|
script_folder = self.script_folder
|
348
329
|
RubyYacht.configure do
|
349
|
-
add_hooks
|
350
|
-
after(:build_checkout) { run_script 'hook1.rb' }
|
330
|
+
add_hooks script_folder: script_folder, container_type: :app do
|
331
|
+
after(:build_checkout) { run_script :ruby, 'hook1.rb' }
|
351
332
|
end
|
352
333
|
end
|
353
334
|
end
|
@@ -384,8 +365,8 @@ describe RubyYacht::Runner::BuildImages do
|
|
384
365
|
before do
|
385
366
|
script_folder = self.script_folder
|
386
367
|
RubyYacht.configure do
|
387
|
-
add_hooks
|
388
|
-
during(:install_libraries) { run_script 'hook2.rb' }
|
368
|
+
add_hooks script_folder: script_folder, container_type: :app do
|
369
|
+
during(:install_libraries) { run_script :ruby, 'hook2.rb' }
|
389
370
|
end
|
390
371
|
end
|
391
372
|
end
|
@@ -422,7 +403,7 @@ describe RubyYacht::Runner::BuildImages do
|
|
422
403
|
before do
|
423
404
|
script_folder = self.script_folder
|
424
405
|
RubyYacht.configure do
|
425
|
-
add_hooks
|
406
|
+
add_hooks script_folder: script_folder, container_type: :app do
|
426
407
|
before :startup do
|
427
408
|
copy_file "hook1.rb"
|
428
409
|
command "cp /var/docker/hook1.rb /var/code/scripts/hook1.rb"
|
@@ -457,5 +438,77 @@ describe RubyYacht::Runner::BuildImages do
|
|
457
438
|
subject.run
|
458
439
|
end
|
459
440
|
end
|
441
|
+
|
442
|
+
context "with an app with no repository" do
|
443
|
+
before do
|
444
|
+
RubyYacht.configuration.projects[0].apps[0].repository_name = nil
|
445
|
+
RubyYacht.configure do
|
446
|
+
during :build_new_app do
|
447
|
+
container_type :app
|
448
|
+
command 'touch /var/code/app.bash'
|
449
|
+
end
|
450
|
+
end
|
451
|
+
end
|
452
|
+
|
453
|
+
it "builds a dependencies dockerfile that does not include that app" do
|
454
|
+
docker.expect("build -t apollo-generic-app-dependencies tmp") do
|
455
|
+
dockerfile = File.read(File.join('tmp', 'Dockerfile'))
|
456
|
+
expected = File.read(File.join('spec', 'fixtures', 'app-dependencies-dockerfile-with-no-repository'))
|
457
|
+
expect(dockerfile).to eq expected
|
458
|
+
end
|
459
|
+
subject.run
|
460
|
+
end
|
461
|
+
|
462
|
+
it "builds a dockerfile for that app that does not check it out" do
|
463
|
+
docker.expect("build -t apollo-mars tmp") do
|
464
|
+
dockerfile = File.read(File.join('tmp', 'Dockerfile'))
|
465
|
+
expected = File.read(File.join('spec', 'fixtures', 'mars-dockerfile-with-no-repository'))
|
466
|
+
expect(dockerfile).to eq expected
|
467
|
+
end
|
468
|
+
subject.run
|
469
|
+
end
|
470
|
+
|
471
|
+
it "builds a before-startup script for the app that does not check out the app" do
|
472
|
+
docker.expect("build -t apollo-mars tmp") do
|
473
|
+
file = File.read(File.join('tmp', 'before_startup.bash'))
|
474
|
+
expected = File.read(File.join('spec', 'fixtures', 'mars-before-startup-with-no-repository'))
|
475
|
+
expect(file).to eq expected
|
476
|
+
end
|
477
|
+
subject.run
|
478
|
+
end
|
479
|
+
|
480
|
+
it "builds a startup script for the app that creates the app before starting it" do
|
481
|
+
docker.expect("build -t apollo-mars tmp") do
|
482
|
+
file = File.read(File.join('tmp', 'startup.bash'))
|
483
|
+
expected = File.read(File.join('spec', 'fixtures', 'mars-startup-with-no-repository'))
|
484
|
+
expect(file).to eq expected
|
485
|
+
end
|
486
|
+
subject.run
|
487
|
+
end
|
488
|
+
end
|
489
|
+
end
|
490
|
+
|
491
|
+
describe 'helper methods' do
|
492
|
+
describe 'set_image_settings' do
|
493
|
+
context 'with an app folder' do
|
494
|
+
it 'sets the templates, hook events, and hook servers' do
|
495
|
+
app = RubyYacht::App.new
|
496
|
+
subject.instance_eval { @app = app }
|
497
|
+
subject.set_image_settings('app')
|
498
|
+
expect(subject.instance_eval { @templates }).to eq ['Dockerfile', 'before_startup.bash', 'startup.bash']
|
499
|
+
expect(subject.instance_eval { @hook_events }).to eq [:startup, :build_checkout, :build_new_app]
|
500
|
+
expect(subject.instance_eval { @hook_servers }).to eq [app]
|
501
|
+
end
|
502
|
+
end
|
503
|
+
|
504
|
+
context 'with an invalid folder' do
|
505
|
+
it 'sets the templates, hook events, and hook servers' do
|
506
|
+
subject.set_image_settings('invalid')
|
507
|
+
expect(subject.instance_eval { @templates }).to eq ['Dockerfile']
|
508
|
+
expect(subject.instance_eval { @hook_events }).to eq []
|
509
|
+
expect(subject.instance_eval { @hook_servers }).to eq []
|
510
|
+
end
|
511
|
+
end
|
512
|
+
end
|
460
513
|
end
|
461
514
|
end
|