ruby_yacht 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/doc/TODO.md +1 -8
  4. data/lib/ruby_yacht/dsl/app.rb +37 -10
  5. data/lib/ruby_yacht/dsl/configuration.rb +21 -21
  6. data/lib/ruby_yacht/dsl/database.rb +53 -0
  7. data/lib/ruby_yacht/dsl/dsl.rb +14 -8
  8. data/lib/ruby_yacht/dsl/hook.rb +35 -15
  9. data/lib/ruby_yacht/dsl/project.rb +23 -10
  10. data/lib/ruby_yacht/dsl/{app_type.rb → server_type.rb} +39 -29
  11. data/lib/ruby_yacht/dsl.rb +1 -1
  12. data/lib/ruby_yacht/images/app/Dockerfile.erb +9 -5
  13. data/lib/ruby_yacht/images/app-dependencies/Dockerfile.erb +2 -2
  14. data/lib/ruby_yacht/images/database/Dockerfile.erb +12 -11
  15. data/lib/ruby_yacht/images/web/Dockerfile.erb +6 -2
  16. data/lib/ruby_yacht/images/web/add_app.rb +7 -1
  17. data/lib/ruby_yacht/images/web/app_config.erb +2 -0
  18. data/lib/ruby_yacht/plugins/mysql/scripts/setup.bash +11 -0
  19. data/lib/ruby_yacht/plugins/mysql.rb +27 -0
  20. data/lib/ruby_yacht/plugins/rails/scripts/install_gems.rb +6 -1
  21. data/lib/ruby_yacht/plugins/rails/scripts/load_seeds.rb +6 -4
  22. data/lib/ruby_yacht/plugins/rails/scripts/prepare_rails_for_launch.rb +1 -0
  23. data/lib/ruby_yacht/plugins/rails/scripts/update_rails_config.rb +1 -5
  24. data/lib/ruby_yacht/plugins/rails.rb +12 -4
  25. data/lib/ruby_yacht/plugins.rb +2 -1
  26. data/lib/ruby_yacht/runner/build_images.rb +32 -26
  27. data/lib/ruby_yacht/runner/checkout.rb +5 -4
  28. data/lib/ruby_yacht/runner/run_containers.rb +7 -6
  29. data/lib/ruby_yacht/runner/services.rb +2 -2
  30. data/lib/ruby_yacht/runner/shell.rb +5 -4
  31. data/lib/ruby_yacht/runner/update_hosts.rb +2 -1
  32. data/ruby_yacht.gemspec +1 -1
  33. data/spec/dsl/app_spec.rb +96 -10
  34. data/spec/dsl/configuration_spec.rb +53 -55
  35. data/spec/dsl/database_spec.rb +70 -12
  36. data/spec/dsl/hook_spec.rb +36 -19
  37. data/spec/dsl/project_spec.rb +26 -18
  38. data/spec/dsl/{app_type_spec.rb → server_type_spec.rb} +52 -28
  39. data/spec/fixtures/app-dependencies-dockerfile-rails +3 -0
  40. data/spec/fixtures/database-dockerfile +1 -8
  41. data/spec/fixtures/database-dockerfile-mysql +30 -0
  42. data/spec/fixtures/database-dockerfile-rails +1 -5
  43. data/spec/fixtures/database-dockerfile-with-seed-hooks +1 -8
  44. data/spec/fixtures/mars-before-startup-with-custom-file-copy +6 -0
  45. data/spec/fixtures/mars-dockerfile +0 -4
  46. data/spec/fixtures/mars-dockerfile-rails +2 -2
  47. data/spec/fixtures/mars-dockerfile-with-after-checkout-hooks +0 -4
  48. data/spec/fixtures/mars-dockerfile-with-before-startup-hooks +0 -4
  49. data/spec/fixtures/mars-dockerfile-with-custom-file-copy +23 -0
  50. data/spec/fixtures/mars-dockerfile-with-local-database +27 -0
  51. data/spec/fixtures/mars-dockerfile-with-remote-database +27 -0
  52. data/spec/fixtures/web-dockerfile-with-eponymous-app +20 -0
  53. data/spec/plugins/mysql_spec.rb +64 -0
  54. data/spec/plugins/rails_spec.rb +103 -43
  55. data/spec/runner/build_images_spec.rb +142 -11
  56. data/spec/runner/checkout_spec.rb +4 -4
  57. data/spec/runner/run_containers_spec.rb +21 -2
  58. data/spec/runner/runner_spec.rb +1 -1
  59. data/spec/runner/services_spec.rb +7 -2
  60. data/spec/runner/shell_spec.rb +3 -3
  61. data/spec/runner/update_hosts_spec.rb +26 -0
  62. data/spec/support/test_project.rb +16 -20
  63. metadata +20 -5
  64. data/lib/ruby_yacht/images/database/setup.bash +0 -15
@@ -0,0 +1,20 @@
1
+ FROM nginx
2
+
3
+ RUN apt-get update
4
+ RUN apt-get upgrade -y
5
+ RUN apt-get install -y ruby
6
+
7
+ RUN mkdir -p /var/docker
8
+
9
+ COPY add_project.rb /var/docker/add_project.rb
10
+ COPY add_app.rb /var/docker/add_app.rb
11
+ COPY index.html.erb /var/docker/index.html.erb
12
+ COPY index_config.erb /var/docker/index_config.erb
13
+ COPY app_config.erb /var/docker/app_config.erb
14
+
15
+ RUN ruby /var/docker/add_app.rb apollo apollo.test.com apollo 8080 true
16
+ RUN ruby /var/docker/add_app.rb apollo apollo.test.com saturn 8080 false
17
+
18
+ RUN rm -r /var/docker
19
+ RUN apt-get remove -y ruby
20
+ RUN apt-get autoremove -y
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyYacht::Plugins::MySQL do
4
+ before do
5
+ RubyYacht.configuration.clear
6
+ described_class.load
7
+ end
8
+
9
+ it "adds MySQL to the app type list" do
10
+ expect(RubyYacht.configuration.server_types.map(&:name)).to include :mysql
11
+ end
12
+
13
+ describe "building images" do
14
+ subject { RubyYacht::Runner::BuildImages.new }
15
+ include DockerCommandSpec
16
+
17
+ before do
18
+ RubyYacht.configuration.clear
19
+ described_class.load
20
+
21
+ RubyYacht.configure do
22
+ server_type :generic do
23
+ container_type :app
24
+ baseline_image :ubuntu
25
+ end
26
+ end
27
+
28
+ RubyYacht.configure do
29
+ project :apollo do
30
+ system_prefix :apollo
31
+ domain "apollo.test.com"
32
+ repository "github.com"
33
+
34
+ mysql_database :apollo do
35
+ host "localhost"
36
+ username "apollo"
37
+ password "test"
38
+ end
39
+
40
+ generic_app :mars do
41
+ repository_name 'brownleej/mars'
42
+ database_name :apollo
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ it "copies the scripts to the docker folder" do
49
+ docker.expect("build -t apollo-database tmp") do
50
+ files = Dir[File.join("tmp", "*")].sort
51
+ expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/checkout.bash', 'tmp/setup.bash']
52
+ end
53
+ subject.run
54
+ end
55
+ it "builds the dockerfile for a MySQL database" do
56
+ docker.expect("build -t apollo-database tmp") do
57
+ dockerfile = File.read(File.join('tmp', 'Dockerfile'))
58
+ expected = File.read(File.join('spec', 'fixtures', 'database-dockerfile-mysql'))
59
+ expect(dockerfile).to eq expected
60
+ end
61
+ subject.run
62
+ end
63
+ end
64
+ end
@@ -5,83 +5,135 @@ describe RubyYacht::Plugins::Rails do
5
5
  RubyYacht.configuration.clear
6
6
  described_class.load
7
7
  end
8
+
9
+ def configure_project(options = {})
10
+ RubyYacht.configuration.clear
11
+ RubyYacht::Plugins::Rails.load
8
12
 
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
13
  RubyYacht.configure do
15
14
  project :test_project do
16
15
  system_prefix :test_project
17
16
  domain 'test.com'
18
17
  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
18
+ rails_secret_key_base(options[:secret_key_base]) if options[:secret_key_base]
19
+ rails_environment(options[:environment]) if options[:environment]
20
+ rails_excluded_gem_groups(options[:excluded_gem_groups]) if options[:excluded_gem_groups]
27
21
  end
28
22
  end
23
+ end
29
24
 
25
+ it "adds rails to the app type list" do
26
+ expect(RubyYacht.configuration.server_types.map(&:name)).to include :rails
27
+ end
28
+
29
+ it "adds an attribute for the rails environment" do
30
+ configure_project(secret_key_base: 'abc', environment: 'production')
31
+ project = RubyYacht.configuration.projects.last
32
+ expect(project.rails_environment).to eq 'production'
33
+
34
+ configure_project(secret_key_base: 'abc')
30
35
  project = RubyYacht.configuration.projects.last
31
36
  expect(project.rails_environment).to eq 'development'
37
+ end
38
+
39
+ it "adds an attribute for the rails secret key" do
40
+ configure_project(secret_key_base: 'abc')
41
+ project = RubyYacht.configuration.projects.last
32
42
  expect(project.rails_secret_key_base).to eq 'abc'
33
43
  end
44
+
45
+ it "adds an attribute for the rails excluded gem groups" do
46
+ configure_project(secret_key_base: 'abc', excluded_gem_groups: %w(development test))
47
+ project = RubyYacht.configuration.projects.last
48
+ expect(project.rails_excluded_gem_groups).to eq %w(development test)
49
+
50
+ RubyYacht.configuration.clear
51
+ configure_project(secret_key_base: 'abc')
52
+ project = RubyYacht.configuration.projects.last
53
+ expect(project.rails_excluded_gem_groups).to eq []
54
+ end
34
55
 
35
- it "sets environment variables for the RAILS_ENV and SECRET_KEY_BASE" do
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
36
68
  @project = RubyYacht::Project.new
37
- @project.rails_environment = 'development'
38
69
  @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'
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
48
100
  end
49
101
 
50
- it "creates a during-install-libraries hook for cleaning the gems" do
102
+ it "creates a during-install-libraries hook for installing the gems" do
51
103
  hooks = RubyYacht.configuration.fetch_hooks(event_time: :during, event_type: :install_libraries)
52
104
  expect(hooks.count).to eq 1
53
105
  expect(hooks[0].command).to eq '/var/docker/install_gems.rb'
54
- expect(hooks[0].app_type).to eq :rails
106
+ expect(hooks[0].server_type).to eq :rails
55
107
  end
56
108
 
57
109
  it "creates an after-build-checkout hook for cleaning the gems" do
58
110
  hooks = RubyYacht.configuration.fetch_hooks(event_time: :after, event_type: :build_checkout)
59
111
  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
112
+ expect(hooks[0].command).to eq 'bundle install --clean'
113
+ expect(hooks[0].server_type).to eq :rails
62
114
  end
63
115
 
64
116
  it "creates a during-load-seeds hook for loading the seeds" do
65
117
  hooks = RubyYacht.configuration.fetch_hooks(event_time: :during, event_type: :load_database_seeds)
66
118
  expect(hooks.count).to eq 1
67
119
  expect(hooks[0].command).to eq '/var/docker/load_seeds.rb'
68
- expect(hooks[0].app_type).to eq :rails
120
+ expect(hooks[0].server_type).to eq :rails
69
121
  end
70
122
 
71
123
  it "creates before-startup hooks for updating the config and preparing the app for launch" do
72
124
  hooks = RubyYacht.configuration.fetch_hooks(event_time: :before, event_type: :startup)
73
125
  expect(hooks.count).to eq 2
74
126
  expect(hooks[0].command).to eq '/var/docker/update_rails_config.rb'
75
- expect(hooks[0].app_type).to eq :rails
127
+ expect(hooks[0].server_type).to eq :rails
76
128
  expect(hooks[1].command).to eq '/var/docker/prepare_rails_for_launch.rb'
77
- expect(hooks[1].app_type).to eq :rails
129
+ expect(hooks[1].server_type).to eq :rails
78
130
  end
79
131
 
80
132
  it "creates a during-startup hook for starting the server" do
81
133
  hooks = RubyYacht.configuration.fetch_hooks(event_time: :during, event_type: :startup)
82
134
  expect(hooks.count).to eq 1
83
135
  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
136
+ expect(hooks[0].server_type).to eq :rails
85
137
  end
86
138
 
87
139
  describe "building images" do
@@ -92,6 +144,13 @@ describe RubyYacht::Plugins::Rails do
92
144
  RubyYacht.configuration.clear
93
145
  described_class.load
94
146
 
147
+ RubyYacht.configure do
148
+ server_type :sqlite do
149
+ container_type :database
150
+ baseline_image 'ubuntu'
151
+ end
152
+ end
153
+
95
154
  RubyYacht.configure do
96
155
  project :apollo do
97
156
  system_prefix :apollo
@@ -99,19 +158,20 @@ describe RubyYacht::Plugins::Rails do
99
158
  repository "github.com"
100
159
  rails_secret_key_base 'abc'
101
160
 
102
- database do
161
+ sqlite_database :apollo do
103
162
  host "db.test.com"
104
- name "apollo"
105
163
  username "apollo"
106
164
  password "test"
107
165
  end
108
166
 
109
167
  rails_app :mars do
110
168
  repository_name 'brownleej/mars'
169
+ database_name :apollo
111
170
  end
112
171
 
113
172
  rails_app :saturn do
114
173
  repository_name 'brownleej/saturn'
174
+ database_name :apollo
115
175
  end
116
176
  end
117
177
  end
@@ -180,18 +240,18 @@ describe RubyYacht::Plugins::Rails do
180
240
 
181
241
  context "with a local database" do
182
242
  before do
183
- RubyYacht.configuration.projects[0].database.host = 'localhost'
243
+ RubyYacht.configuration.projects.first.databases.first.host = 'localhost'
184
244
  end
185
245
 
186
246
  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
247
+ docker.expect "build -t apollo-database tmp" do
248
+ files = Dir[File.join("tmp", "*")].sort
249
+ expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/checkout.bash', 'tmp/install_gems.rb', 'tmp/load_seeds.rb']
250
+ dockerfile = File.read(File.join('tmp', 'Dockerfile'))
251
+ expected = File.read(File.join('spec', 'fixtures', 'database-dockerfile-rails'))
252
+ expect(dockerfile).to eq expected
253
+ end
254
+ subject.run
195
255
  end
196
256
  end
197
257
  end
@@ -77,13 +77,39 @@ describe RubyYacht::Runner::BuildImages do
77
77
 
78
78
  context "with a local database" do
79
79
  before do
80
- RubyYacht.configuration.projects[0].database.host = 'localhost'
80
+ RubyYacht.configure do
81
+ server_type :sqlite do
82
+ container_type :database
83
+ baseline_image 'ubuntu'
84
+ end
85
+ end
86
+
87
+ database = RubyYacht::Database.new
88
+ database.name = 'apollo'
89
+ database.server_type = :sqlite
90
+ database.container_label = 'mysql'
91
+ database.username = 'apollo'
92
+ database.password = 'test'
93
+ database.host = 'localhost'
94
+ RubyYacht.configuration.projects.first.databases << database
95
+ RubyYacht.configuration.projects.first.apps.first.database_name = 'apollo'
96
+ end
97
+
98
+ it "builds an app dockerfile with the database config" do
99
+ docker.expect("build -t apollo-mars tmp") do
100
+ files = Dir[File.join("tmp", "*")].sort
101
+ 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']
102
+ dockerfile = File.read(File.join('tmp', 'Dockerfile'))
103
+ expected = File.read(File.join('spec', 'fixtures', 'mars-dockerfile-with-local-database'))
104
+ expect(dockerfile).to eq expected
105
+ end
106
+ subject.run
81
107
  end
82
108
 
83
109
  it "builds the database" do
84
- docker.expect("build -t apollo-database tmp") do
110
+ docker.expect("build -t apollo-mysql tmp") do
85
111
  files = Dir[File.join("tmp", "*")].sort
86
- expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/checkout.bash','tmp/setup.bash']
112
+ expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/checkout.bash']
87
113
  dockerfile = File.read(File.join('tmp', 'Dockerfile'))
88
114
  expected = File.read(File.join('spec', 'fixtures', 'database-dockerfile'))
89
115
  expect(dockerfile).to eq expected
@@ -101,22 +127,22 @@ describe RubyYacht::Runner::BuildImages do
101
127
  before do
102
128
  script_folder = self.script_folder
103
129
  RubyYacht.configure do
104
- add_hooks folder: script_folder, app_type: :generic do
130
+ add_hooks folder: script_folder, server_type: :generic do
105
131
  during(:load_database_seeds) { run_script 'hook1.rb' }
106
132
  end
107
133
  end
108
134
  end
109
135
 
110
136
  it "copies the files for the hooks to the database" do
111
- docker.expect("build -t apollo-database tmp") do
137
+ docker.expect("build -t apollo-mysql tmp") do
112
138
  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']
139
+ expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb', 'tmp/checkout.bash', 'tmp/hook1.rb']
114
140
  end
115
141
  subject.run
116
142
  end
117
143
 
118
144
  it "includes the scripts in the database dockerfile" do
119
- docker.expect("build -t apollo-database tmp") do
145
+ docker.expect("build -t apollo-mysql tmp") do
120
146
  dockerfile = File.read(File.join('tmp', 'Dockerfile'))
121
147
  expected = File.read(File.join('spec', 'fixtures', 'database-dockerfile-with-seed-hooks'))
122
148
  expect(dockerfile).to eq expected
@@ -125,6 +151,42 @@ describe RubyYacht::Runner::BuildImages do
125
151
  end
126
152
  end
127
153
  end
154
+
155
+ context 'with a non-local database' do
156
+ before do
157
+ database = RubyYacht::Database.new
158
+ database.name = 'apollo'
159
+ database.server_type = 'mysql'
160
+ database.container_label = 'mysql'
161
+ database.username = 'apollo'
162
+ database.password = 'test'
163
+ database.host = 'db1.test.com'
164
+ RubyYacht.configuration.projects.first.databases << database
165
+ RubyYacht.configuration.projects.first.apps.first.database_name = 'apollo'
166
+ end
167
+
168
+ it "builds an app dockerfile with the database config" do
169
+ docker.expect("build -t apollo-mars tmp") do
170
+ files = Dir[File.join("tmp", "*")].sort
171
+ 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']
172
+ dockerfile = File.read(File.join('tmp', 'Dockerfile'))
173
+ expected = File.read(File.join('spec', 'fixtures', 'mars-dockerfile-with-remote-database'))
174
+ expect(dockerfile).to eq expected
175
+ end
176
+ subject.run
177
+ end
178
+
179
+ it "does not build an image for the database" do
180
+ docker.fail_unexpected_commands!
181
+ docker.expect "network create apollo 2> /dev/null"
182
+ docker.expect "build -t apollo-generic-app-dependencies tmp"
183
+ docker.expect "build -t apollo-debian-app-dependencies tmp"
184
+ docker.expect "build -t apollo-mars tmp"
185
+ docker.expect "build -t apollo-saturn tmp"
186
+ docker.expect "build -t apollo-web tmp"
187
+ subject.run
188
+ end
189
+ end
128
190
 
129
191
  context "with an id_rsa key" do
130
192
  let(:id_file_path) { File.join(ENV['HOME'], '.ssh', 'id_rsa') }
@@ -164,7 +226,7 @@ describe RubyYacht::Runner::BuildImages do
164
226
  RubyYacht.configuration.projects[0].primary_app = :mars
165
227
  end
166
228
 
167
- it "includes that app in the setup in the web server dockerfile" do
229
+ it "includes that app as the primary in the web server dockerfile" do
168
230
  docker.expect "build -t apollo-web tmp" do
169
231
  files = Dir[File.join("tmp", "*")].sort
170
232
  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']
@@ -175,6 +237,34 @@ describe RubyYacht::Runner::BuildImages do
175
237
  subject.run
176
238
  end
177
239
  end
240
+
241
+ context "with an app with the same name as the system" do
242
+ before do
243
+ RubyYacht.configuration.projects[0].apps[0].name = :apollo
244
+ end
245
+
246
+ it "builds all the images for the project" do
247
+ docker.fail_unexpected_commands!
248
+ docker.expect "network create apollo 2> /dev/null"
249
+ docker.expect "build -t apollo-generic-app-dependencies tmp"
250
+ docker.expect "build -t apollo-debian-app-dependencies tmp"
251
+ docker.expect "build -t apollo tmp"
252
+ docker.expect "build -t apollo-saturn tmp"
253
+ docker.expect "build -t apollo-web tmp"
254
+ subject.run
255
+ end
256
+
257
+ it "includes that app as the primary in the web server dockerfile" do
258
+ docker.expect "build -t apollo-web tmp" do
259
+ files = Dir[File.join("tmp", "*")].sort
260
+ 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']
261
+ dockerfile = File.read(File.join('tmp', 'Dockerfile'))
262
+ expected = File.read(File.join('spec', 'fixtures', 'web-dockerfile-with-eponymous-app'))
263
+ expect(dockerfile).to eq expected
264
+ end
265
+ subject.run
266
+ end
267
+ end
178
268
 
179
269
  context "with multiple projects" do
180
270
  before do
@@ -216,7 +306,7 @@ describe RubyYacht::Runner::BuildImages do
216
306
  before do
217
307
  script_folder = self.script_folder
218
308
  RubyYacht.configure do
219
- add_hooks folder: script_folder, app_type: :generic do
309
+ add_hooks folder: script_folder, server_type: :generic do
220
310
  before(:startup) { run_script 'hook1.rb' }
221
311
  before(:startup) { run_script 'hook2.rb' }
222
312
  end
@@ -256,7 +346,7 @@ describe RubyYacht::Runner::BuildImages do
256
346
  before do
257
347
  script_folder = self.script_folder
258
348
  RubyYacht.configure do
259
- add_hooks folder: script_folder, app_type: :generic do
349
+ add_hooks folder: script_folder, server_type: :generic do
260
350
  after(:build_checkout) { run_script 'hook1.rb' }
261
351
  end
262
352
  end
@@ -294,7 +384,7 @@ describe RubyYacht::Runner::BuildImages do
294
384
  before do
295
385
  script_folder = self.script_folder
296
386
  RubyYacht.configure do
297
- add_hooks folder: script_folder, app_type: :generic do
387
+ add_hooks folder: script_folder, server_type: :generic do
298
388
  during(:install_libraries) { run_script 'hook2.rb' }
299
389
  end
300
390
  end
@@ -326,5 +416,46 @@ describe RubyYacht::Runner::BuildImages do
326
416
  subject.run
327
417
  end
328
418
  end
419
+
420
+ context "with hooks for copying custom files" do
421
+ let(:script_folder) { File.join(File.dirname(File.dirname(__FILE__)), 'fixtures', 'hooks') }
422
+ before do
423
+ script_folder = self.script_folder
424
+ RubyYacht.configure do
425
+ add_hooks folder: script_folder, server_type: :generic do
426
+ before :startup do
427
+ copy_file "hook1.rb"
428
+ command "cp /var/docker/hook1.rb /var/code/scripts/hook1.rb"
429
+ end
430
+ end
431
+ end
432
+ end
433
+
434
+ it "copies the scripts to the tmp directory" do
435
+ docker.expect("build -t apollo-mars tmp") do
436
+ files = Dir[File.join('tmp', '*')]
437
+ expect(files).to include 'tmp/hook1.rb'
438
+ end
439
+ subject.run
440
+ end
441
+
442
+ it "builds a before_startup script that copies the file" do
443
+ docker.expect("build -t apollo-mars tmp") do
444
+ dockerfile = File.read(File.join('tmp', 'before_startup.bash'))
445
+ expected = File.read(File.join('spec', 'fixtures', 'mars-before-startup-with-custom-file-copy'))
446
+ expect(dockerfile).to eq expected
447
+ end
448
+ subject.run
449
+ end
450
+
451
+ it "builds a dockerfile that copies the file to the /var/docker directory" do
452
+ docker.expect("build -t apollo-mars tmp") do
453
+ startup = File.read(File.join('tmp', 'Dockerfile'))
454
+ expected = File.read(File.join('spec', 'fixtures', 'mars-dockerfile-with-custom-file-copy'))
455
+ expect(startup).to eq expected
456
+ end
457
+ subject.run
458
+ end
459
+ end
329
460
  end
330
461
  end
@@ -30,7 +30,7 @@ describe RubyYacht::Runner::Checkout do
30
30
 
31
31
  it "takes the app and checkout from the command line" do
32
32
  subject.parse_positional_arguments(['venus', 'issue1234'])
33
- expect(subject.app).to eq 'venus'
33
+ expect(subject.app_name).to eq 'venus'
34
34
  expect(subject.branch).to eq 'issue1234'
35
35
  end
36
36
  end
@@ -38,7 +38,7 @@ describe RubyYacht::Runner::Checkout do
38
38
 
39
39
  describe "run behavior" do
40
40
  before do
41
- subject.app = 'saturn'
41
+ subject.app_name = 'saturn'
42
42
  subject.branch = 'issue1234'
43
43
  end
44
44
 
@@ -61,7 +61,7 @@ describe RubyYacht::Runner::Checkout do
61
61
  end
62
62
 
63
63
  it "runs the command in that project" do
64
- subject.app = 'venus'
64
+ subject.app_name = '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
67
  docker.expect "exec jupiter-venus /var/docker/before_startup.bash"
@@ -91,7 +91,7 @@ describe RubyYacht::Runner::Checkout do
91
91
 
92
92
  context "with no app" do
93
93
  before do
94
- subject.app = nil
94
+ subject.app_name = nil
95
95
  end
96
96
 
97
97
  it "logs an error" do
@@ -34,11 +34,16 @@ describe RubyYacht::Runner::RunContainers do
34
34
 
35
35
  context "with a local database" do
36
36
  before do
37
- RubyYacht.configuration.projects.first.database.host = 'localhost'
37
+ database = RubyYacht::Database.new
38
+ database.name = 'apollo'
39
+ database.server_type = 'mysql'
40
+ database.container_label = 'mysql'
41
+ database.host = 'localhost'
42
+ RubyYacht.configuration.projects.first.databases << database
38
43
  end
39
44
 
40
45
  it "runs the database container" do
41
- docker.expect 'run -d --net=apollo --net-alias=apollo-database --name=apollo-database apollo-database'
46
+ docker.expect 'run -d --net=apollo --net-alias=apollo-mysql --name=apollo-mysql apollo-mysql'
42
47
  subject.run
43
48
  end
44
49
 
@@ -100,6 +105,20 @@ describe RubyYacht::Runner::RunContainers do
100
105
  expect(subject.run).to be_truthy
101
106
  end
102
107
  end
108
+
109
+ context "with an app with the same name as the project" do
110
+ before do
111
+ RubyYacht.configuration.projects.first.apps.first.name = :apollo
112
+ end
113
+
114
+ it "runs the containers for all the apps" do
115
+ docker.fail_unexpected_commands!
116
+ docker.expect 'run -d --net=apollo --net-alias=apollo --name=apollo apollo'
117
+ docker.expect 'run -d --net=apollo --net-alias=apollo-saturn --name=apollo-saturn apollo-saturn'
118
+ docker.expect 'run -d -p 80:80 --net=apollo --net-alias=apollo-web --name=apollo-web apollo-web'
119
+ subject.run
120
+ end
121
+ end
103
122
  end
104
123
 
105
124
  describe "remove_container" do
@@ -37,7 +37,7 @@ describe RubyYacht::Runner do
37
37
 
38
38
  it "calls the command" do
39
39
  expect(command.project_name).to eq :apollo
40
- expect(command.app).to eq 'mars'
40
+ expect(command.app_name).to eq 'mars'
41
41
  expect(command.branch).to eq 'issue1234'
42
42
  expect(command).to have_received(:run)
43
43
  end
@@ -39,11 +39,16 @@ describe RubyYacht::Runner::Services do
39
39
 
40
40
  context "with a local database" do
41
41
  before do
42
- RubyYacht.configuration.projects.first.database.host = 'localhost'
42
+ database = RubyYacht::Database.new
43
+ database.name = 'apollo'
44
+ database.server_type = 'mysql'
45
+ database.container_label = 'mysql'
46
+ database.host = 'localhost'
47
+ RubyYacht.configuration.projects.first.databases << database
43
48
  end
44
49
 
45
50
  it "stops the database" do
46
- docker.expect 'stop apollo-database'
51
+ docker.expect 'stop apollo-mysql'
47
52
  subject.run
48
53
  end
49
54