ruby_yacht 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile.lock +1 -1
  3. data/doc/TODO.md +16 -6
  4. data/doc/configuration_sample.rb +8 -9
  5. data/lib/ruby_yacht/dsl/app.rb +29 -1
  6. data/lib/ruby_yacht/dsl/app_type.rb +112 -0
  7. data/lib/ruby_yacht/dsl/configuration.rb +163 -2
  8. data/lib/ruby_yacht/dsl/dsl.rb +51 -9
  9. data/lib/ruby_yacht/dsl/hook.rb +105 -0
  10. data/lib/ruby_yacht/dsl/project.rb +17 -21
  11. data/lib/ruby_yacht/dsl.rb +2 -0
  12. data/lib/ruby_yacht/images/app/Dockerfile.erb +20 -13
  13. data/lib/ruby_yacht/images/app/before_startup.bash.erb +8 -0
  14. data/lib/ruby_yacht/images/app/checkout.bash +6 -0
  15. data/lib/ruby_yacht/images/app/startup.bash.erb +5 -0
  16. data/lib/ruby_yacht/images/app-dependencies/Dockerfile.erb +23 -5
  17. data/lib/ruby_yacht/images/database/Dockerfile.erb +25 -11
  18. data/lib/ruby_yacht/images/database/checkout.bash +10 -0
  19. data/lib/ruby_yacht/images/database/setup.bash +15 -0
  20. data/lib/ruby_yacht/images/web/Dockerfile.erb +4 -3
  21. data/lib/ruby_yacht/plugins/rails/scripts/install_gems.rb +3 -0
  22. data/lib/ruby_yacht/plugins/rails/scripts/load_seeds.rb +34 -0
  23. data/lib/ruby_yacht/{images/app/startup.rb → plugins/rails/scripts/prepare_rails_for_launch.rb} +2 -8
  24. data/lib/ruby_yacht/{images/app/update_database_config.rb → plugins/rails/scripts/update_rails_config.rb} +0 -1
  25. data/lib/ruby_yacht/plugins/rails.rb +40 -0
  26. data/lib/ruby_yacht/plugins.rb +6 -0
  27. data/lib/ruby_yacht/runner/build_images.rb +72 -5
  28. data/lib/ruby_yacht/runner/checkout.rb +1 -1
  29. data/lib/ruby_yacht.rb +2 -1
  30. data/ruby_yacht.gemspec +2 -1
  31. data/spec/docker/Dockerfile +1 -1
  32. data/spec/dsl/app_spec.rb +34 -0
  33. data/spec/dsl/app_type_spec.rb +176 -0
  34. data/spec/dsl/configuration_spec.rb +161 -2
  35. data/spec/dsl/dsl_spec.rb +3 -3
  36. data/spec/dsl/hook_spec.rb +111 -0
  37. data/spec/dsl/project_spec.rb +19 -83
  38. data/spec/fixtures/app-dependencies-dockerfile-generic +21 -0
  39. data/spec/fixtures/app-dependencies-dockerfile-generic-with-library-install +28 -0
  40. data/spec/fixtures/app-dependencies-dockerfile-rails +32 -0
  41. data/spec/fixtures/database-dockerfile +16 -15
  42. data/spec/fixtures/database-dockerfile-rails +35 -0
  43. data/spec/fixtures/database-dockerfile-with-seed-hooks +34 -0
  44. data/spec/fixtures/hooks/hook1.rb +0 -0
  45. data/spec/fixtures/hooks/hook2.rb +0 -0
  46. data/spec/fixtures/mars-before-startup +4 -0
  47. data/spec/fixtures/mars-before-startup-rails +7 -0
  48. data/spec/fixtures/mars-before-startup-with-before-startup-hooks +7 -0
  49. data/spec/fixtures/mars-dockerfile +9 -14
  50. data/spec/fixtures/mars-dockerfile-rails +33 -0
  51. data/spec/fixtures/mars-dockerfile-with-after-checkout-hooks +30 -0
  52. data/spec/fixtures/mars-dockerfile-with-before-startup-hooks +29 -0
  53. data/spec/fixtures/mars-startup +3 -0
  54. data/spec/fixtures/mars-startup-rails +3 -0
  55. data/spec/fixtures/multi-project-web-dockerfile +0 -10
  56. data/spec/fixtures/web-dockerfile +0 -6
  57. data/spec/plugins/rails_spec.rb +198 -0
  58. data/spec/runner/build_images_spec.rb +181 -15
  59. data/spec/runner/checkout_spec.rb +2 -2
  60. data/spec/support/test_project.rb +16 -8
  61. metadata +62 -30
  62. data/lib/ruby_yacht/images/app/checkout.rb +0 -7
  63. data/lib/ruby_yacht/images/app-dependencies/install_gems.rb +0 -12
  64. data/lib/ruby_yacht/images/database/load_seeds.rb +0 -42
  65. data/lib/ruby_yacht/images/database/setup.rb +0 -19
  66. data/lib/ruby_yacht/images/database/setup_database.sql.erb +0 -12
  67. data/spec/fixtures/app-dependencies-dockerfile +0 -25
@@ -0,0 +1,198 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyYacht::Plugins::Rails do
4
+ before do
5
+ RubyYacht.configuration.clear
6
+ described_class.load
7
+ end
8
+
9
+ it "adds rails to the app type list" do
10
+ expect(RubyYacht.configuration.app_types.map(&:name)).to include :rails
11
+ end
12
+
13
+ it "adds attributes for the rails environment and secret key" do
14
+ RubyYacht.configure do
15
+ project :test_project do
16
+ system_prefix :test_project
17
+ domain 'test.com'
18
+ repository 'github.com'
19
+ rails_secret_key_base 'abc'
20
+
21
+ database do
22
+ host 'localhost'
23
+ name 'test'
24
+ password 'test'
25
+ username 'test'
26
+ end
27
+ end
28
+ end
29
+
30
+ project = RubyYacht.configuration.projects.last
31
+ expect(project.rails_environment).to eq 'development'
32
+ expect(project.rails_secret_key_base).to eq 'abc'
33
+ end
34
+
35
+ it "sets environment variables for the RAILS_ENV and SECRET_KEY_BASE" do
36
+ @project = RubyYacht::Project.new
37
+ @project.rails_environment = 'development'
38
+ @project.rails_secret_key_base = 'abc'
39
+ variables = RubyYacht.configuration.find_app_type(:rails).environment_variables
40
+
41
+ expect(variables.count).to eq 2
42
+ expect(variables[0][:name]).to eq 'RAILS_ENV'
43
+ expect(variables[0][:image]).to eq :app
44
+ expect(instance_eval(&variables[0][:block])).to eq 'development'
45
+ expect(variables[1][:name]).to eq 'SECRET_KEY_BASE'
46
+ expect(variables[1][:image]).to eq :app
47
+ expect(instance_eval(&variables[1][:block])).to eq 'abc'
48
+ end
49
+
50
+ it "creates a during-install-libraries hook for cleaning the gems" do
51
+ hooks = RubyYacht.configuration.fetch_hooks(event_time: :during, event_type: :install_libraries)
52
+ expect(hooks.count).to eq 1
53
+ expect(hooks[0].command).to eq '/var/docker/install_gems.rb'
54
+ expect(hooks[0].app_type).to eq :rails
55
+ end
56
+
57
+ it "creates an after-build-checkout hook for cleaning the gems" do
58
+ hooks = RubyYacht.configuration.fetch_hooks(event_time: :after, event_type: :build_checkout)
59
+ expect(hooks.count).to eq 1
60
+ expect(hooks[0].command).to eq 'bundle install && bundle clean --force'
61
+ expect(hooks[0].app_type).to eq :rails
62
+ end
63
+
64
+ it "creates a during-load-seeds hook for loading the seeds" do
65
+ hooks = RubyYacht.configuration.fetch_hooks(event_time: :during, event_type: :load_database_seeds)
66
+ expect(hooks.count).to eq 1
67
+ expect(hooks[0].command).to eq '/var/docker/load_seeds.rb'
68
+ expect(hooks[0].app_type).to eq :rails
69
+ end
70
+
71
+ it "creates before-startup hooks for updating the config and preparing the app for launch" do
72
+ hooks = RubyYacht.configuration.fetch_hooks(event_time: :before, event_type: :startup)
73
+ expect(hooks.count).to eq 2
74
+ expect(hooks[0].command).to eq '/var/docker/update_rails_config.rb'
75
+ expect(hooks[0].app_type).to eq :rails
76
+ expect(hooks[1].command).to eq '/var/docker/prepare_rails_for_launch.rb'
77
+ expect(hooks[1].app_type).to eq :rails
78
+ end
79
+
80
+ it "creates a during-startup hook for starting the server" do
81
+ hooks = RubyYacht.configuration.fetch_hooks(event_time: :during, event_type: :startup)
82
+ expect(hooks.count).to eq 1
83
+ expect(hooks[0].command).to eq 'rails s -b 0.0.0.0 -p $APP_PORT -e $RAILS_ENV'
84
+ expect(hooks[0].app_type).to eq :rails
85
+ end
86
+
87
+ describe "building images" do
88
+ subject { RubyYacht::Runner::BuildImages.new }
89
+ include DockerCommandSpec
90
+
91
+ before do
92
+ RubyYacht.configuration.clear
93
+ described_class.load
94
+
95
+ RubyYacht.configure do
96
+ project :apollo do
97
+ system_prefix :apollo
98
+ domain "apollo.test.com"
99
+ repository "github.com"
100
+ rails_secret_key_base 'abc'
101
+
102
+ database do
103
+ host "db.test.com"
104
+ name "apollo"
105
+ username "apollo"
106
+ password "test"
107
+ end
108
+
109
+ rails_app :mars do
110
+ repository_name 'brownleej/mars'
111
+ end
112
+
113
+ rails_app :saturn do
114
+ repository_name 'brownleej/saturn'
115
+ end
116
+ end
117
+ end
118
+ end
119
+
120
+ it "builds all the images for the project" do
121
+ docker.fail_unexpected_commands!
122
+ docker.expect "network create apollo 2> /dev/null"
123
+ docker.expect "build -t apollo-rails-app-dependencies tmp"
124
+ docker.expect "build -t apollo-mars tmp"
125
+ docker.expect "build -t apollo-saturn tmp"
126
+ docker.expect "build -t apollo-web tmp"
127
+ subject.run
128
+ end
129
+
130
+ it "generates the dockerfile for the app dependencies" do
131
+ docker.expect("build -t apollo-rails-app-dependencies tmp") do
132
+ files = Dir[File.join("tmp", "*")].sort
133
+ expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/install_gems.rb']
134
+ dockerfile = File.read(File.join('tmp', 'Dockerfile'))
135
+ expected = File.read(File.join('spec', 'fixtures', 'app-dependencies-dockerfile-rails'))
136
+ expect(dockerfile).to eq expected
137
+ end
138
+ subject.run
139
+ end
140
+
141
+ it "generates the dockerfiles for the apps" do
142
+ docker.expect("build -t apollo-mars tmp") do
143
+ files = Dir[File.join("tmp", "*")].sort
144
+ 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']
145
+ dockerfile = File.read(File.join('tmp', 'Dockerfile'))
146
+ expected = File.read(File.join('spec', 'fixtures', 'mars-dockerfile-rails'))
147
+ expect(dockerfile).to eq expected
148
+ end
149
+ subject.run
150
+ end
151
+
152
+ it "builds a startup file for the apps" do
153
+ docker.expect("build -t apollo-mars tmp") do
154
+ startup = File.read(File.join('tmp', 'startup.bash'))
155
+ expected = File.read(File.join('spec', 'fixtures', 'mars-startup-rails'))
156
+ expect(startup).to eq expected
157
+ end
158
+ subject.run
159
+ end
160
+
161
+ it "builds a before-startup file for the apps" do
162
+ docker.expect("build -t apollo-mars tmp") do
163
+ startup = File.read(File.join('tmp', 'before_startup.bash'))
164
+ expected = File.read(File.join('spec', 'fixtures', 'mars-before-startup-rails'))
165
+ expect(startup).to eq expected
166
+ end
167
+ subject.run
168
+ end
169
+
170
+ it "generates the dockerfiles for the web server" do
171
+ docker.expect "build -t apollo-web tmp" do
172
+ files = Dir[File.join("tmp", "*")].sort
173
+ 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', 'tmp/setup.rb']
174
+ dockerfile = File.read(File.join('tmp', 'Dockerfile'))
175
+ expected = File.read(File.join('spec', 'fixtures', 'web-dockerfile'))
176
+ expect(dockerfile).to eq expected
177
+ end
178
+ subject.run
179
+ end
180
+
181
+ context "with a local database" do
182
+ before do
183
+ RubyYacht.configuration.projects[0].database.host = 'localhost'
184
+ end
185
+
186
+ it "generates the dockerfiles for the database server" do
187
+ docker.expect "build -t apollo-database tmp" do
188
+ files = Dir[File.join("tmp", "*")].sort
189
+ expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/checkout.bash', 'tmp/load_seeds.rb', 'tmp/setup.bash']
190
+ dockerfile = File.read(File.join('tmp', 'Dockerfile'))
191
+ expected = File.read(File.join('spec', 'fixtures', 'database-dockerfile-rails'))
192
+ expect(dockerfile).to eq expected
193
+ end
194
+ subject.run
195
+ end
196
+ end
197
+ end
198
+ end
@@ -12,7 +12,8 @@ describe RubyYacht::Runner::BuildImages do
12
12
  it "builds all the images for the project" do
13
13
  docker.fail_unexpected_commands!
14
14
  docker.expect "network create apollo 2> /dev/null"
15
- docker.expect "build -t apollo-app-dependencies tmp"
15
+ docker.expect "build -t apollo-generic-app-dependencies tmp"
16
+ docker.expect "build -t apollo-debian-app-dependencies tmp"
16
17
  docker.expect "build -t apollo-mars tmp"
17
18
  docker.expect "build -t apollo-saturn tmp"
18
19
  docker.expect "build -t apollo-web tmp"
@@ -20,11 +21,11 @@ describe RubyYacht::Runner::BuildImages do
20
21
  end
21
22
 
22
23
  it "generates the dockerfile for the app dependencies" do
23
- docker.expect("build -t apollo-app-dependencies tmp") do
24
+ docker.expect("build -t apollo-generic-app-dependencies tmp") do
24
25
  files = Dir[File.join("tmp", "*")].sort
25
- expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/install_gems.rb']
26
+ expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb']
26
27
  dockerfile = File.read(File.join('tmp', 'Dockerfile'))
27
- expected = File.read(File.join('spec', 'fixtures', 'app-dependencies-dockerfile'))
28
+ expected = File.read(File.join('spec', 'fixtures', 'app-dependencies-dockerfile-generic'))
28
29
  expect(dockerfile).to eq expected
29
30
  end
30
31
  subject.run
@@ -33,13 +34,31 @@ describe RubyYacht::Runner::BuildImages do
33
34
  it "generates the dockerfiles for the apps" do
34
35
  docker.expect("build -t apollo-mars tmp") do
35
36
  files = Dir[File.join("tmp", "*")].sort
36
- expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/checkout.rb', 'tmp/startup.rb', 'tmp/update_database_config.rb']
37
+ expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/before_startup.bash', 'tmp/before_startup.bash.erb', 'tmp/checkout.bash', 'tmp/startup.bash', 'tmp/startup.bash.erb']
37
38
  dockerfile = File.read(File.join('tmp', 'Dockerfile'))
38
39
  expected = File.read(File.join('spec', 'fixtures', 'mars-dockerfile'))
39
40
  expect(dockerfile).to eq expected
40
41
  end
41
42
  subject.run
42
43
  end
44
+
45
+ it "builds a startup file for the apps" do
46
+ docker.expect("build -t apollo-mars tmp") do
47
+ startup = File.read(File.join('tmp', 'startup.bash'))
48
+ expected = File.read(File.join('spec', 'fixtures', 'mars-startup'))
49
+ expect(startup).to eq expected
50
+ end
51
+ subject.run
52
+ end
53
+
54
+ it "builds a before-startup file for the apps" do
55
+ docker.expect("build -t apollo-mars tmp") do
56
+ startup = File.read(File.join('tmp', 'before_startup.bash'))
57
+ expected = File.read(File.join('spec', 'fixtures', 'mars-before-startup'))
58
+ expect(startup).to eq expected
59
+ end
60
+ subject.run
61
+ end
43
62
 
44
63
  it "generates the dockerfiles for the web server" do
45
64
  docker.expect "build -t apollo-web tmp" do
@@ -63,11 +82,11 @@ describe RubyYacht::Runner::BuildImages do
63
82
 
64
83
  it "builds the database" do
65
84
  docker.expect("build -t apollo-database tmp") do
66
- files = Dir[File.join("tmp", "*")].sort
67
- expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/load_seeds.rb', 'tmp/setup.rb', 'tmp/setup_database.sql.erb']
68
- dockerfile = File.read(File.join('tmp', 'Dockerfile'))
69
- expected = File.read(File.join('spec', 'fixtures', 'database-dockerfile'))
70
- expect(dockerfile).to eq expected
85
+ files = Dir[File.join("tmp", "*")].sort
86
+ expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/checkout.bash','tmp/setup.bash']
87
+ dockerfile = File.read(File.join('tmp', 'Dockerfile'))
88
+ expected = File.read(File.join('spec', 'fixtures', 'database-dockerfile'))
89
+ expect(dockerfile).to eq expected
71
90
  end
72
91
  subject.run
73
92
  end
@@ -75,6 +94,36 @@ describe RubyYacht::Runner::BuildImages do
75
94
  it "returns true" do
76
95
  expect(subject.run).to be_truthy
77
96
  end
97
+
98
+ context "with a hook for loading the seeds" do
99
+ let(:script_folder) { File.join(File.dirname(File.dirname(__FILE__)), 'fixtures', 'hooks') }
100
+
101
+ before do
102
+ script_folder = self.script_folder
103
+ RubyYacht.configure do
104
+ add_hooks folder: script_folder, app_type: :generic do
105
+ during(:load_database_seeds) { run_script 'hook1.rb' }
106
+ end
107
+ end
108
+ end
109
+
110
+ it "copies the files for the hooks to the database" do
111
+ docker.expect("build -t apollo-database tmp") do
112
+ files = Dir[File.join("tmp", "*")].sort
113
+ expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/checkout.bash', 'tmp/hook1.rb', 'tmp/setup.bash']
114
+ end
115
+ subject.run
116
+ end
117
+
118
+ it "includes the scripts in the database dockerfile" do
119
+ docker.expect("build -t apollo-database tmp") do
120
+ dockerfile = File.read(File.join('tmp', 'Dockerfile'))
121
+ expected = File.read(File.join('spec', 'fixtures', 'database-dockerfile-with-seed-hooks'))
122
+ expect(dockerfile).to eq expected
123
+ end
124
+ subject.run
125
+ end
126
+ end
78
127
  end
79
128
 
80
129
  context "with an id_rsa key" do
@@ -90,9 +139,9 @@ describe RubyYacht::Runner::BuildImages do
90
139
  end
91
140
 
92
141
  it "copies the id_rsa key to the app-dependencies container" do
93
- docker.expect "build -t apollo-app-dependencies tmp" do
142
+ docker.expect "build -t apollo-generic-app-dependencies tmp" do
94
143
  files = Dir[File.join("tmp", "*")].sort
95
- expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/id_rsa', 'tmp/install_gems.rb']
144
+ expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/id_rsa']
96
145
  expect(File.read('tmp/id_rsa')).to eq File.read(id_file_path)
97
146
  end
98
147
 
@@ -135,10 +184,11 @@ describe RubyYacht::Runner::BuildImages do
135
184
  it "builds the containers for both projects" do
136
185
  docker.fail_unexpected_commands!
137
186
  docker.expect "network create apollo 2> /dev/null"
138
- docker.expect "build -t apollo-app-dependencies tmp"
187
+ docker.expect "build -t apollo-generic-app-dependencies tmp"
188
+ docker.expect "build -t apollo-debian-app-dependencies tmp"
139
189
  docker.expect "build -t apollo-mars tmp"
140
190
  docker.expect "build -t apollo-saturn tmp"
141
- docker.expect "build -t jupiter-app-dependencies tmp"
191
+ docker.expect "build -t jupiter-debian-app-dependencies tmp"
142
192
  docker.expect "build -t jupiter-venus tmp"
143
193
  docker.expect "build -t jupiter-saturn tmp"
144
194
  docker.expect "build -t apollo-web tmp"
@@ -160,5 +210,121 @@ describe RubyYacht::Runner::BuildImages do
160
210
  expect(subject.run).to be_truthy
161
211
  end
162
212
  end
213
+
214
+ context "with hooks before starting an app" do
215
+ let(:script_folder) { File.join(File.dirname(File.dirname(__FILE__)), 'fixtures', 'hooks') }
216
+ before do
217
+ script_folder = self.script_folder
218
+ RubyYacht.configure do
219
+ add_hooks folder: script_folder, app_type: :generic do
220
+ before(:startup) { run_script 'hook1.rb' }
221
+ before(:startup) { run_script 'hook2.rb' }
222
+ end
223
+ end
224
+ end
225
+
226
+ it "copies the scripts to the tmp directory" do
227
+ docker.expect("build -t apollo-mars tmp") do
228
+ files = Dir[File.join('tmp', '*')]
229
+ expect(files).to include 'tmp/hook1.rb'
230
+ expect(files).to include 'tmp/hook2.rb'
231
+ end
232
+ subject.run
233
+ end
234
+
235
+ it "builds a dockerfile that copies the scripts" do
236
+ docker.expect("build -t apollo-mars tmp") do
237
+ dockerfile = File.read(File.join('tmp', 'Dockerfile'))
238
+ expected = File.read(File.join('spec', 'fixtures', 'mars-dockerfile-with-before-startup-hooks'))
239
+ expect(dockerfile).to eq expected
240
+ end
241
+ subject.run
242
+ end
243
+
244
+ it "builds a before-startup file that runs the scripts" do
245
+ docker.expect("build -t apollo-mars tmp") do
246
+ startup = File.read(File.join('tmp', 'before_startup.bash'))
247
+ expected = File.read(File.join('spec', 'fixtures', 'mars-before-startup-with-before-startup-hooks'))
248
+ expect(startup).to eq expected
249
+ end
250
+ subject.run
251
+ end
252
+ end
253
+
254
+ context "with hooks after checking out an app" do
255
+ let(:script_folder) { File.join(File.dirname(File.dirname(__FILE__)), 'fixtures', 'hooks') }
256
+ before do
257
+ script_folder = self.script_folder
258
+ RubyYacht.configure do
259
+ add_hooks folder: script_folder, app_type: :generic do
260
+ after(:build_checkout) { run_script 'hook1.rb' }
261
+ end
262
+ end
263
+ end
264
+
265
+ it "copies the scripts to the tmp directory" do
266
+ docker.expect("build -t apollo-mars tmp") do
267
+ files = Dir[File.join('tmp', '*')]
268
+ expect(files).to include 'tmp/hook1.rb'
269
+ end
270
+ subject.run
271
+ end
272
+
273
+ it "builds a dockerfile that copies the scripts" do
274
+ docker.expect("build -t apollo-mars tmp") do
275
+ dockerfile = File.read(File.join('tmp', 'Dockerfile'))
276
+ expected = File.read(File.join('spec', 'fixtures', 'mars-dockerfile-with-after-checkout-hooks'))
277
+ expect(dockerfile).to eq expected
278
+ end
279
+ subject.run
280
+ end
281
+
282
+ it "builds a normal before-startup" do
283
+ docker.expect("build -t apollo-mars tmp") do
284
+ startup = File.read(File.join('tmp', 'before_startup.bash'))
285
+ expected = File.read(File.join('spec', 'fixtures', 'mars-before-startup'))
286
+ expect(startup).to eq expected
287
+ end
288
+ subject.run
289
+ end
290
+ end
291
+
292
+ context "with hooks for installing libraries for an app" do
293
+ let(:script_folder) { File.join(File.dirname(File.dirname(__FILE__)), 'fixtures', 'hooks') }
294
+ before do
295
+ script_folder = self.script_folder
296
+ RubyYacht.configure do
297
+ add_hooks folder: script_folder, app_type: :generic do
298
+ during(:install_libraries) { run_script 'hook2.rb' }
299
+ end
300
+ end
301
+ end
302
+
303
+ it "copies the scripts to the tmp directory" do
304
+ docker.expect("build -t apollo-generic-app-dependencies tmp") do
305
+ files = Dir[File.join('tmp', '*')]
306
+ expect(files).to include 'tmp/hook2.rb'
307
+ end
308
+ subject.run
309
+ end
310
+
311
+ it "builds a dependencies dockerfile that copies and runs he scripts" do
312
+ docker.expect("build -t apollo-generic-app-dependencies tmp") do
313
+ dockerfile = File.read(File.join('tmp', 'Dockerfile'))
314
+ expected = File.read(File.join('spec', 'fixtures', 'app-dependencies-dockerfile-generic-with-library-install'))
315
+ expect(dockerfile).to eq expected
316
+ end
317
+ subject.run
318
+ end
319
+
320
+ it "builds a normal before-startup" do
321
+ docker.expect("build -t apollo-mars tmp") do
322
+ startup = File.read(File.join('tmp', 'before_startup.bash'))
323
+ expected = File.read(File.join('spec', 'fixtures', 'mars-before-startup'))
324
+ expect(startup).to eq expected
325
+ end
326
+ subject.run
327
+ end
328
+ end
163
329
  end
164
- end
330
+ end
@@ -45,7 +45,7 @@ describe RubyYacht::Runner::Checkout do
45
45
  it "runs the commands to check out the branch and update the app" do
46
46
  docker.fail_unexpected_commands!
47
47
  docker.expect "exec apollo-saturn bash -c 'cd /var/code; git fetch; git checkout .; git checkout issue1234; git pull'"
48
- docker.expect "exec apollo-saturn bash -c '/var/docker/update_database_config.rb; rake db:migrate'"
48
+ docker.expect "exec apollo-saturn /var/docker/before_startup.bash"
49
49
  docker.expect "restart apollo-saturn"
50
50
  subject.run
51
51
  end
@@ -64,7 +64,7 @@ describe RubyYacht::Runner::Checkout do
64
64
  subject.app = 'venus'
65
65
  docker.fail_unexpected_commands!
66
66
  docker.expect "exec jupiter-venus bash -c 'cd /var/code; git fetch; git checkout .; git checkout issue1234; git pull'"
67
- docker.expect "exec jupiter-venus bash -c '/var/docker/update_database_config.rb; rake db:migrate'"
67
+ docker.expect "exec jupiter-venus /var/docker/before_startup.bash"
68
68
  docker.expect "restart jupiter-venus"
69
69
  subject.run
70
70
  end
@@ -1,6 +1,18 @@
1
1
  module RubyYacht
2
2
  def self.configure_test_project
3
3
  RubyYacht.configuration.clear
4
+ RubyYacht.configure do
5
+ app_type(:generic) { baseline_image 'ubuntu' }
6
+ app_type(:debian) { baseline_image 'debian' }
7
+ end
8
+
9
+ RubyYacht.configure do
10
+ during :startup do
11
+ app_type :generic
12
+ command '/var/docker/start_app.bash'
13
+ end
14
+ end
15
+
4
16
  RubyYacht.configure do
5
17
  project :apollo do
6
18
  system_prefix :apollo
@@ -14,15 +26,13 @@ module RubyYacht
14
26
  password "test"
15
27
  end
16
28
 
17
- app :mars do
29
+ generic_app :mars do
18
30
  repository_name 'brownleej/mars'
19
31
  end
20
32
 
21
- app :saturn do
33
+ debian_app :saturn do
22
34
  repository_name 'brownleej/saturn'
23
35
  end
24
-
25
- secret_key_base 'abc'
26
36
  end
27
37
  end
28
38
  end
@@ -41,15 +51,13 @@ module RubyYacht
41
51
  password "test"
42
52
  end
43
53
 
44
- app :venus do
54
+ debian_app :venus do
45
55
  repository_name 'brownleej/venus'
46
56
  end
47
57
 
48
- app :saturn do
58
+ debian_app :saturn do
49
59
  repository_name 'brownleej/saturn'
50
60
  end
51
-
52
- secret_key_base 'abc'
53
61
  end
54
62
  end
55
63
  end