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
@@ -10,7 +10,7 @@ describe RubyYacht::Configuration do
|
|
10
10
|
describe "fetch_hooks" do
|
11
11
|
before do
|
12
12
|
RubyYacht.configure do
|
13
|
-
server_type :
|
13
|
+
server_type :django do
|
14
14
|
container_type :app
|
15
15
|
baseline_image 'ubuntu'
|
16
16
|
end
|
@@ -18,31 +18,231 @@ describe RubyYacht::Configuration do
|
|
18
18
|
container_type :app
|
19
19
|
baseline_image 'ubuntu'
|
20
20
|
end
|
21
|
+
|
22
|
+
server_type :postgres do
|
23
|
+
container_type :database
|
24
|
+
baseline_image 'ubuntu'
|
25
|
+
end
|
26
|
+
server_type :mongo do
|
27
|
+
container_type :database
|
28
|
+
baseline_image 'ubuntu'
|
29
|
+
end
|
30
|
+
|
31
|
+
server_type :nginx do
|
32
|
+
container_type :web
|
33
|
+
baseline_image 'ubuntu'
|
34
|
+
end
|
35
|
+
|
36
|
+
server_type :apache do
|
37
|
+
container_type :web
|
38
|
+
baseline_image 'ubuntu'
|
39
|
+
end
|
21
40
|
end
|
22
41
|
|
23
42
|
RubyYacht.configure do
|
24
|
-
add_hooks
|
25
|
-
before
|
26
|
-
|
43
|
+
add_hooks container_type: :app, app_server_type: :django, database_server_type: :postgres, script_folder: '.' do
|
44
|
+
before :startup do
|
45
|
+
run_script :bash, 'app-a.bash'
|
46
|
+
end
|
47
|
+
|
48
|
+
before :install_libraries do
|
49
|
+
run_script :bash, 'app-b.bash'
|
50
|
+
end
|
51
|
+
|
52
|
+
before :startup do
|
53
|
+
app_server_type :php
|
54
|
+
run_script :bash, 'app-c.bash'
|
55
|
+
end
|
56
|
+
|
57
|
+
before :startup do
|
58
|
+
database_server_type :mongo
|
59
|
+
run_script :bash, 'app-d.bash'
|
60
|
+
end
|
61
|
+
|
62
|
+
before :startup do
|
63
|
+
database_server_type :all
|
64
|
+
run_script :bash, 'app-e.bash'
|
65
|
+
end
|
66
|
+
|
67
|
+
before :startup do
|
68
|
+
app_server_type :all
|
69
|
+
run_script :bash, 'app-f.bash'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
add_hooks container_type: :database, app_server_type: :django, database_server_type: :postgres, script_folder: '.' do
|
74
|
+
before :startup do
|
75
|
+
run_script :bash, 'database-a.bash'
|
76
|
+
end
|
77
|
+
|
78
|
+
before :install_libraries do
|
79
|
+
run_script :bash, 'database-b.bash'
|
80
|
+
end
|
27
81
|
|
28
82
|
before :startup do
|
29
|
-
|
30
|
-
run_script 'c.
|
83
|
+
database_server_type :mongo
|
84
|
+
run_script :bash, 'database-c.bash'
|
85
|
+
end
|
86
|
+
|
87
|
+
before :startup do
|
88
|
+
app_server_type :php
|
89
|
+
run_script :bash, 'database-d.bash'
|
31
90
|
end
|
32
91
|
|
33
92
|
before :startup do
|
34
|
-
|
35
|
-
run_script '
|
93
|
+
app_server_type :all
|
94
|
+
run_script :bash, 'database-e.bash'
|
95
|
+
end
|
96
|
+
|
97
|
+
before :startup do
|
98
|
+
database_server_type :all
|
99
|
+
run_script :bash, 'database-f.bash'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
add_hooks container_type: :web, web_server_type: :nginx, script_folder: '.' do
|
104
|
+
before :startup do
|
105
|
+
run_script :bash, 'web-a.bash'
|
106
|
+
end
|
107
|
+
|
108
|
+
before :startup do
|
109
|
+
web_server_type :all
|
110
|
+
run_script :bash, 'web-b.bash'
|
111
|
+
end
|
112
|
+
|
113
|
+
before :startup do
|
114
|
+
web_server_type :apache
|
115
|
+
run_script :bash, 'web-c.bash'
|
116
|
+
end
|
117
|
+
|
118
|
+
before :install_libraries do
|
119
|
+
run_script :bash, 'web-d.bash'
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
RubyYacht.configure do
|
125
|
+
project :test_project do
|
126
|
+
repository 'github.com'
|
127
|
+
system_prefix :test_project
|
128
|
+
|
129
|
+
postgres_database :db1 do
|
130
|
+
host :localhost
|
131
|
+
username 'test'
|
132
|
+
password 'test'
|
133
|
+
port 5432
|
134
|
+
end
|
135
|
+
|
136
|
+
mongo_database :db2 do
|
137
|
+
host :localhost
|
138
|
+
username 'test'
|
139
|
+
password 'test'
|
140
|
+
port 27017
|
141
|
+
end
|
142
|
+
|
143
|
+
django_app :app1 do
|
144
|
+
database_name :db1
|
145
|
+
repository_name 'test/app1'
|
146
|
+
end
|
147
|
+
|
148
|
+
php_app :app2 do
|
149
|
+
database_name :db2
|
150
|
+
repository_name 'test/app2'
|
151
|
+
end
|
152
|
+
|
153
|
+
nginx_web_server do
|
154
|
+
domain 'test.com'
|
36
155
|
end
|
37
156
|
end
|
38
157
|
end
|
39
158
|
end
|
40
159
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
160
|
+
let(:hooks) { RubyYacht.configuration.fetch_hooks(server, :startup) }
|
161
|
+
let(:filenames) { hooks.collect { |hook| File.basename(hook.behaviors.first.file_path) } }
|
162
|
+
|
163
|
+
context "with an app" do
|
164
|
+
let(:server) { RubyYacht.configuration.projects.first.apps.first }
|
165
|
+
it "finds hooks for that app" do
|
166
|
+
expect(filenames).to include 'app-a.bash'
|
167
|
+
end
|
168
|
+
|
169
|
+
it "finds hooks for all apps" do
|
170
|
+
expect(filenames).to include 'app-f.bash'
|
171
|
+
end
|
172
|
+
|
173
|
+
it "does not find hooks for other apps" do
|
174
|
+
expect(filenames).not_to include 'app-c.bash'
|
175
|
+
end
|
176
|
+
|
177
|
+
it "finds hooks for all databases for that app" do
|
178
|
+
expect(filenames).to include 'app-e.bash'
|
179
|
+
end
|
180
|
+
|
181
|
+
it "does not find hooks for other databases for that app" do
|
182
|
+
expect(filenames).not_to include 'app-d.bash'
|
183
|
+
end
|
184
|
+
|
185
|
+
it "does not find hooks for other events" do
|
186
|
+
expect(filenames).not_to include 'app-b.bash'
|
187
|
+
end
|
188
|
+
|
189
|
+
it "does not find hooks for database containers" do
|
190
|
+
expect(filenames).not_to include 'database-a.bash'
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
context "with a database" do
|
195
|
+
let(:server) { RubyYacht.configuration.projects.first.databases.first }
|
196
|
+
|
197
|
+
it "finds hooks for that databases" do
|
198
|
+
expect(filenames).to include 'database-a.bash'
|
199
|
+
end
|
200
|
+
|
201
|
+
it "finds hooks for all databases" do
|
202
|
+
expect(filenames).to include 'database-f.bash'
|
203
|
+
end
|
204
|
+
|
205
|
+
it "does not find hooks for other databases" do
|
206
|
+
expect(filenames).not_to include 'database-c.bash'
|
207
|
+
end
|
208
|
+
|
209
|
+
it "finds hooks for all apps for that database" do
|
210
|
+
expect(filenames).to include 'database-e.bash'
|
211
|
+
end
|
212
|
+
|
213
|
+
it "does not find hooks for other apps for that database" do
|
214
|
+
expect(filenames).not_to include 'database-d.bash'
|
215
|
+
end
|
216
|
+
|
217
|
+
it "does not find hooks for other events" do
|
218
|
+
expect(filenames).not_to include 'database-b.bash'
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
context 'with a web server' do
|
223
|
+
let(:server) { RubyYacht.configuration.projects.first.web_servers.first }
|
224
|
+
|
225
|
+
it "finds hooks for that type" do
|
226
|
+
expect(filenames).to include 'web-a.bash'
|
227
|
+
end
|
228
|
+
|
229
|
+
it "finds hooks for all types" do
|
230
|
+
expect(filenames).to include 'web-b.bash'
|
231
|
+
end
|
232
|
+
|
233
|
+
it "does not find hooks for other types" do
|
234
|
+
expect(filenames).not_to include 'web-c.bash'
|
235
|
+
end
|
236
|
+
|
237
|
+
it "does not find hooks for other events" do
|
238
|
+
expect(filenames).not_to include 'web-d.bash'
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
context "with an invalid type" do
|
243
|
+
it "is an empty array" do
|
244
|
+
expect(RubyYacht.configuration.fetch_hooks(:test, :startup)).to eq []
|
245
|
+
end
|
46
246
|
end
|
47
247
|
end
|
48
248
|
|
@@ -73,13 +273,11 @@ describe RubyYacht::Configuration do
|
|
73
273
|
Proc.new do
|
74
274
|
project :project1 do
|
75
275
|
system_prefix :a
|
76
|
-
domain "a.test.com"
|
77
276
|
repository "github.com"
|
78
277
|
end
|
79
278
|
|
80
279
|
project :project2 do
|
81
280
|
system_prefix :b
|
82
|
-
domain "b.test.com"
|
83
281
|
repository "github.com"
|
84
282
|
end
|
85
283
|
end
|
@@ -87,9 +285,9 @@ describe RubyYacht::Configuration do
|
|
87
285
|
|
88
286
|
let(:hook_creation_block) do
|
89
287
|
Proc.new do
|
90
|
-
add_hooks
|
288
|
+
add_hooks container_type: :app, app_server_type: :configuration_test, script_folder: './scripts' do
|
91
289
|
before :startup do
|
92
|
-
run_script 'update_config.rb'
|
290
|
+
run_script :ruby, 'update_config.rb'
|
93
291
|
end
|
94
292
|
end
|
95
293
|
end
|
@@ -111,6 +309,10 @@ describe RubyYacht::Configuration do
|
|
111
309
|
container_type :app
|
112
310
|
baseline_image 'ubuntu'
|
113
311
|
end
|
312
|
+
server_type :configuration_test_db do
|
313
|
+
container_type :database
|
314
|
+
baseline_image 'ubuntu'
|
315
|
+
end
|
114
316
|
end
|
115
317
|
end
|
116
318
|
|
@@ -126,10 +328,10 @@ describe RubyYacht::Configuration do
|
|
126
328
|
expect(configuration.hooks.count).to eq 1
|
127
329
|
expect(configuration.hooks[0].event_time).to eq :before
|
128
330
|
expect(configuration.hooks[0].event_type).to eq :startup
|
129
|
-
expect(configuration.hooks[0].
|
331
|
+
expect(configuration.hooks[0].behaviors.first.file_path).to eq './scripts/update_config.rb'
|
130
332
|
end
|
131
333
|
|
132
|
-
it "can server types" do
|
334
|
+
it "can add server types" do
|
133
335
|
configuration = RubyYacht::Configuration::DSL.new.run(server_type_creation_block).create_object
|
134
336
|
expect(configuration.server_types.count).to eq 1
|
135
337
|
expect(configuration.server_types[0].name).to eq :second_configuration_test
|
@@ -139,30 +341,36 @@ describe RubyYacht::Configuration do
|
|
139
341
|
|
140
342
|
it "can add `during` hooks" do
|
141
343
|
configuration = RubyYacht::Configuration::DSL.new.run(Proc.new do
|
142
|
-
add_hooks
|
344
|
+
add_hooks container_type: :app, app_server_type: :configuration_test, script_folder: './scripts' do
|
143
345
|
during :startup do
|
144
|
-
run_script 'start_app.rb'
|
346
|
+
run_script :ruby, 'start_app.rb'
|
145
347
|
end
|
146
348
|
end
|
147
349
|
end).create_object
|
148
350
|
expect(configuration.hooks.count).to eq 1
|
149
351
|
expect(configuration.hooks[0].event_time).to eq :during
|
150
352
|
expect(configuration.hooks[0].event_type).to eq :startup
|
151
|
-
expect(configuration.hooks[0].
|
353
|
+
expect(configuration.hooks[0].app_server_type).to eq :configuration_test
|
354
|
+
expect(configuration.hooks[0].database_server_type).to eq :all
|
355
|
+
expect(configuration.hooks[0].container_type).to eq :app
|
356
|
+
expect(configuration.hooks[0].behaviors.first.file_path).to eq './scripts/start_app.rb'
|
152
357
|
end
|
153
358
|
|
154
359
|
it "can add `after` hooks" do
|
155
360
|
configuration = RubyYacht::Configuration::DSL.new.run(Proc.new do
|
156
|
-
add_hooks
|
361
|
+
add_hooks container_type: :database, database_server_type: :configuration_test_db, script_folder: './scripts' do
|
157
362
|
after :startup do
|
158
|
-
run_script 'start_app.rb'
|
363
|
+
run_script :ruby, 'start_app.rb'
|
159
364
|
end
|
160
365
|
end
|
161
366
|
end).create_object
|
162
367
|
expect(configuration.hooks.count).to eq 1
|
163
368
|
expect(configuration.hooks[0].event_time).to eq :after
|
164
369
|
expect(configuration.hooks[0].event_type).to eq :startup
|
165
|
-
expect(configuration.hooks[0].
|
370
|
+
expect(configuration.hooks[0].app_server_type).to eq :all
|
371
|
+
expect(configuration.hooks[0].database_server_type).to eq :configuration_test_db
|
372
|
+
expect(configuration.hooks[0].container_type).to eq :database
|
373
|
+
expect(configuration.hooks[0].behaviors.first.file_path).to eq './scripts/start_app.rb'
|
166
374
|
end
|
167
375
|
|
168
376
|
describe "configure method" do
|
@@ -183,23 +391,21 @@ describe RubyYacht::Configuration do
|
|
183
391
|
hook = RubyYacht::Hook.new
|
184
392
|
hook.event_time = :after
|
185
393
|
hook.event_type = :restart_application
|
186
|
-
hook.copied_file_path = './scripts/log_success.rb'
|
187
394
|
RubyYacht.configuration.hooks << hook
|
188
395
|
RubyYacht.configure(&hook_creation_block)
|
189
396
|
|
190
397
|
configuration = RubyYacht.configuration
|
191
398
|
expect(configuration.hooks.count).to eq 2
|
192
|
-
expect(configuration.hooks[0].copied_file_path).to eq './scripts/log_success.rb'
|
193
|
-
expect(configuration.hooks[1].copied_file_path).to eq './scripts/update_config.rb'
|
194
399
|
end
|
195
400
|
|
196
401
|
it "adds to the list of server types" do
|
197
402
|
RubyYacht.configure(&server_type_creation_block)
|
198
403
|
|
199
404
|
configuration = RubyYacht.configuration
|
200
|
-
expect(configuration.server_types.count).to eq
|
405
|
+
expect(configuration.server_types.count).to eq 3
|
201
406
|
expect(configuration.server_types[0].name).to eq :configuration_test
|
202
|
-
expect(configuration.server_types[1].name).to eq :
|
407
|
+
expect(configuration.server_types[1].name).to eq :configuration_test_db
|
408
|
+
expect(configuration.server_types[2].name).to eq :second_configuration_test
|
203
409
|
end
|
204
410
|
|
205
411
|
context "with a server type that is already registered" do
|
data/spec/dsl/database_spec.rb
CHANGED
@@ -12,13 +12,14 @@ describe RubyYacht::Database do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "dsl" do
|
15
|
-
let(:database) { RubyYacht::Database::DSL.new(:
|
15
|
+
let(:database) { RubyYacht::Database::DSL.new(:sqlite, :apps).run(@builder).create_object }
|
16
16
|
|
17
17
|
it "creates a database with all the fields" do
|
18
18
|
@builder = Proc.new do
|
19
19
|
host 'db1.test.com'
|
20
20
|
username 'test-user'
|
21
21
|
password 'test-pass'
|
22
|
+
port 1237
|
22
23
|
container_label :database
|
23
24
|
end
|
24
25
|
|
@@ -27,6 +28,7 @@ describe RubyYacht::Database do
|
|
27
28
|
expect(database.server_type).to eq :sqlite
|
28
29
|
expect(database.username).to eq 'test-user'
|
29
30
|
expect(database.password).to eq 'test-pass'
|
31
|
+
expect(database.port).to eq 1237
|
30
32
|
expect(database.container_label).to eq :database
|
31
33
|
end
|
32
34
|
|
@@ -34,6 +36,7 @@ describe RubyYacht::Database do
|
|
34
36
|
@builder = Proc.new do
|
35
37
|
username 'test-user'
|
36
38
|
password 'test-pass'
|
39
|
+
port 1237
|
37
40
|
container_label :database
|
38
41
|
end
|
39
42
|
|
@@ -44,6 +47,7 @@ describe RubyYacht::Database do
|
|
44
47
|
@builder = Proc.new do
|
45
48
|
host 'db1.test.com'
|
46
49
|
password 'test-pass'
|
50
|
+
port 1237
|
47
51
|
container_label :database
|
48
52
|
end
|
49
53
|
|
@@ -54,6 +58,7 @@ describe RubyYacht::Database do
|
|
54
58
|
@builder = Proc.new do
|
55
59
|
host 'db1.test.com'
|
56
60
|
username 'test-user'
|
61
|
+
port 1237
|
57
62
|
container_label :database
|
58
63
|
end
|
59
64
|
|
@@ -65,6 +70,7 @@ describe RubyYacht::Database do
|
|
65
70
|
host 'db1.test.com'
|
66
71
|
username 'test-user'
|
67
72
|
password 'test-pass'
|
73
|
+
port 1237
|
68
74
|
end
|
69
75
|
|
70
76
|
expect(database.container_label).to eq :database
|
@@ -75,11 +81,12 @@ describe RubyYacht::Database do
|
|
75
81
|
host 'db1.test.com'
|
76
82
|
username 'test-user'
|
77
83
|
password 'test-pass'
|
84
|
+
port 1237
|
78
85
|
container_label :database
|
79
86
|
server_type :invalid
|
80
87
|
end
|
81
88
|
|
82
|
-
expect { database }.to raise_exception "Database has invalid server type `invalid`"
|
89
|
+
expect { database }.to raise_exception "RubyYacht::Database::DSL has invalid database server type `invalid`"
|
83
90
|
end
|
84
91
|
|
85
92
|
it "requires a defined server type for a database" do
|
@@ -94,11 +101,12 @@ describe RubyYacht::Database do
|
|
94
101
|
host 'db1.test.com'
|
95
102
|
username 'test-user'
|
96
103
|
password 'test-pass'
|
104
|
+
port 1237
|
97
105
|
container_label :database
|
98
106
|
server_type :generic
|
99
107
|
end
|
100
108
|
|
101
|
-
expect { database }.to raise_exception "Database has invalid server type `generic`"
|
109
|
+
expect { database }.to raise_exception "RubyYacht::Database::DSL has invalid database server type `generic`"
|
102
110
|
end
|
103
111
|
end
|
104
112
|
|
@@ -116,6 +124,94 @@ describe RubyYacht::Database do
|
|
116
124
|
end
|
117
125
|
end
|
118
126
|
|
127
|
+
describe 'project' do
|
128
|
+
before do
|
129
|
+
RubyYacht.configuration.clear
|
130
|
+
RubyYacht.configure do
|
131
|
+
server_type :test do
|
132
|
+
container_type :database
|
133
|
+
baseline_image 'ubuntu'
|
134
|
+
end
|
135
|
+
end
|
136
|
+
RubyYacht.configure do
|
137
|
+
project :project1 do
|
138
|
+
repository 'github.com'
|
139
|
+
system_prefix :project1
|
140
|
+
|
141
|
+
test_database :db1 do
|
142
|
+
host :localhost
|
143
|
+
username :test
|
144
|
+
password :test
|
145
|
+
port 1237
|
146
|
+
end
|
147
|
+
|
148
|
+
test_database :db2 do
|
149
|
+
host :localhost
|
150
|
+
username :test
|
151
|
+
password :test
|
152
|
+
port 1237
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
project :project2 do
|
157
|
+
repository 'github.com'
|
158
|
+
system_prefix :project2
|
159
|
+
|
160
|
+
test_database :db3 do
|
161
|
+
host :localhost
|
162
|
+
username :test
|
163
|
+
password :test
|
164
|
+
port 1237
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'finds the project that contains the apps' do
|
171
|
+
db2 = RubyYacht.configuration.projects[0].databases[1]
|
172
|
+
db3 = RubyYacht.configuration.projects[1].databases[0]
|
173
|
+
|
174
|
+
expect(db2.project.name).to eq :project1
|
175
|
+
expect(db3.project.name).to eq :project2
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe 'apps' do
|
180
|
+
before do
|
181
|
+
@project = RubyYacht::Project.new
|
182
|
+
@project.name = :test_project
|
183
|
+
@project.system_prefix = :tests
|
184
|
+
|
185
|
+
@database = RubyYacht::Database.new
|
186
|
+
@database.name = :db1
|
187
|
+
@database.container_label = 'mysql'
|
188
|
+
|
189
|
+
@project.databases = [@database]
|
190
|
+
@project.apps = []
|
191
|
+
|
192
|
+
app = RubyYacht::App.new
|
193
|
+
app.name = :app1
|
194
|
+
app.database_name = :db1
|
195
|
+
@project.apps << app
|
196
|
+
|
197
|
+
app = RubyYacht::App.new
|
198
|
+
app.name = :app2
|
199
|
+
app.database_name = :db1
|
200
|
+
@project.apps << app
|
201
|
+
|
202
|
+
app = RubyYacht::App.new
|
203
|
+
app.name = :app3
|
204
|
+
app.database_name = :db2
|
205
|
+
@project.apps << app
|
206
|
+
|
207
|
+
RubyYacht.configuration.projects << @project
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'is the apps from the project that have the same database name' do
|
211
|
+
expect(@database.apps.map(&:name)).to eq [:app1, :app2]
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
119
215
|
describe "container_name" do
|
120
216
|
before do
|
121
217
|
@project = RubyYacht::Project.new
|
@@ -124,10 +220,13 @@ describe RubyYacht::Database do
|
|
124
220
|
|
125
221
|
@database = RubyYacht::Database.new
|
126
222
|
@database.container_label = 'mysql'
|
223
|
+
|
224
|
+
@project.databases = [@database]
|
225
|
+
RubyYacht.configuration.projects << @project
|
127
226
|
end
|
128
227
|
|
129
228
|
it "combines the project's prefix with the database's container label" do
|
130
|
-
expect(@database.container_name
|
229
|
+
expect(@database.container_name).to eq 'tests-mysql'
|
131
230
|
end
|
132
231
|
end
|
133
232
|
end
|
data/spec/dsl/dsl_spec.rb
CHANGED
@@ -32,6 +32,7 @@ module DSLTestHelpers
|
|
32
32
|
include RubyYacht::DSL::Base
|
33
33
|
end
|
34
34
|
end
|
35
|
+
|
35
36
|
describe RubyYacht::DSL::Base do
|
36
37
|
let(:DSL) { DSLTestHelpers::DSL }
|
37
38
|
let(:SecondDSL) { DSLTestHelpers::SecondDSL }
|
@@ -49,7 +50,7 @@ describe RubyYacht::DSL::Base do
|
|
49
50
|
|
50
51
|
describe "add_generic_attribute" do
|
51
52
|
it "adds the attribute to the list" do
|
52
|
-
DSLTestHelpers::DSL.add_generic_attribute :namify, :name do |
|
53
|
+
DSLTestHelpers::DSL.add_generic_attribute :namify, :name do |_|
|
53
54
|
end
|
54
55
|
|
55
56
|
expect(DSLTestHelpers::DSL.all_attributes).to eq [:name]
|
@@ -70,7 +71,7 @@ describe RubyYacht::DSL::Base do
|
|
70
71
|
end
|
71
72
|
|
72
73
|
it "can accept optional fields" do
|
73
|
-
DSLTestHelpers::DSL.add_generic_attribute :namify, :name, nil, false do |
|
74
|
+
DSLTestHelpers::DSL.add_generic_attribute :namify, :name, nil, false do |_|
|
74
75
|
end
|
75
76
|
|
76
77
|
expect(DSLTestHelpers::DSL.all_attributes).to eq [:name]
|
@@ -78,7 +79,7 @@ describe RubyYacht::DSL::Base do
|
|
78
79
|
end
|
79
80
|
|
80
81
|
it "can accept fields with default values" do
|
81
|
-
DSLTestHelpers::DSL.add_generic_attribute :namify, :name, 'hello' do |
|
82
|
+
DSLTestHelpers::DSL.add_generic_attribute :namify, :name, 'hello' do |_|
|
82
83
|
end
|
83
84
|
|
84
85
|
expect(DSLTestHelpers::DSL.all_attributes).to eq [:name]
|
@@ -185,6 +186,24 @@ describe RubyYacht::DSL::Base do
|
|
185
186
|
DSLTestHelpers::DSL.add_object :thing, DSLTestHelpers::SecondDSL, required: false
|
186
187
|
expect(DSLTestHelpers::DSL.required_attributes).to eq []
|
187
188
|
end
|
189
|
+
|
190
|
+
context 'with no required attributes on the second DSL' do
|
191
|
+
before do
|
192
|
+
DSLTestHelpers::SecondDSL.clear
|
193
|
+
DSLTestHelpers::SecondDSL.add_attribute :name, 'Jim'
|
194
|
+
DSLTestHelpers::SecondDSL.creates_object DSLTestHelpers::ThingOne
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'allows created objects with no block' do
|
198
|
+
dsl = run_dsl do
|
199
|
+
thing
|
200
|
+
end
|
201
|
+
|
202
|
+
thing = dsl.instance_eval { @thing }
|
203
|
+
expect(thing).to be_a DSLTestHelpers::ThingOne
|
204
|
+
expect(thing.name).to eq 'Jim'
|
205
|
+
end
|
206
|
+
end
|
188
207
|
end
|
189
208
|
|
190
209
|
describe "add_object_list" do
|
@@ -217,6 +236,30 @@ describe RubyYacht::DSL::Base do
|
|
217
236
|
dsl = run_dsl {}
|
218
237
|
expect(dsl.instance_eval { @things }).to eq []
|
219
238
|
end
|
239
|
+
|
240
|
+
context 'with no required attributes on the second DSL' do
|
241
|
+
before do
|
242
|
+
DSLTestHelpers::SecondDSL.clear
|
243
|
+
DSLTestHelpers::SecondDSL.add_attribute :name, 'Jim'
|
244
|
+
DSLTestHelpers::SecondDSL.creates_object DSLTestHelpers::ThingOne
|
245
|
+
end
|
246
|
+
|
247
|
+
it 'allows created objects with no block' do
|
248
|
+
dsl = run_dsl do
|
249
|
+
thing do
|
250
|
+
name 'Charlie'
|
251
|
+
end
|
252
|
+
thing
|
253
|
+
end
|
254
|
+
|
255
|
+
things = dsl.instance_eval { @things }
|
256
|
+
expect(things.count).to eq 2
|
257
|
+
expect(things[0]).to be_a DSLTestHelpers::ThingOne
|
258
|
+
expect(things[0].name).to eq 'Charlie'
|
259
|
+
expect(things[1]).to be_a DSLTestHelpers::ThingOne
|
260
|
+
expect(things[1].name).to eq 'Jim'
|
261
|
+
end
|
262
|
+
end
|
220
263
|
end
|
221
264
|
|
222
265
|
describe "creates_object" do
|