ruby_yacht 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +7 -5
  4. data/doc/TODO.md +1 -5
  5. data/doc/configuration.md +51 -0
  6. data/doc/plugins.md +4 -0
  7. data/lib/ruby_yacht/dsl/configuration.rb +26 -1
  8. data/lib/ruby_yacht/dsl/dsl.rb +35 -3
  9. data/lib/ruby_yacht/dsl/hook.rb +4 -0
  10. data/lib/ruby_yacht/dsl/project.rb +11 -0
  11. data/lib/ruby_yacht/images/app/Dockerfile.erb +2 -1
  12. data/lib/ruby_yacht/images/app/checkout.bash +1 -1
  13. data/lib/ruby_yacht/images/app-dependencies/Dockerfile.erb +7 -1
  14. data/lib/ruby_yacht/images/database/Dockerfile.erb +3 -1
  15. data/lib/ruby_yacht/images/database/checkout.bash +3 -4
  16. data/lib/ruby_yacht/images/web/Dockerfile.erb +2 -0
  17. data/lib/ruby_yacht/plugins/nginx.rb +5 -0
  18. data/lib/ruby_yacht/plugins/rails/scripts/load_seeds.rb +10 -1
  19. data/lib/ruby_yacht/plugins/rails/scripts/prepare_rails_for_launch.rb +1 -1
  20. data/lib/ruby_yacht/plugins/rails/scripts/update_rails_config.rb +6 -4
  21. data/lib/ruby_yacht/plugins/rails.rb +30 -17
  22. data/lib/ruby_yacht/plugins.rb +1 -1
  23. data/lib/ruby_yacht/runner/build_images.rb +5 -7
  24. data/lib/ruby_yacht/runner/run_containers.rb +1 -2
  25. data/ruby_yacht.gemspec +2 -2
  26. data/spec/docker/run.bash +4 -0
  27. data/spec/dsl/configuration_spec.rb +29 -0
  28. data/spec/dsl/dsl_spec.rb +56 -0
  29. data/spec/dsl/hook_spec.rb +28 -5
  30. data/spec/dsl/project_spec.rb +46 -0
  31. data/spec/dsl/server_type_spec.rb +3 -0
  32. data/spec/fixtures/app-dependencies-dockerfile-generic +3 -1
  33. data/spec/fixtures/app-dependencies-dockerfile-generic-with-library-install +3 -1
  34. data/spec/fixtures/app-dependencies-dockerfile-rails +4 -3
  35. data/spec/fixtures/app-dependencies-dockerfile-rails-production +35 -0
  36. data/spec/fixtures/app-dependencies-dockerfile-with-https-repository +25 -0
  37. data/spec/fixtures/app-dependencies-dockerfile-with-no-repository +2 -0
  38. data/spec/fixtures/database-dockerfile +1 -1
  39. data/spec/fixtures/database-dockerfile-mysql +1 -1
  40. data/spec/fixtures/database-dockerfile-rails +2 -6
  41. data/spec/fixtures/database-dockerfile-rails-mysql +38 -0
  42. data/spec/fixtures/database-dockerfile-rails-with-no-repository +1 -3
  43. data/spec/fixtures/database-dockerfile-with-seed-hooks +1 -1
  44. data/spec/fixtures/local_config.yml +8 -0
  45. data/spec/fixtures/mars-dockerfile +0 -1
  46. data/spec/fixtures/mars-dockerfile-rails +0 -1
  47. data/spec/fixtures/mars-dockerfile-rails-with-no-repository +0 -1
  48. data/spec/fixtures/mars-dockerfile-with-after-checkout-hooks +0 -1
  49. data/spec/fixtures/mars-dockerfile-with-before-startup-hooks +0 -1
  50. data/spec/fixtures/mars-dockerfile-with-custom-file-copy +0 -1
  51. data/spec/fixtures/mars-dockerfile-with-local-database +0 -1
  52. data/spec/fixtures/mars-dockerfile-with-no-repository +0 -1
  53. data/spec/fixtures/mars-dockerfile-with-remote-database +0 -1
  54. data/spec/fixtures/mars-startup-rails +1 -1
  55. data/spec/fixtures/mars-startup-rails-with-no-repository +1 -1
  56. data/spec/fixtures/web-dockerfile-nginx +3 -0
  57. data/spec/integration/01_normal_config_spec.rb +352 -0
  58. data/spec/integration/{create_new_project_spec.rb → 02_creating_new_project_spec.rb} +2 -2
  59. data/spec/integration/03_no_repository_spec.rb +56 -0
  60. data/spec/integration/04_no_database_spec.rb +58 -0
  61. data/spec/integration/05_https_repository_spec.rb +52 -0
  62. data/spec/integration/06_production_environment_spec.rb +72 -0
  63. data/spec/integration/07_local_checkout_spec.rb +52 -0
  64. data/spec/integration/08_multiple_projects_spec.rb +46 -0
  65. data/spec/integration/09_titular_app_spec.rb +53 -0
  66. data/spec/integration/10_misc_scenarios_spec.rb +97 -0
  67. data/spec/integration/run.rb +18 -2
  68. data/spec/plugins/rails_spec.rb +73 -16
  69. data/spec/runner/build_images_spec.rb +17 -1
  70. data/spec/runner/run_containers_spec.rb +3 -3
  71. data/spec/support/integration_helpers.rb +18 -4
  72. metadata +30 -20
  73. data/spec/integration/build_images_spec.rb +0 -210
  74. data/spec/integration/build_spec.rb +0 -23
  75. data/spec/integration/checkout_spec.rb +0 -94
  76. data/spec/integration/implode_spec.rb +0 -20
  77. data/spec/integration/run_containers_spec.rb +0 -279
  78. data/spec/integration/services_spec.rb +0 -99
  79. data/spec/integration/shell_spec.rb +0 -31
  80. data/spec/integration/update_hosts_spec.rb +0 -35
@@ -1,10 +1,22 @@
1
1
  require 'ruby_yacht'
2
2
 
3
+ RubyYacht.configure do
4
+ add_local_config File.join(File.dirname(__FILE__), '..', 'fixtures', 'local_config.yml')
5
+ end
6
+
3
7
  RubyYacht.configure do
4
8
  project :apollo do
5
9
  system_prefix :apollo
6
10
  repository 'github.com'
11
+ if ENV['HTTPS_REPOSITORY'] == '1'
12
+ repository_protocol :https
13
+ end
14
+
7
15
  rails_secret_key_base 'c330d739b502b4c43f4a850c592798243c5e92b1828b4e1e69de764fbdf8e733e0165241c67a76f34a9a46b10d27960fa288149ac662ea6bd9408fdb766aea39'
16
+
17
+ if ENV['USE_LOCAL_CONFIG'] == '1'
18
+ copy_local_config :rails_environment
19
+ end
8
20
 
9
21
  if ENV['CHECK_OUT_LOCALLY'] == '1'
10
22
  check_out_locally
@@ -16,6 +28,10 @@ RubyYacht.configure do
16
28
  password 'testpass'
17
29
  host 'localhost'
18
30
 
31
+ if ENV['USE_LOCAL_CONFIG'] == '1'
32
+ copy_local_config :username, :password, :host, from: 'database'
33
+ end
34
+
19
35
  if ENV['USE_NONSTANDARD_MYSQL_PORT'] == '1'
20
36
  port 3333
21
37
  end
@@ -51,12 +67,12 @@ RubyYacht.configure do
51
67
  end
52
68
  end
53
69
 
54
- if ENV['USE_PRODUCTION_ENVIRONMENT']
70
+ if ENV['USE_PRODUCTION_ENVIRONMENT'] == '1'
55
71
  rails_environment 'production'
56
72
  rails_excluded_gem_groups %w(development test)
57
73
  end
58
74
 
59
- if ENV['CREATE_PRIMARY_APP']
75
+ if ENV['CREATE_PRIMARY_APP'] == '1'
60
76
  primary_app :mars
61
77
  end
62
78
  end
@@ -16,6 +16,8 @@ describe RubyYacht::Plugins::Rails do
16
16
  @database = RubyYacht::Database.new
17
17
  @database.name = :test_db
18
18
  @project.databases = [@database]
19
+
20
+ @project.web_servers = []
19
21
  end
20
22
 
21
23
  def configure_project(options = {})
@@ -68,21 +70,7 @@ describe RubyYacht::Plugins::Rails do
68
70
  subject { RubyYacht::Runner::BuildImages.new }
69
71
  include DockerCommandSpec
70
72
 
71
- before do
72
- RubyYacht.configuration.clear
73
- described_class.load
74
-
75
- RubyYacht.configure do
76
- server_type :sqlite do
77
- container_type :database
78
- baseline_image 'ubuntu'
79
- end
80
- server_type :nginx do
81
- container_type :web
82
- baseline_image 'ubuntu'
83
- end
84
- end
85
-
73
+ def configure_project
86
74
  RubyYacht.configure do
87
75
  project :apollo do
88
76
  system_prefix :apollo
@@ -112,6 +100,24 @@ describe RubyYacht::Plugins::Rails do
112
100
  end
113
101
  end
114
102
  end
103
+
104
+ before do
105
+ RubyYacht.configuration.clear
106
+ described_class.load
107
+
108
+ RubyYacht.configure do
109
+ server_type :sqlite do
110
+ container_type :database
111
+ baseline_image 'ubuntu'
112
+ end
113
+ server_type :nginx do
114
+ container_type :web
115
+ baseline_image 'ubuntu'
116
+ end
117
+ end
118
+
119
+ configure_project
120
+ end
115
121
 
116
122
  it "builds all the images for the project" do
117
123
  docker.fail_unexpected_commands!
@@ -182,7 +188,7 @@ describe RubyYacht::Plugins::Rails do
182
188
  it "generates the dockerfiles for the database server" do
183
189
  docker.expect "build -t apollo-database tmp" do
184
190
  files = Dir[File.join("tmp", "*")].sort
185
- expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/checkout.bash', 'tmp/load_seeds.rb', 'tmp/startup.bash', 'tmp/startup.bash.erb']
191
+ expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/checkout.bash', 'tmp/startup.bash', 'tmp/startup.bash.erb']
186
192
  dockerfile = File.read(File.join('tmp', 'Dockerfile'))
187
193
  expected = File.read(File.join('spec', 'fixtures', 'database-dockerfile-rails'))
188
194
  expect(dockerfile).to eq expected
@@ -191,6 +197,57 @@ describe RubyYacht::Plugins::Rails do
191
197
  end
192
198
  end
193
199
 
200
+ context "with a production app" do
201
+ before do
202
+ RubyYacht.configuration.projects.first.rails_environment = 'production'
203
+ end
204
+
205
+ it "generates the dockerfiles for the app server" do
206
+ docker.expect("build -t apollo-rails-app-dependencies tmp") do
207
+ files = Dir[File.join("tmp", "*")].sort
208
+ expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/id_rsa', 'tmp/install_gems.rb']
209
+ dockerfile = File.read(File.join('tmp', 'Dockerfile'))
210
+ expected = File.read(File.join('spec', 'fixtures', 'app-dependencies-dockerfile-rails-production'))
211
+ expect(dockerfile).to eq expected
212
+ end
213
+ subject.run
214
+ end
215
+ end
216
+
217
+ context "with a local MySQL database" do
218
+ before do
219
+ RubyYacht.configuration.clear
220
+ RubyYacht::Plugins::MySQL.load
221
+ described_class.load
222
+
223
+ RubyYacht.configure do
224
+ server_type :sqlite do
225
+ container_type :database
226
+ baseline_image 'ubuntu'
227
+ end
228
+ server_type :nginx do
229
+ container_type :web
230
+ baseline_image 'ubuntu'
231
+ end
232
+ end
233
+
234
+ configure_project
235
+ RubyYacht.configuration.projects.first.databases.first.host = 'localhost'
236
+ RubyYacht.configuration.projects.first.databases.first.server_type = :mysql
237
+ end
238
+
239
+ it "generates the dockerfiles for the database server" do
240
+ docker.expect "build -t apollo-database tmp" do
241
+ files = Dir[File.join("tmp", "*")].sort
242
+ expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/checkout.bash', 'tmp/load_seeds.rb', 'tmp/setup.bash', 'tmp/startup.bash', 'tmp/startup.bash.erb']
243
+ dockerfile = File.read(File.join('tmp', 'Dockerfile'))
244
+ expected = File.read(File.join('spec', 'fixtures', 'database-dockerfile-rails-mysql'))
245
+ expect(dockerfile).to eq expected
246
+ end
247
+ subject.run
248
+ end
249
+ end
250
+
194
251
  context "with no repository" do
195
252
  before do
196
253
  RubyYacht.configuration.projects.first.apps.first.repository_name = nil
@@ -248,6 +248,7 @@ describe RubyYacht::Runner::BuildImages do
248
248
  docker.expect "build -t apollo-mars tmp"
249
249
  docker.expect "build -t apollo-saturn tmp"
250
250
  docker.expect "build -t apollo-nginx tmp"
251
+ docker.expect "network create jupiter 2> /dev/null"
251
252
  docker.expect "build -t jupiter-debian-app-dependencies tmp"
252
253
  docker.expect "build -t jupiter-venus tmp"
253
254
  docker.expect "build -t jupiter-saturn tmp"
@@ -439,6 +440,21 @@ describe RubyYacht::Runner::BuildImages do
439
440
  end
440
441
  end
441
442
 
443
+ context "with an HTTPS repository" do
444
+ before do
445
+ RubyYacht.configuration.projects[0].repository_protocol = :https
446
+ end
447
+
448
+ it "builds a dependencies dockerfile that does checks the repository out over HTTPS" do
449
+ docker.expect("build -t apollo-generic-app-dependencies tmp") do
450
+ dockerfile = File.read(File.join('tmp', 'Dockerfile'))
451
+ expected = File.read(File.join('spec', 'fixtures', 'app-dependencies-dockerfile-with-https-repository'))
452
+ expect(dockerfile).to eq expected
453
+ end
454
+ subject.run
455
+ end
456
+ end
457
+
442
458
  context "with an app with no repository" do
443
459
  before do
444
460
  RubyYacht.configuration.projects[0].apps[0].repository_name = nil
@@ -496,7 +512,7 @@ describe RubyYacht::Runner::BuildImages do
496
512
  subject.instance_eval { @app = app }
497
513
  subject.set_image_settings('app')
498
514
  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]
515
+ expect(subject.instance_eval { @hook_events }).to eq [:startup, :build_checkout, :build_new_app, :cleanup]
500
516
  expect(subject.instance_eval { @hook_servers }).to eq [app]
501
517
  end
502
518
  end
@@ -62,9 +62,9 @@ describe RubyYacht::Runner::RunContainers do
62
62
  docker.expect 'run -d --net=apollo --net-alias=apollo-mars --name=apollo-mars apollo-mars'
63
63
  docker.expect 'run -d --net=apollo --net-alias=apollo-saturn --name=apollo-saturn apollo-saturn'
64
64
  docker.expect 'run -d -p 80:80 --net=apollo --net-alias=apollo-nginx --name=apollo-nginx apollo-nginx'
65
- docker.expect 'run -d --net=apollo --net-alias=jupiter-venus --name=jupiter-venus jupiter-venus'
66
- docker.expect 'run -d --net=apollo --net-alias=jupiter-saturn --name=jupiter-saturn jupiter-saturn'
67
- docker.expect 'run -d -p 80:80 --net=apollo --net-alias=jupiter-web --name=jupiter-web jupiter-web'
65
+ docker.expect 'run -d --net=jupiter --net-alias=jupiter-venus --name=jupiter-venus jupiter-venus'
66
+ docker.expect 'run -d --net=jupiter --net-alias=jupiter-saturn --name=jupiter-saturn jupiter-saturn'
67
+ docker.expect 'run -d -p 80:80 --net=jupiter --net-alias=jupiter-web --name=jupiter-web jupiter-web'
68
68
  subject.run
69
69
  end
70
70
 
@@ -1,7 +1,10 @@
1
1
  module IntegrationHelpers
2
- def configure_project
3
- IntegrationHelpers.clear_docker_containers
4
- system "docker network rm apollo 1> /dev/null 2> /dev/null"
2
+ def containers
3
+ `docker ps | grep "apollo\\|jupiter"`.split("\n").collect { |line| line.split(/\s+/).last }.sort
4
+ end
5
+
6
+ def images
7
+ `docker images | grep "apollo\\|jupiter"`.split("\n").collect { |line| line.split(/\s+/).first }.sort
5
8
  end
6
9
 
7
10
  def run_command(command, environment: {}, capture_output: false)
@@ -11,6 +14,8 @@ module IntegrationHelpers
11
14
  end
12
15
  if capture_output
13
16
  `#{full_command}`
17
+ elsif ENV['VERBOSE_DOCKER'] == '1'
18
+ system full_command
14
19
  else
15
20
  system "#{full_command} 1> log/integration_stdout.txt 2> log/integration_stderr.txt"
16
21
  end
@@ -45,6 +50,11 @@ module IntegrationHelpers
45
50
  end
46
51
  end
47
52
  end
53
+
54
+ def start_database
55
+ system "docker run -d --net=apollo --net-alias=apollo-database --name=apollo-database apollo-database > /dev/null"
56
+ wait_on_command_result 'docker run --rm --net=apollo apollo-mars mysql -uapollo -ptestpass -hapollo-database', does_not_contain: 'ERROR'
57
+ end
48
58
 
49
59
  def restore_hosts_file
50
60
  backup_path = Dir["/etc/hosts*.backup"].last
@@ -71,6 +81,10 @@ module IntegrationHelpers
71
81
  end
72
82
 
73
83
  def self.clear_checkout_folders
74
- `docker run --rm -v $PWD/..:/var/code ruby:2.3 bash -c 'rm -r /var/code/mars; rm -r /var/code/saturn'`
84
+ %w(mars saturn).each do |app|
85
+ if Dir.exist?("../#{app}")
86
+ FileUtils.rm_rf("../#{app}")
87
+ end
88
+ end
75
89
  end
76
90
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_yacht
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Brownlee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-16 00:00:00.000000000 Z
11
+ date: 2016-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -171,15 +171,19 @@ files:
171
171
  - spec/fixtures/app-dependencies-dockerfile-generic
172
172
  - spec/fixtures/app-dependencies-dockerfile-generic-with-library-install
173
173
  - spec/fixtures/app-dependencies-dockerfile-rails
174
+ - spec/fixtures/app-dependencies-dockerfile-rails-production
175
+ - spec/fixtures/app-dependencies-dockerfile-with-https-repository
174
176
  - spec/fixtures/app-dependencies-dockerfile-with-no-repository
175
177
  - spec/fixtures/database-dockerfile
176
178
  - spec/fixtures/database-dockerfile-mysql
177
179
  - spec/fixtures/database-dockerfile-rails
180
+ - spec/fixtures/database-dockerfile-rails-mysql
178
181
  - spec/fixtures/database-dockerfile-rails-with-no-repository
179
182
  - spec/fixtures/database-dockerfile-with-seed-hooks
180
183
  - spec/fixtures/database-startup-mysql
181
184
  - spec/fixtures/hooks/hook1.rb
182
185
  - spec/fixtures/hooks/hook2.rb
186
+ - spec/fixtures/local_config.yml
183
187
  - spec/fixtures/mars-before-startup
184
188
  - spec/fixtures/mars-before-startup-rails
185
189
  - spec/fixtures/mars-before-startup-with-before-startup-hooks
@@ -203,16 +207,17 @@ files:
203
207
  - spec/fixtures/web-dockerfile-nginx
204
208
  - spec/fixtures/web-dockerfile-with-eponymous-app
205
209
  - spec/fixtures/web-dockerfile-with-primary-app
206
- - spec/integration/build_images_spec.rb
207
- - spec/integration/build_spec.rb
208
- - spec/integration/checkout_spec.rb
209
- - spec/integration/create_new_project_spec.rb
210
- - spec/integration/implode_spec.rb
210
+ - spec/integration/01_normal_config_spec.rb
211
+ - spec/integration/02_creating_new_project_spec.rb
212
+ - spec/integration/03_no_repository_spec.rb
213
+ - spec/integration/04_no_database_spec.rb
214
+ - spec/integration/05_https_repository_spec.rb
215
+ - spec/integration/06_production_environment_spec.rb
216
+ - spec/integration/07_local_checkout_spec.rb
217
+ - spec/integration/08_multiple_projects_spec.rb
218
+ - spec/integration/09_titular_app_spec.rb
219
+ - spec/integration/10_misc_scenarios_spec.rb
211
220
  - spec/integration/run.rb
212
- - spec/integration/run_containers_spec.rb
213
- - spec/integration/services_spec.rb
214
- - spec/integration/shell_spec.rb
215
- - spec/integration/update_hosts_spec.rb
216
221
  - spec/plugins/mysql_spec.rb
217
222
  - spec/plugins/nginx_spec.rb
218
223
  - spec/plugins/rails_spec.rb
@@ -274,15 +279,19 @@ test_files:
274
279
  - spec/fixtures/app-dependencies-dockerfile-generic
275
280
  - spec/fixtures/app-dependencies-dockerfile-generic-with-library-install
276
281
  - spec/fixtures/app-dependencies-dockerfile-rails
282
+ - spec/fixtures/app-dependencies-dockerfile-rails-production
283
+ - spec/fixtures/app-dependencies-dockerfile-with-https-repository
277
284
  - spec/fixtures/app-dependencies-dockerfile-with-no-repository
278
285
  - spec/fixtures/database-dockerfile
279
286
  - spec/fixtures/database-dockerfile-mysql
280
287
  - spec/fixtures/database-dockerfile-rails
288
+ - spec/fixtures/database-dockerfile-rails-mysql
281
289
  - spec/fixtures/database-dockerfile-rails-with-no-repository
282
290
  - spec/fixtures/database-dockerfile-with-seed-hooks
283
291
  - spec/fixtures/database-startup-mysql
284
292
  - spec/fixtures/hooks/hook1.rb
285
293
  - spec/fixtures/hooks/hook2.rb
294
+ - spec/fixtures/local_config.yml
286
295
  - spec/fixtures/mars-before-startup
287
296
  - spec/fixtures/mars-before-startup-rails
288
297
  - spec/fixtures/mars-before-startup-with-before-startup-hooks
@@ -306,16 +315,17 @@ test_files:
306
315
  - spec/fixtures/web-dockerfile-nginx
307
316
  - spec/fixtures/web-dockerfile-with-eponymous-app
308
317
  - spec/fixtures/web-dockerfile-with-primary-app
309
- - spec/integration/build_images_spec.rb
310
- - spec/integration/build_spec.rb
311
- - spec/integration/checkout_spec.rb
312
- - spec/integration/create_new_project_spec.rb
313
- - spec/integration/implode_spec.rb
318
+ - spec/integration/01_normal_config_spec.rb
319
+ - spec/integration/02_creating_new_project_spec.rb
320
+ - spec/integration/03_no_repository_spec.rb
321
+ - spec/integration/04_no_database_spec.rb
322
+ - spec/integration/05_https_repository_spec.rb
323
+ - spec/integration/06_production_environment_spec.rb
324
+ - spec/integration/07_local_checkout_spec.rb
325
+ - spec/integration/08_multiple_projects_spec.rb
326
+ - spec/integration/09_titular_app_spec.rb
327
+ - spec/integration/10_misc_scenarios_spec.rb
314
328
  - spec/integration/run.rb
315
- - spec/integration/run_containers_spec.rb
316
- - spec/integration/services_spec.rb
317
- - spec/integration/shell_spec.rb
318
- - spec/integration/update_hosts_spec.rb
319
329
  - spec/plugins/mysql_spec.rb
320
330
  - spec/plugins/nginx_spec.rb
321
331
  - spec/plugins/rails_spec.rb
@@ -1,210 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe RubyYacht::Runner::BuildImages, :integration do
4
- include IntegrationHelpers
5
-
6
- def start_database
7
- system "docker run -d --net=apollo --net-alias=apollo-database --name=apollo-database apollo-database > /dev/null"
8
- wait_on_command_result 'docker run --rm --net=apollo apollo-mars mysql -uapollo -ptestpass -hapollo-database', does_not_contain: 'ERROR'
9
- end
10
-
11
- let(:images) { `docker images | grep "apollo\\|jupiter"`.split("\n").collect { |line| line.split(/\s+/).first }.sort }
12
-
13
- before :all do
14
- configure_project
15
- system 'docker network create apollo 1> /dev/null 2> /dev/null'
16
- end
17
-
18
- context "with the standard config" do
19
- before :all do
20
- run_command 'build_images'
21
- end
22
-
23
- after do
24
- IntegrationHelpers.clear_docker_containers
25
- end
26
-
27
- it "creates images for the app, dependencies, database, and web server" do
28
- expect(images).to eq ['apollo-database', 'apollo-mars', 'apollo-rails-app-dependencies', 'apollo-saturn', 'apollo-web']
29
- end
30
-
31
- it "populates the tables in the database image" do
32
- start_database
33
-
34
- results = run_command_in_docker :mars, 'mysql -uapollo -ptestpass -hapollo-database -e "use apollo; show tables"'
35
- results = results.split("\n").collect { |line| line.delete('|').strip }.sort
36
- results.shift
37
- expect(results).to eq %w(clients posts schema_migrations users)
38
- end
39
-
40
- it "populates the seed data in the database image" do
41
- start_database
42
-
43
- results = run_command_in_docker :mars, 'mysql -uapollo -ptestpass -hapollo-database -e "select count(*) FROM apollo.users"'
44
- results = results.split("\n").collect { |line| line.delete('|').strip }
45
- results.shift
46
- expect(results).to eq ['1']
47
-
48
- results = run_command_in_docker :mars, 'mysql -uapollo -ptestpass -hapollo-database -e "select name FROM apollo.clients"'
49
- results = results.split("\n").collect { |line| line.delete('|').strip }
50
- results.shift
51
- expect(results).to eq ['Test Client']
52
- end
53
-
54
- it "creates a test database" do
55
- start_database
56
-
57
- results = run_command_in_docker :mars, 'mysql -uapollo -ptestpass -hapollo-database apollo_test 2>&1'
58
- expect(results).not_to include 'ERROR'
59
- end
60
-
61
- it "installs the gems on the app dependency image" do
62
- results = run_command_in_docker 'rails-app-dependencies', 'gem list'
63
- expect(results).to include 'mysql2'
64
- expect(results).to include 'sass-rails'
65
- expect(results).to include 'byebug'
66
- expect(results).to include 'factory_girl'
67
- end
68
-
69
- it "leaves all the apps checked out on the app dependency image" do
70
- results = run_command_in_docker 'rails-app-dependencies', 'ls /var/code'
71
- folders = results.split("\n")
72
- expect(folders).to include 'mars'
73
- expect(folders).to include 'saturn'
74
- end
75
-
76
- it "installs the gems on the app images" do
77
- results = run_command_in_docker :mars, 'gem list'
78
- expect(results).to include 'mysql2'
79
- expect(results).not_to include 'sass-rails'
80
- expect(results).to include 'byebug'
81
- expect(results).to include 'factory_girl'
82
-
83
- results = run_command_in_docker :saturn, 'gem list'
84
- expect(results).to include 'mysql2'
85
- expect(results).to include 'sass-rails'
86
- expect(results).not_to include 'byebug'
87
- expect(results).not_to include 'factory_girl'
88
- end
89
-
90
- it 'installs mysql on the app images' do
91
- results = run_command_in_docker :mars, 'which mysql'
92
- expect(results).to eq "/usr/bin/mysql\n"
93
- end
94
-
95
- it "checks out just the single app on the app image" do
96
- results = run_command_in_docker :mars, 'ls /var/code'
97
- folders = results.split("\n")
98
- expect(folders).to include 'app'
99
- expect(folders).to include 'db'
100
- end
101
-
102
- it "installs the scripts in the /var/docker folder in the app image" do
103
- results = run_command_in_docker :mars, 'ls /var/docker'
104
- files = results.split("\n")
105
- expect(files).to include 'checkout.bash'
106
- expect(files).to include 'before_startup.bash'
107
- expect(files).to include 'startup.bash'
108
- expect(files).to include 'update_rails_config.rb'
109
- expect(files).to include 'prepare_rails_for_launch.rb'
110
- end
111
- end
112
-
113
- context 'with no database server' do
114
- before :all do
115
- system "docker rmi apollo-database 1> /dev/null 2> /dev/null"
116
- run_command 'build_images', environment: { SKIP_DATABASE: 1 }
117
- end
118
-
119
- it "does not build a database image" do
120
- expect(images).to eq ['apollo-mars', 'apollo-rails-app-dependencies', 'apollo-saturn', 'apollo-web']
121
- end
122
-
123
- it 'does not install mysql on the app servers' do
124
- results = run_command_in_docker :mars, 'which mysql'
125
- expect(results).to eq ''
126
- end
127
- end
128
-
129
- context 'with a production environment' do
130
- before :all do
131
- run_command 'build_images', environment: { USE_PRODUCTION_ENVIRONMENT: 1 }
132
- end
133
-
134
- after :all do
135
- IntegrationHelpers.clear_docker_containers
136
- end
137
-
138
- it "does not install the non-production gems" do
139
- results = run_command_in_docker 'rails-app-dependencies', 'gem list'
140
- expect(results).to include 'mysql2'
141
- expect(results).not_to include 'byebug'
142
- expect(results).not_to include 'factory_girl'
143
-
144
- results = run_command_in_docker :mars, 'gem list'
145
- expect(results).to include 'mysql2'
146
- expect(results).not_to include 'byebug'
147
- expect(results).not_to include 'factory_girl'
148
- end
149
-
150
- it "does not create a test database" do
151
- start_database
152
- results = run_command_in_docker :mars, 'mysql -uapollo -ptestpass -hapollo-database apollo_test 2>&1'
153
- expect(results).to include 'ERROR'
154
- end
155
- end
156
-
157
- context "with an app with the same name as the project" do
158
- before :all do
159
- system "docker rmi apollo-mars 1> /dev/null 2> /dev/null"
160
- run_command 'build_images', environment: { CREATE_TITULAR_APP: 1 }
161
- end
162
-
163
- after :all do
164
- system "docker rmi apollo 1> /dev/null"
165
- end
166
-
167
- it "creates an image with the same name as the project" do
168
- expect(images).to eq ['apollo', 'apollo-database', 'apollo-rails-app-dependencies', 'apollo-saturn', 'apollo-web']
169
- end
170
-
171
- it "checks out the app onto the image" do
172
- results = `docker run --rm apollo ls /var/code/app/models`
173
- expect(results).to include 'user.rb'
174
- expect(results).to include 'post.rb'
175
- end
176
- end
177
-
178
- context "with a second project" do
179
- before :all do
180
- run_command 'build_images', environment: { CREATE_SECOND_PROJECT: 1 }
181
- end
182
-
183
- after :all do
184
- IntegrationHelpers.image_names.select { |name| name =~ /jupiter/ }.each do |name|
185
- `docker rmi #{name} 1> /dev/null`
186
- end
187
- end
188
-
189
- it "creates images for the app, dependencies, database, and web server" do
190
- expect(images).to eq ['apollo-database', 'apollo-mars', 'apollo-rails-app-dependencies', 'apollo-saturn', 'apollo-web', 'jupiter-database', 'jupiter-rails-app-dependencies', 'jupiter-saturn', 'jupiter-web']
191
- end
192
- end
193
-
194
- context 'with no repository name' do
195
- before :all do
196
- run_command 'build_images', environment: { NO_REPOSITORY: 1 }
197
- end
198
-
199
-
200
- it 'creates images for the app, dependencies, database, and web server' do
201
- expect(images).to eq ['apollo-database', 'apollo-mars', 'apollo-rails-app-dependencies', 'apollo-saturn', 'apollo-web']
202
- end
203
-
204
- it 'creates a fresh app in the app image' do
205
- results = run_command_in_docker :mars, 'ls /var/code'
206
- expect(results).to include 'app'
207
- expect(results).to include 'Gemfile'
208
- end
209
- end
210
- end