ruby_yacht 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +1 -0
  4. data/doc/TODO.md +1 -6
  5. data/doc/configuration_sample.rb +7 -0
  6. data/lib/ruby_yacht/dsl/app.rb +0 -2
  7. data/lib/ruby_yacht/dsl/dsl.rb +31 -14
  8. data/lib/ruby_yacht/dsl/project.rb +15 -11
  9. data/lib/ruby_yacht/images/app/Dockerfile.erb +4 -16
  10. data/lib/ruby_yacht/images/app/before_startup.bash.erb +1 -3
  11. data/lib/ruby_yacht/images/app/startup.bash.erb +1 -3
  12. data/lib/ruby_yacht/images/app-dependencies/Dockerfile.erb +5 -11
  13. data/lib/ruby_yacht/images/database/Dockerfile.erb +6 -5
  14. data/lib/ruby_yacht/images/web/Dockerfile.erb +4 -2
  15. data/lib/ruby_yacht/images/web/add_app.rb +1 -0
  16. data/lib/ruby_yacht/images/web/app_config.erb +13 -0
  17. data/lib/ruby_yacht/plugins/rails/scripts/load_seeds.rb +11 -4
  18. data/lib/ruby_yacht/runner/build_images.rb +114 -31
  19. data/lib/ruby_yacht/runner/run_containers.rb +1 -10
  20. data/ruby_yacht.gemspec +2 -2
  21. data/spec/dsl/app_type_spec.rb +5 -5
  22. data/spec/dsl/project_spec.rb +44 -0
  23. data/spec/fixtures/app-dependencies-dockerfile-generic +5 -0
  24. data/spec/fixtures/app-dependencies-dockerfile-generic-with-library-install +1 -0
  25. data/spec/fixtures/app-dependencies-dockerfile-rails +1 -0
  26. data/spec/fixtures/mars-dockerfile +2 -3
  27. data/spec/fixtures/mars-dockerfile-rails +2 -4
  28. data/spec/fixtures/mars-dockerfile-with-after-checkout-hooks +2 -4
  29. data/spec/fixtures/mars-dockerfile-with-before-startup-hooks +2 -3
  30. data/spec/fixtures/multi-project-web-dockerfile +4 -4
  31. data/spec/fixtures/web-dockerfile +2 -2
  32. data/spec/fixtures/web-dockerfile-with-primary-app +20 -0
  33. data/spec/plugins/rails_spec.rb +1 -1
  34. data/spec/runner/build_images_spec.rb +10 -10
  35. data/spec/runner/run_containers_spec.rb +2 -31
  36. metadata +4 -4
  37. data/lib/ruby_yacht/images/deploy/Dockerfile.erb +0 -2
  38. data/lib/ruby_yacht/images/web/setup.rb +0 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8fe86d0666f935e2212841266623b3f2fc4b0fdc
4
- data.tar.gz: 5f5c2ed02c41aaf4f9b98dd3fc79e8110a43d2cc
3
+ metadata.gz: 60a4d2f558965415e5cd128391116e187b05c165
4
+ data.tar.gz: fa574d48c920037379ecf355ce1e07a31a5795ff
5
5
  SHA512:
6
- metadata.gz: f4ad7a074ec77f4e8cfd1716ea69de349d0180125da4f7964420a1890c157c444a61eb7b06682e5dd672008fd55fdf01c4d037744286af4dd423be57cdccaa12
7
- data.tar.gz: efc077fdd18c3485ce9f6ff25ad066c55dea2315324087aaa589a1ee6eb003b6bf0feb82c252ff9d4f96a91d335a0eb4a22d9a68cb341605edd3cc3d507d36f0
6
+ metadata.gz: 3a534420ae3d0eb73b31ae1f60c930d64bd217cca3717a04e50ac526d291952d024ebb3b604dd97cb5418fda3bc7fd2078220668dc01ca8651919db02d61ea15
7
+ data.tar.gz: 03bba6e531b6b21bb96250593f06bad135d796bf88bfe21358e92ade3ca194470b2b463a22d00ac5270e53890e9624febffba66d7638842654dac9a12fcce5a0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby_yacht (0.1.1)
4
+ ruby_yacht (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -3,6 +3,7 @@ Rails apps.
3
3
 
4
4
  [![Code Climate](https://codeclimate.com/github/brownleej/ruby-yacht/badges/gpa.svg)](https://codeclimate.com/github/brownleej/ruby-yacht)
5
5
  [![Test Coverage](https://codeclimate.com/github/brownleej/ruby-yacht/badges/coverage.svg)](https://codeclimate.com/github/brownleej/ruby-yacht/coverage)
6
+ [![Build Status](https://travis-ci.org/brownleej/ruby-yacht.svg?branch=master)](https://travis-ci.org/brownleej/ruby-yacht)
6
7
 
7
8
  # Prerequisites
8
9
 
data/doc/TODO.md CHANGED
@@ -4,17 +4,15 @@ for open tickets.
4
4
  # General
5
5
 
6
6
  * Do more testing with remote databases and non-development environments
7
- * Consider whether deploy containers are worth including
8
7
  * Consider whether using the same web server for multiple projects is the best
9
8
  approach
10
9
  * Look into issues with running shell command that has its own command-line
11
10
  flags.
11
+ * Add formal documentation on configuration DSL.
12
12
 
13
13
  # Plugins
14
14
 
15
- * Move more of the hooks to using the include_event helper
16
15
  * Add documentation on plugin API
17
- * Supporting shared databases between apps of different types
18
16
 
19
17
  # More Command Line Options
20
18
 
@@ -24,9 +22,6 @@ for open tickets.
24
22
 
25
23
  # More customization
26
24
 
27
- * Add customizations for installation
28
- * Add customization for post-checkout hooks
29
- * Using one of the apps for the bare domain
30
25
  * Defining custom commands
31
26
  * Allowing customization points at different levels, like adding hooks to
32
27
  individual apps
@@ -49,6 +49,10 @@ RubyYacht.configure do
49
49
  # This app's repository is at github.com/brownleej/saturn
50
50
  repository_name 'brownleej/saturn'
51
51
  end
52
+
53
+ # This indicates that apollo.docker.local should serve requests to the mars
54
+ # app.
55
+ primary_app :mars
52
56
  end
53
57
 
54
58
  # This is a second project that runs a different set of apps, with different
@@ -79,6 +83,9 @@ RubyYacht.configure do
79
83
  rails_app :saturn do
80
84
  repository_name 'brownleej/saturn'
81
85
  end
86
+
87
+ # Because this project has no primary app, jupiter.docker.local will serve
88
+ # an ad-hoc landing page with links to the individual apps.
82
89
  end
83
90
  end
84
91
 
@@ -67,8 +67,6 @@ module RubyYacht
67
67
  add_attribute :port, 8080
68
68
 
69
69
  creates_object App
70
-
71
-
72
70
 
73
71
  # This method checks that all of the required attributes have been set on
74
72
  # the object.
@@ -208,27 +208,44 @@ module RubyYacht
208
208
 
209
209
  if self.class.created_type
210
210
  dsl_type = self.class.created_type.name.split('::').last.downcase
211
- copied_attributes = self.class.copied_attributes
212
-
213
211
  RubyYacht.configuration.app_types.each do |app_type|
214
212
  next if @app_type && app_type.name != @app_type
215
- attributes = app_type.send("#{dsl_type}_attributes") || [] rescue []
216
- attributes.each do |attribute|
217
- if attribute.has_key?(:required)
218
- required = attribute[:required]
219
- else
220
- required = true
221
- end
222
- name = "#{app_type.name}_#{attribute[:name]}"
223
- self.singleton_class.add_attribute name, attribute[:default], required
224
- self.singleton_class.copied_attributes << name
225
- self.class.created_type.instance_eval do
226
- attr_accessor name
213
+ method_name = "#{dsl_type}_attributes"
214
+ if app_type.respond_to?("#{dsl_type}_attributes")
215
+ attributes = app_type.send(method_name)
216
+ attributes.each do |attribute|
217
+ attribute = attribute.merge(name: "#{app_type.name}_#{attribute[:name]}")
218
+ load_custom_attribute(attribute)
227
219
  end
228
220
  end
229
221
  end
230
222
  end
231
223
  end
224
+
225
+ private
226
+
227
+ # This method defines the fields for a custom attribute on the DSL.
228
+ #
229
+ # ### Parameters
230
+ #
231
+ # * **attribute: Hash** The settings on the attribute. The `name`
232
+ # setting must already include the app type's
233
+ # prefix.
234
+ def load_custom_attribute(attribute)
235
+ if attribute.has_key?(:required)
236
+ required = attribute[:required]
237
+ else
238
+ required = true
239
+ end
240
+ name = attribute[:name]
241
+ self.singleton_class.add_attribute name, attribute[:default], required
242
+ self.singleton_class.copied_attributes << name
243
+ self.class.created_type.instance_eval do
244
+ attr_accessor name
245
+ end
246
+ end
247
+
248
+ public
232
249
 
233
250
  # This method runs a block with DSL methods.
234
251
  #
@@ -27,10 +27,6 @@ module RubyYacht
27
27
  # keeping it entirely inside the container.
28
28
  attr_accessor :check_out_locally
29
29
 
30
- # Whether we should create a special container with all the apps for running
31
- # deploys.
32
- attr_accessor :create_deploy_container
33
-
34
30
  # The configuration for the database. This is a RubyYacht::Database.
35
31
  attr_accessor :database
36
32
 
@@ -39,6 +35,15 @@ module RubyYacht
39
35
 
40
36
  # The configuration for the DNS for the apps. This is a RubyYacht::DnsServer.
41
37
  attr_accessor :dns_server
38
+
39
+ # The name of the primary app for the project.
40
+ #
41
+ # This app will respond to requests to the bare domain with no app
42
+ # subdomain. It will also respond under its normal subdomain.
43
+ #
44
+ # If this is not provided, this will create a special index page for the
45
+ # bare domain, with links to each app.
46
+ attr_accessor :primary_app
42
47
 
43
48
  # This class provides a DSL for configuring a project.
44
49
  #
@@ -78,6 +83,12 @@ module RubyYacht
78
83
  # You can call `repository 'github.com'` to set the project's `repository`
79
84
  # to `github.com`
80
85
  add_attribute :repository
86
+
87
+ #
88
+ # :method: primary_app
89
+ # You can call `primary_app :app1` to tell the project to use `app1` as
90
+ # the app under the bare domain.
91
+ add_attribute :primary_app, nil, false
81
92
 
82
93
  ##
83
94
  # :method: check_out_locally
@@ -86,13 +97,6 @@ module RubyYacht
86
97
  # `check_out_locally` flag to `true`. The default is false.
87
98
  add_boolean :check_out_locally
88
99
 
89
- ##
90
- # :method: create_deploy_container
91
- #
92
- # You can call `create_deploy_container` to set the project's
93
- # `create_deploy_container` flag to `true`. The default is false.
94
- add_boolean :create_deploy_container
95
-
96
100
  ##
97
101
  # :method: app
98
102
  #
@@ -6,33 +6,21 @@ ENV DATABASE_PASSWORD <%= @project.database.password %>
6
6
  ENV DATABASE_USERNAME <%= @project.database.username %>
7
7
  ENV APP_PORT <%= @app.port %>
8
8
  ENV REPOSITORY_HOST <%= @project.repository %>
9
+ ENV REPOSITORY_NAME <%= @app.repository_name %>
9
10
  ENV SYSTEM_PREFIX <%= @project.system_prefix %>
10
- <% app_type = RubyYacht.configuration.find_app_type(@app.app_type) %>
11
- <% app_type.environment_variables.select { |variable| variable[:image] == :app }.each do |variable| %>
12
- ENV <%= variable[:name] %> <%= instance_eval(&variable[:block]) %>
13
- <% end %>
11
+ <%= include_environment_variables :app %>
14
12
 
15
13
  RUN rm -r /var/code
16
14
  RUN mkdir -p /var/code
17
15
 
18
- ENV REPOSITORY_NAME <%= @app.repository_name %>
19
16
  COPY checkout.bash /var/docker/checkout.bash
20
- RUN bash /var/docker/checkout.bash
21
-
22
17
  COPY before_startup.bash /var/docker/before_startup.bash
23
18
  COPY startup.bash /var/docker/startup.bash
24
- <% RubyYacht.configuration.fetch_hooks(app_type: @app.app_type).select { |hook| hook.script_name != '' }.each do |hook| %>
25
- <% next unless [:startup, :build_checkout].include?(hook.event_type) %>
26
- COPY <%= hook.script_name %> /var/docker/<%= hook.script_name %>
27
- <% end %>
19
+ <%= copy_hooks [:startup, :build_checkout] %>
28
20
 
29
21
  RUN chmod u+x /var/docker/*
30
22
 
31
- WORKDIR /var/code
32
-
33
- <% RubyYacht.configuration.fetch_hooks(app_type: @app.app_type, event_time: :after, event_type: :build_checkout).each do |hook| %>
34
- RUN <%= hook.command %>
35
- <% end %>
23
+ <%= include_event(:build_checkout) { "RUN /var/docker/checkout.bash\nWORKDIR /var/code"} %>
36
24
 
37
25
  EXPOSE <%= @app.port %>
38
26
 
@@ -3,6 +3,4 @@
3
3
  cd /var/code;
4
4
  /var/docker/checkout.bash;
5
5
 
6
- <% RubyYacht.configuration.fetch_hooks(app_type: @app.app_type, event_time: :before, event_type: :startup).each do |hook| %>
7
- <%= hook.command %>;
8
- <% end %>
6
+ <%= include_event :startup, :before, in_bash: true %>
@@ -1,5 +1,3 @@
1
1
  #! /bin/bash
2
2
  /var/docker/before_startup.bash;
3
- <% RubyYacht.configuration.fetch_hooks(app_type: @app.app_type, event_time: :during, event_type: :startup).each do |hook| %>
4
- <%= hook.command %>;
5
- <% end %>
3
+ <%= include_event :startup, [:during, :after], in_bash: true %>
@@ -6,34 +6,28 @@
6
6
 
7
7
  FROM <%= @app_type.baseline_image %>
8
8
 
9
+ <%= include_environment_variables :app_dependencies %>
10
+
9
11
  RUN mkdir -p /root/.ssh
10
12
  COPY id_rsa /root/.ssh
11
13
  RUN ssh-keyscan <%= @project.repository %> >> /root/.ssh/known_hosts
12
14
 
13
15
  RUN mkdir -p /var/docker/
16
+ RUN touch /var/docker/.keep
14
17
 
15
- <% library_scripts = RubyYacht.configuration.fetch_hooks(app_type: @app_type.name, event_time: :during, event_type: :install_libraries).select { |hook| hook.script_name != '' } %>
16
- <% library_scripts.each do |hook |%>
17
- COPY <%= hook.script_name %> /var/docker/<%= hook.script_name %>
18
- <% end %>
18
+ <%= copy_hooks [:install_libraries] %>
19
19
 
20
- <% if library_scripts.any? %>
21
20
  RUN chmod u+x /var/docker/*
22
- <% end %>
23
21
 
24
22
  <% @project.apps.each do |app| %>
25
23
  <% next unless app.app_type == @app_type.name %>
26
24
 
27
25
  RUN git clone git@<%= @project.repository %>:<%= app.repository_name %> /var/code/<%= app.name %>
28
26
  WORKDIR /var/code/<%= app.name %>
29
- <% RubyYacht.configuration.fetch_hooks(app_type: @app_type.name, event_time: :during, event_type: :install_libraries).each do |hook |%>
30
- RUN <%= hook.command %>
31
- <% end %>
27
+ <%= include_event :install_libraries %>
32
28
  <% end %>
33
29
 
34
- <% if library_scripts.any? %>
35
30
  RUN rm /var/docker/*
36
- <% end %>
37
31
 
38
32
  WORKDIR /
39
33
 
@@ -7,13 +7,14 @@ RUN apt-get install -y mysql-server
7
7
  ENV DATABASE_USERNAME <%= @project.database.username %>
8
8
  ENV DATABASE_PASSWORD <%= @project.database.password %>
9
9
  ENV DATABASE_NAME <%= @project.database.name %>
10
+ <% with_each_app_type do %>
11
+ <%= include_environment_variables :database %>
12
+ <% end %>
10
13
 
11
14
  COPY setup.bash /var/docker/setup.bash
12
15
  COPY checkout.bash /var/docker/checkout.bash
13
- <% @project.apps.map(&:app_type).uniq.each do |app_type| %>
14
- <% RubyYacht.configuration.fetch_hooks(app_type: app_type, event_type: :load_database_seeds).each do |hook| %>
15
- COPY <%= hook.script_name %> /var/docker/<%= hook.script_name %>
16
- <% end %>
16
+ <% with_each_app_type do %>
17
+ <%= copy_hooks [:load_database_seeds] %>
17
18
  <% end %>
18
19
 
19
20
  RUN chmod u+x /var/docker/*
@@ -21,10 +22,10 @@ RUN chmod u+x /var/docker/*
21
22
  RUN /var/docker/setup.bash <%= database.name %> <%= database.username %> <%= database.password %>
22
23
 
23
24
  <% @project.apps.each do |app| %>
25
+ <% @app_type = RubyYacht.configuration.find_app_type(app.app_type) %>
24
26
 
25
27
  RUN /var/docker/checkout.bash <%= @project.repository %> <%= app.name %> <%= app.repository_name %>
26
28
  WORKDIR /var/code/<%= app.name %>
27
- <% @app_type = RubyYacht.configuration.find_app_type(app.app_type) %>
28
29
  <%= include_event :load_database_seeds %>
29
30
  <% end %>
30
31
 
@@ -13,11 +13,13 @@ COPY index_config.erb /var/docker/index_config.erb
13
13
  COPY app_config.erb /var/docker/app_config.erb
14
14
 
15
15
  <% @projects.each do |project| %>
16
-
16
+ <% if project.primary_app == nil %>
17
17
  <% app_list = project.apps.map(&:name).join(',') %>
18
+
18
19
  RUN ruby /var/docker/add_project.rb <%= project.system_prefix %> <%= project.domain %> <%= app_list %>
20
+ <% end %>
19
21
  <% project.apps.each do |app| %>
20
- RUN ruby /var/docker/add_app.rb <%= project.system_prefix %> <%= project.domain %> <%= app.name %> <%= app.port %>
22
+ RUN ruby /var/docker/add_app.rb <%= project.system_prefix %> <%= project.domain %> <%= app.name %> <%= app.port %> <%= app.name == project.primary_app %>
21
23
  <% end %>
22
24
  <% end %>
23
25
 
@@ -6,6 +6,7 @@ require 'erb'
6
6
  @app = ARGV.shift
7
7
  @port = ARGV.shift
8
8
  @container_name = "#{@project}-#{@app}"
9
+ @is_primary_app = ARGV.shift == 'true'
9
10
 
10
11
  File.open(File.join("/etc/nginx/conf.d/#{@container_name}.conf"), 'w') do |file|
11
12
  file.write(ERB.new(File.read('/var/docker/app_config.erb')).result(binding))
@@ -9,3 +9,16 @@ server {
9
9
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
10
10
  }
11
11
  }
12
+ <% if @is_primary_app %>
13
+ server {
14
+ listen 80;
15
+ server_name <%= @domain %>;
16
+
17
+ location / {
18
+ proxy_pass http://<%= @container_name %>:<%= @port %>;
19
+ proxy_redirect off;
20
+ proxy_set_header Host $host;
21
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
22
+ }
23
+ }
24
+ <% end %>
@@ -9,15 +9,20 @@ system "service mysql start"
9
9
 
10
10
  config_path = "./config/database.yml"
11
11
 
12
+ username = ENV['DATABASE_USERNAME']
13
+ password = ENV['DATABASE_PASSWORD']
14
+ database = ENV['DATABASE_NAME']
15
+
16
+
12
17
  database_config = {
13
18
  'development' => {
14
19
  'adapter' => 'mysql2',
15
20
  'encoding' => 'utf8',
16
21
  'reconnect' => true,
17
- 'username' => ENV['DATABASE_USERNAME'],
18
- 'password' => ENV['DATABASE_PASSWORD'],
22
+ 'username' => username,
23
+ 'password' => password,
19
24
  'host' => 'localhost',
20
- 'database' => ENV['DATABASE_NAME']
25
+ 'database' => database
21
26
  }
22
27
  }
23
28
 
@@ -26,8 +31,10 @@ File.open(config_path, "w") do |file|
26
31
  end
27
32
 
28
33
  system "bundle install"
29
- tables = `mysql -uroot -e "SHOW TABLES" #{ENV['DATABASE_NAME']}`
34
+ tables = `mysql -uroot -e "SHOW TABLES" #{database}`
30
35
  if tables == ''
36
+ test_database_command = "CREATE DATABASE #{database}_test; GRANT ALL ON #{database}_test.* TO '#{username}'@'%';"
37
+ system "mysql -uroot -e \"#{test_database_command}\""
31
38
  system "bundle exec rake db:reset"
32
39
  else
33
40
  system "bundle exec rake db:migrate; bundle exec rake db:seed"
@@ -41,10 +41,6 @@ module RubyYacht::Runner
41
41
  build_image 'app', "#{@project.system_prefix}-#{app.name}"
42
42
  end
43
43
  @app = nil
44
-
45
- if @project.create_deploy_container
46
- build_image 'deploy'
47
- end
48
44
  end
49
45
 
50
46
  @projects = projects
@@ -78,28 +74,10 @@ module RubyYacht::Runner
78
74
  FileUtils.cp(path, File.join('tmp', File.basename(path)))
79
75
  end
80
76
 
81
- templates =
82
- case folder_name
83
- when 'app' then ['Dockerfile', 'before_startup.bash', 'startup.bash']
84
- else ['Dockerfile']
85
- end
77
+ set_image_settings(folder_name)
86
78
 
87
- hook_events =
88
- case folder_name
89
- when 'app' then [:startup, :build_checkout]
90
- when 'app-dependencies' then [:install_libraries]
91
- when 'database' then [:load_database_seeds]
92
- else []
93
- end
94
-
95
- app_types =
96
- case folder_name
97
- when 'database' then @project.apps.map(&:app_type).uniq
98
- else [@app_type.name]
99
- end
100
-
101
- hook_events.each do |event|
102
- app_types.each do |app_type|
79
+ @hook_events.each do |event|
80
+ @app_types.each do |app_type|
103
81
  RubyYacht.configuration.fetch_hooks(app_type: app_type, event_type: event).each do |hook|
104
82
  next unless hook.script_path
105
83
  FileUtils.cp hook.script_path, "tmp"
@@ -107,7 +85,7 @@ module RubyYacht::Runner
107
85
  end
108
86
  end
109
87
 
110
- templates.each do |template_name|
88
+ @templates.each do |template_name|
111
89
  File.open(File.join('tmp', template_name), 'w') do |file|
112
90
  template_contents = File.read(File.join('tmp', template_name + '.erb'))
113
91
  file_contents = ERB.new(template_contents, nil, '<>').result(binding)
@@ -122,6 +100,38 @@ module RubyYacht::Runner
122
100
 
123
101
  FileUtils.rm(Dir[File.join("tmp", "*")])
124
102
  end
103
+
104
+ # This method establishes settings for building an image.
105
+ #
106
+ # This will set the `@templates`, `@hook_events`, and `@app_types` instance
107
+ # variables.
108
+ #
109
+ # ### Parameters
110
+ #
111
+ # * **folder_name: String** The name of the folder containing the image
112
+ # files.
113
+ def set_image_settings(folder_name)
114
+ @templates =
115
+ case folder_name
116
+ when 'app' then ['Dockerfile', 'before_startup.bash', 'startup.bash']
117
+ else ['Dockerfile']
118
+ end
119
+
120
+ @hook_events =
121
+ case folder_name
122
+ when 'app' then [:startup, :build_checkout]
123
+ when 'app-dependencies' then [:install_libraries]
124
+ when 'database' then [:load_database_seeds]
125
+ else []
126
+ end
127
+
128
+ @app_types =
129
+ case folder_name
130
+ when 'database' then @project.apps.map(&:app_type).uniq
131
+ else [@app_type.name]
132
+ end
133
+ end
134
+
125
135
 
126
136
  # This method includes the hooks for an event in a Dockerfile.
127
137
  #
@@ -130,20 +140,93 @@ module RubyYacht::Runner
130
140
  #
131
141
  # ### Parameters
132
142
  #
133
- # * **event_type: Symbol** The event whose hooks we are running.
143
+ # * **event_type: Symbol** The event whose hooks we are running.
144
+ # * **times: [Symbol]** The event times whose hooks we want to
145
+ # include. You can also pass a symbol to this
146
+ # method, which will cause it to include only
147
+ # that event time.
148
+ # * **options: [Hash]** Additional flags for customizing the output.
149
+ # At this time, the only option is `in_bash`,
150
+ # which indicates whether the commands are
151
+ # running in bash rather than a Dockerfile.
152
+ # * **block** This also takes a block, which should yield
153
+ # fixed contents for the "during" section of
154
+ # the event.
134
155
  #
135
156
  # ### Returns
136
157
  #
137
158
  # A String with the contents of the Dockerfile for running the hooks.
138
- def include_event(event_type)
159
+ def include_event(event_type, times = [:before, :during, :after], options = {})
139
160
  result = ""
140
- [:before, :during, :after].each do |time|
141
- before_hooks = RubyYacht.configuration.fetch_hooks(app_type: @app_type.name, event_type: event_type, event_time: time).each do |hook|
142
- result += "RUN #{hook.command}\n"
161
+ if times.is_a?(Symbol)
162
+ times = [times]
163
+ end
164
+ times.each do |time|
165
+ if time == :during && block_given?
166
+ result += yield
167
+ result += "\n"
168
+ next
169
+ end
170
+ RubyYacht.configuration.fetch_hooks(app_type: @app_type.name, event_type: event_type, event_time: time).each do |hook|
171
+ if options[:in_bash]
172
+ result += "#{hook.command};\n"
173
+ else
174
+ result += "RUN #{hook.command}\n"
175
+ end
143
176
  end
144
177
  end
145
178
 
146
179
  result
147
180
  end
181
+
182
+ # This method includes the app environment variables for the current app
183
+ # type.
184
+ #
185
+ # ### Parameters
186
+ #
187
+ # * **image_type: Symbol** The image type that we're building. This can
188
+ # be `app_dependencies`, `app`, or `database`.
189
+ #
190
+ # ### Returns
191
+ #
192
+ # A String with the contents of the Dockerfile for adding the environment
193
+ # variables.
194
+ def include_environment_variables(image_type)
195
+ result = ""
196
+ @app_type.environment_variables.select { |variable| variable[:image] == image_type }.each do |variable|
197
+ result += "ENV #{variable[:name]} #{instance_eval(&variable[:block])}\n"
198
+ end
199
+ result
200
+ end
201
+
202
+ # This method includes commands for copying script files for the hooks for
203
+ # the current app type.
204
+ #
205
+ # ### Parameters
206
+ #
207
+ # * **event_types: [Symbol]** The events whose hooks we should include.
208
+ #
209
+ # ### Returns
210
+ #
211
+ # A String with the contents of the Dockerfile for copying the script.
212
+ def copy_hooks(event_types)
213
+ result = ""
214
+ RubyYacht.configuration.fetch_hooks(app_type: @app_type.name).each do |hook|
215
+ next if hook.script_name == ''
216
+ next unless event_types.include?(hook.event_type)
217
+ result += "COPY #{hook.script_name} /var/docker/#{hook.script_name}\n"
218
+ end
219
+ result
220
+ end
221
+
222
+ # This method goes through all the app types for the apps in the project,
223
+ # sets each one as the `@app_type` instance variable, and then yields to the
224
+ # block passed to the method.
225
+ def with_each_app_type
226
+ @project.apps.map(&:app_type).uniq.each do |app_type|
227
+ @app_type = RubyYacht.configuration.find_app_type(app_type)
228
+ yield
229
+ end
230
+ end
148
231
  end
149
232
  end
@@ -26,10 +26,6 @@ module RubyYacht::Runner
26
26
  project.apps.each do |app|
27
27
  run_container app.name
28
28
  end
29
-
30
- if @project.create_deploy_container
31
- run_container :deploy
32
- end
33
29
  end
34
30
 
35
31
  @project = projects.first
@@ -59,11 +55,7 @@ module RubyYacht::Runner
59
55
  # the system prefix.
60
56
  def volume_flags(container_name)
61
57
  if @project.check_out_locally && ![:database, :web].include?(container_name)
62
- if container_name == :deploy
63
- return ["-v $PWD/../code:/var/code"]
64
- else
65
- return ["-v $PWD/../code/#{container_name}:/var/code"]
66
- end
58
+ return ["-v $PWD/../#{container_name}:/var/code"]
67
59
  else
68
60
  return []
69
61
  end
@@ -84,7 +76,6 @@ module RubyYacht::Runner
84
76
  flags = ["-d"]
85
77
  flags += dns_server_flags
86
78
  flags += volume_flags(name)
87
- flags << "-it" if name == :deploy
88
79
  flags << "-p 80:80" if name == :web
89
80
  flags << "--net=#{@network}"
90
81
  flags << "--net-alias=#{container_name}"
data/ruby_yacht.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'ruby_yacht'
3
- spec.version = '0.2.0'
4
- spec.date = '2016-04-17'
3
+ spec.version = '0.3.0'
4
+ spec.date = '2016-04-19'
5
5
  spec.description = "A DSL for building docker containers for a family of Rails apps"
6
6
  spec.summary = "A DSL for building docker containers for a family of Rails apps"
7
7
  spec.authors = ["John Brownlee"]
@@ -50,7 +50,7 @@ describe RubyYacht::AppType do
50
50
  block = project_configuration_block
51
51
  RubyYacht.configure do
52
52
  project :test do
53
- instance_eval &block
53
+ instance_eval(&block)
54
54
  app_type_test_foo 'test value'
55
55
 
56
56
  app_type_test_app :test do
@@ -68,7 +68,7 @@ describe RubyYacht::AppType do
68
68
  block = project_configuration_block
69
69
  RubyYacht.configure do
70
70
  project :test do
71
- instance_eval &block
71
+ instance_eval(&block)
72
72
  app_type_test_foo 'test value'
73
73
  end
74
74
  end
@@ -82,7 +82,7 @@ describe RubyYacht::AppType do
82
82
  block = project_configuration_block
83
83
  RubyYacht.configure do
84
84
  project :test do
85
- instance_eval &block
85
+ instance_eval(&block)
86
86
  app_type_test_foo 'test value'
87
87
 
88
88
  app :test1, :app_type_test do
@@ -102,7 +102,7 @@ describe RubyYacht::AppType do
102
102
  block = project_configuration_block
103
103
  RubyYacht.configure do
104
104
  project :test do
105
- instance_eval &block
105
+ instance_eval(&block)
106
106
  app_type_test_foo 'test value'
107
107
 
108
108
  app :test1, :generic do
@@ -128,7 +128,7 @@ describe RubyYacht::AppType do
128
128
  expect(lambda do
129
129
  RubyYacht.configure do
130
130
  project :test do
131
- instance_eval &block
131
+ instance_eval(&block)
132
132
  end
133
133
  end
134
134
  end).to raise_exception "Missing required attribute app_type_test_foo for RubyYacht::Project::DSL"
@@ -35,12 +35,15 @@ describe RubyYacht::Project do
35
35
  dns_server do
36
36
  server '8.10.1.1'
37
37
  end
38
+
39
+ primary_app :app1
38
40
  end
39
41
 
40
42
  expect(project.name).to eq :test_project
41
43
  expect(project.system_prefix).to eq :a
42
44
  expect(project.domain).to eq "a.test.com"
43
45
  expect(project.repository).to eq "github.com"
46
+ expect(project.primary_app).to eq :app1
44
47
 
45
48
  expect(project.apps.map(&:name)).to eq [:app1, :app2]
46
49
  expect(project.database.name).to eq 'project1'
@@ -70,6 +73,8 @@ describe RubyYacht::Project do
70
73
  dns_server do
71
74
  server '8.10.1.1'
72
75
  end
76
+
77
+ primary_app :app1
73
78
  end
74
79
 
75
80
  expect { project }.to raise_exception "Missing required attribute system_prefix for RubyYacht::Project::DSL"
@@ -98,6 +103,8 @@ describe RubyYacht::Project do
98
103
  dns_server do
99
104
  server '8.10.1.1'
100
105
  end
106
+
107
+ primary_app :app1
101
108
  end
102
109
 
103
110
  expect { project }.to raise_exception "Missing required attribute domain for RubyYacht::Project::DSL"
@@ -126,6 +133,8 @@ describe RubyYacht::Project do
126
133
  dns_server do
127
134
  server '8.10.1.1'
128
135
  end
136
+
137
+ primary_app :app1
129
138
  end
130
139
 
131
140
  expect { project }.to raise_exception "Missing required attribute repository for RubyYacht::Project::DSL"
@@ -147,6 +156,8 @@ describe RubyYacht::Project do
147
156
  dns_server do
148
157
  server '8.10.1.1'
149
158
  end
159
+
160
+ primary_app :app1
150
161
  end
151
162
 
152
163
  expect(project.apps.count).to eq 0
@@ -169,6 +180,8 @@ describe RubyYacht::Project do
169
180
  dns_server do
170
181
  server '8.10.1.1'
171
182
  end
183
+
184
+ primary_app :app1
172
185
  end
173
186
 
174
187
  expect { project }.to raise_exception "Missing required attribute database for RubyYacht::Project::DSL"
@@ -194,9 +207,40 @@ describe RubyYacht::Project do
194
207
  username "test"
195
208
  password "test"
196
209
  end
210
+
211
+ primary_app :app1
197
212
  end
198
213
 
199
214
  expect(project.dns_server).to be_nil
200
215
  end
216
+
217
+ it "does not require the primary_app field" do
218
+ @builder = Proc.new do
219
+ system_prefix :a
220
+ domain "a.test.com"
221
+ repository "github.com"
222
+
223
+ app :app1, :generic do
224
+ repository_name 'brownleej/test1'
225
+ end
226
+
227
+ app :app2, :generic do
228
+ repository_name 'brownleej/test2'
229
+ end
230
+
231
+ database do
232
+ host "localhost"
233
+ name "project1"
234
+ username "test"
235
+ password "test"
236
+ end
237
+
238
+ dns_server do
239
+ server '8.10.1.1'
240
+ end
241
+ end
242
+
243
+ expect(project.primary_app).to be_nil
244
+ end
201
245
  end
202
246
  end
@@ -11,10 +11,15 @@ COPY id_rsa /root/.ssh
11
11
  RUN ssh-keyscan github.com >> /root/.ssh/known_hosts
12
12
 
13
13
  RUN mkdir -p /var/docker/
14
+ RUN touch /var/docker/.keep
15
+
16
+ RUN chmod u+x /var/docker/*
14
17
 
15
18
  RUN git clone git@github.com:brownleej/mars /var/code/mars
16
19
  WORKDIR /var/code/mars
17
20
 
21
+ RUN rm /var/docker/*
22
+
18
23
  WORKDIR /
19
24
 
20
25
  RUN apt-get update && apt-get upgrade -y
@@ -11,6 +11,7 @@ COPY id_rsa /root/.ssh
11
11
  RUN ssh-keyscan github.com >> /root/.ssh/known_hosts
12
12
 
13
13
  RUN mkdir -p /var/docker/
14
+ RUN touch /var/docker/.keep
14
15
 
15
16
  COPY hook2.rb /var/docker/hook2.rb
16
17
 
@@ -11,6 +11,7 @@ COPY id_rsa /root/.ssh
11
11
  RUN ssh-keyscan github.com >> /root/.ssh/known_hosts
12
12
 
13
13
  RUN mkdir -p /var/docker/
14
+ RUN touch /var/docker/.keep
14
15
 
15
16
  COPY install_gems.rb /var/docker/install_gems.rb
16
17
 
@@ -6,20 +6,19 @@ ENV DATABASE_PASSWORD test
6
6
  ENV DATABASE_USERNAME apollo
7
7
  ENV APP_PORT 8080
8
8
  ENV REPOSITORY_HOST github.com
9
+ ENV REPOSITORY_NAME brownleej/mars
9
10
  ENV SYSTEM_PREFIX apollo
10
11
 
11
12
  RUN rm -r /var/code
12
13
  RUN mkdir -p /var/code
13
14
 
14
- ENV REPOSITORY_NAME brownleej/mars
15
15
  COPY checkout.bash /var/docker/checkout.bash
16
- RUN bash /var/docker/checkout.bash
17
-
18
16
  COPY before_startup.bash /var/docker/before_startup.bash
19
17
  COPY startup.bash /var/docker/startup.bash
20
18
 
21
19
  RUN chmod u+x /var/docker/*
22
20
 
21
+ RUN /var/docker/checkout.bash
23
22
  WORKDIR /var/code
24
23
 
25
24
  EXPOSE 8080
@@ -6,6 +6,7 @@ ENV DATABASE_PASSWORD test
6
6
  ENV DATABASE_USERNAME apollo
7
7
  ENV APP_PORT 8080
8
8
  ENV REPOSITORY_HOST github.com
9
+ ENV REPOSITORY_NAME brownleej/mars
9
10
  ENV SYSTEM_PREFIX apollo
10
11
  ENV RAILS_ENV development
11
12
  ENV SECRET_KEY_BASE abc
@@ -13,10 +14,7 @@ ENV SECRET_KEY_BASE abc
13
14
  RUN rm -r /var/code
14
15
  RUN mkdir -p /var/code
15
16
 
16
- ENV REPOSITORY_NAME brownleej/mars
17
17
  COPY checkout.bash /var/docker/checkout.bash
18
- RUN bash /var/docker/checkout.bash
19
-
20
18
  COPY before_startup.bash /var/docker/before_startup.bash
21
19
  COPY startup.bash /var/docker/startup.bash
22
20
  COPY update_rails_config.rb /var/docker/update_rails_config.rb
@@ -24,8 +22,8 @@ COPY prepare_rails_for_launch.rb /var/docker/prepare_rails_for_launch.rb
24
22
 
25
23
  RUN chmod u+x /var/docker/*
26
24
 
25
+ RUN /var/docker/checkout.bash
27
26
  WORKDIR /var/code
28
-
29
27
  RUN bundle install && bundle clean --force
30
28
 
31
29
  EXPOSE 8080
@@ -6,23 +6,21 @@ ENV DATABASE_PASSWORD test
6
6
  ENV DATABASE_USERNAME apollo
7
7
  ENV APP_PORT 8080
8
8
  ENV REPOSITORY_HOST github.com
9
+ ENV REPOSITORY_NAME brownleej/mars
9
10
  ENV SYSTEM_PREFIX apollo
10
11
 
11
12
  RUN rm -r /var/code
12
13
  RUN mkdir -p /var/code
13
14
 
14
- ENV REPOSITORY_NAME brownleej/mars
15
15
  COPY checkout.bash /var/docker/checkout.bash
16
- RUN bash /var/docker/checkout.bash
17
-
18
16
  COPY before_startup.bash /var/docker/before_startup.bash
19
17
  COPY startup.bash /var/docker/startup.bash
20
18
  COPY hook1.rb /var/docker/hook1.rb
21
19
 
22
20
  RUN chmod u+x /var/docker/*
23
21
 
22
+ RUN /var/docker/checkout.bash
24
23
  WORKDIR /var/code
25
-
26
24
  RUN /var/docker/hook1.rb
27
25
 
28
26
  EXPOSE 8080
@@ -6,15 +6,13 @@ ENV DATABASE_PASSWORD test
6
6
  ENV DATABASE_USERNAME apollo
7
7
  ENV APP_PORT 8080
8
8
  ENV REPOSITORY_HOST github.com
9
+ ENV REPOSITORY_NAME brownleej/mars
9
10
  ENV SYSTEM_PREFIX apollo
10
11
 
11
12
  RUN rm -r /var/code
12
13
  RUN mkdir -p /var/code
13
14
 
14
- ENV REPOSITORY_NAME brownleej/mars
15
15
  COPY checkout.bash /var/docker/checkout.bash
16
- RUN bash /var/docker/checkout.bash
17
-
18
16
  COPY before_startup.bash /var/docker/before_startup.bash
19
17
  COPY startup.bash /var/docker/startup.bash
20
18
  COPY hook1.rb /var/docker/hook1.rb
@@ -22,6 +20,7 @@ COPY hook2.rb /var/docker/hook2.rb
22
20
 
23
21
  RUN chmod u+x /var/docker/*
24
22
 
23
+ RUN /var/docker/checkout.bash
25
24
  WORKDIR /var/code
26
25
 
27
26
  EXPOSE 8080
@@ -13,12 +13,12 @@ COPY index_config.erb /var/docker/index_config.erb
13
13
  COPY app_config.erb /var/docker/app_config.erb
14
14
 
15
15
  RUN ruby /var/docker/add_project.rb apollo apollo.test.com mars,saturn
16
- RUN ruby /var/docker/add_app.rb apollo apollo.test.com mars 8080
17
- RUN ruby /var/docker/add_app.rb apollo apollo.test.com saturn 8080
16
+ RUN ruby /var/docker/add_app.rb apollo apollo.test.com mars 8080 false
17
+ RUN ruby /var/docker/add_app.rb apollo apollo.test.com saturn 8080 false
18
18
 
19
19
  RUN ruby /var/docker/add_project.rb jupiter jupiter.test.com venus,saturn
20
- RUN ruby /var/docker/add_app.rb jupiter jupiter.test.com venus 8080
21
- RUN ruby /var/docker/add_app.rb jupiter jupiter.test.com saturn 8080
20
+ RUN ruby /var/docker/add_app.rb jupiter jupiter.test.com venus 8080 false
21
+ RUN ruby /var/docker/add_app.rb jupiter jupiter.test.com saturn 8080 false
22
22
 
23
23
  RUN rm -r /var/docker
24
24
  RUN apt-get remove -y ruby
@@ -13,8 +13,8 @@ COPY index_config.erb /var/docker/index_config.erb
13
13
  COPY app_config.erb /var/docker/app_config.erb
14
14
 
15
15
  RUN ruby /var/docker/add_project.rb apollo apollo.test.com mars,saturn
16
- RUN ruby /var/docker/add_app.rb apollo apollo.test.com mars 8080
17
- RUN ruby /var/docker/add_app.rb apollo apollo.test.com saturn 8080
16
+ RUN ruby /var/docker/add_app.rb apollo apollo.test.com mars 8080 false
17
+ RUN ruby /var/docker/add_app.rb apollo apollo.test.com saturn 8080 false
18
18
 
19
19
  RUN rm -r /var/docker
20
20
  RUN apt-get remove -y ruby
@@ -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 mars 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
@@ -170,7 +170,7 @@ describe RubyYacht::Plugins::Rails do
170
170
  it "generates the dockerfiles for the web server" do
171
171
  docker.expect "build -t apollo-web tmp" do
172
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']
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']
174
174
  dockerfile = File.read(File.join('tmp', 'Dockerfile'))
175
175
  expected = File.read(File.join('spec', 'fixtures', 'web-dockerfile'))
176
176
  expect(dockerfile).to eq expected
@@ -63,7 +63,7 @@ describe RubyYacht::Runner::BuildImages do
63
63
  it "generates the dockerfiles for the web server" do
64
64
  docker.expect "build -t apollo-web tmp" do
65
65
  files = Dir[File.join("tmp", "*")].sort
66
- 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']
66
+ 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']
67
67
  dockerfile = File.read(File.join('tmp', 'Dockerfile'))
68
68
  expected = File.read(File.join('spec', 'fixtures', 'web-dockerfile'))
69
69
  expect(dockerfile).to eq expected
@@ -158,18 +158,18 @@ describe RubyYacht::Runner::BuildImages do
158
158
  end
159
159
  end
160
160
  end
161
-
162
- context "with a deploy container" do
161
+
162
+ context "with an app set up as the primary app" do
163
163
  before do
164
- RubyYacht.configuration.projects.first.create_deploy_container = true
164
+ RubyYacht.configuration.projects[0].primary_app = :mars
165
165
  end
166
-
167
- it "creates the deploy container" do
168
- docker.expect("build -t apollo-deploy tmp") do
166
+
167
+ it "includes that app in the setup in the web server dockerfile" do
168
+ docker.expect "build -t apollo-web tmp" do
169
169
  files = Dir[File.join("tmp", "*")].sort
170
- expect(files).to eq ['tmp/Dockerfile', 'tmp/Dockerfile.erb']
170
+ 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']
171
171
  dockerfile = File.read(File.join('tmp', 'Dockerfile'))
172
- expected = File.read(File.join('spec', 'fixtures', 'deploy-dockerfile'))
172
+ expected = File.read(File.join('spec', 'fixtures', 'web-dockerfile-with-primary-app'))
173
173
  expect(dockerfile).to eq expected
174
174
  end
175
175
  subject.run
@@ -198,7 +198,7 @@ describe RubyYacht::Runner::BuildImages do
198
198
  it "generates one dockerfile for the web server with both projects" do
199
199
  docker.expect "build -t apollo-web tmp" do
200
200
  files = Dir[File.join("tmp", "*")].sort
201
- 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']
201
+ 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']
202
202
  dockerfile = File.read(File.join('tmp', 'Dockerfile'))
203
203
  expected = File.read(File.join('spec', 'fixtures', 'multi-project-web-dockerfile'))
204
204
  expect(dockerfile).to eq expected
@@ -32,21 +32,6 @@ describe RubyYacht::Runner::RunContainers do
32
32
  expect(subject.run).to be_truthy
33
33
  end
34
34
 
35
- context "with a deploy container" do
36
- before do
37
- RubyYacht.configuration.projects.first.create_deploy_container = true
38
- end
39
-
40
- it "runs the deploy container" do
41
- docker.expect 'run -d -it --net=apollo --net-alias=apollo-deploy --name=apollo-deploy apollo-deploy'
42
- subject.run
43
- end
44
-
45
- it "returns true" do
46
- expect(subject.run).to be_truthy
47
- end
48
- end
49
-
50
35
  context "with a local database" do
51
36
  before do
52
37
  RubyYacht.configuration.projects.first.database.host = 'localhost'
@@ -106,28 +91,14 @@ describe RubyYacht::Runner::RunContainers do
106
91
  end
107
92
 
108
93
  it "maps the code volume to a local directory" do
109
- docker.expect 'run -d -v $PWD/../code/mars:/var/code --net=apollo --net-alias=apollo-mars --name=apollo-mars apollo-mars'
110
- docker.expect 'run -d -v $PWD/../code/saturn:/var/code --net=apollo --net-alias=apollo-saturn --name=apollo-saturn apollo-saturn'
94
+ docker.expect 'run -d -v $PWD/../mars:/var/code --net=apollo --net-alias=apollo-mars --name=apollo-mars apollo-mars'
95
+ docker.expect 'run -d -v $PWD/../saturn:/var/code --net=apollo --net-alias=apollo-saturn --name=apollo-saturn apollo-saturn'
111
96
  subject.run
112
97
  end
113
98
 
114
99
  it "returns true" do
115
100
  expect(subject.run).to be_truthy
116
101
  end
117
-
118
- context "when creating a deploy container" do
119
- before do
120
- RubyYacht.configuration.projects.first.create_deploy_container = true
121
- end
122
- it "maps the code volume to a local directory" do
123
- docker.expect 'run -d -v $PWD/../code:/var/code -it --net=apollo --net-alias=apollo-deploy --name=apollo-deploy apollo-deploy'
124
- subject.run
125
- end
126
-
127
- it "returns true" do
128
- expect(subject.run).to be_truthy
129
- end
130
- end
131
102
  end
132
103
  end
133
104
 
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.2.0
4
+ version: 0.3.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-04-17 00:00:00.000000000 Z
11
+ date: 2016-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -89,14 +89,12 @@ files:
89
89
  - lib/ruby_yacht/images/database/Dockerfile.erb
90
90
  - lib/ruby_yacht/images/database/checkout.bash
91
91
  - lib/ruby_yacht/images/database/setup.bash
92
- - lib/ruby_yacht/images/deploy/Dockerfile.erb
93
92
  - lib/ruby_yacht/images/web/Dockerfile.erb
94
93
  - lib/ruby_yacht/images/web/add_app.rb
95
94
  - lib/ruby_yacht/images/web/add_project.rb
96
95
  - lib/ruby_yacht/images/web/app_config.erb
97
96
  - lib/ruby_yacht/images/web/index.html.erb
98
97
  - lib/ruby_yacht/images/web/index_config.erb
99
- - lib/ruby_yacht/images/web/setup.rb
100
98
  - lib/ruby_yacht/plugins.rb
101
99
  - lib/ruby_yacht/plugins/rails.rb
102
100
  - lib/ruby_yacht/plugins/rails/scripts/install_gems.rb
@@ -146,6 +144,7 @@ files:
146
144
  - spec/fixtures/mars-startup-rails
147
145
  - spec/fixtures/multi-project-web-dockerfile
148
146
  - spec/fixtures/web-dockerfile
147
+ - spec/fixtures/web-dockerfile-with-primary-app
149
148
  - spec/plugins/rails_spec.rb
150
149
  - spec/runner/build_images_spec.rb
151
150
  - spec/runner/build_spec.rb
@@ -216,6 +215,7 @@ test_files:
216
215
  - spec/fixtures/mars-startup-rails
217
216
  - spec/fixtures/multi-project-web-dockerfile
218
217
  - spec/fixtures/web-dockerfile
218
+ - spec/fixtures/web-dockerfile-with-primary-app
219
219
  - spec/plugins/rails_spec.rb
220
220
  - spec/runner/build_images_spec.rb
221
221
  - spec/runner/build_spec.rb
@@ -1,2 +0,0 @@
1
- FROM <%= @project.system_prefix %>-app-dependencies
2
- CMD bash
@@ -1,22 +0,0 @@
1
- #! /usr/local/bin/ruby
2
- require 'erb'
3
- require 'fileutils'
4
-
5
- @project = ARGV.shift
6
- @domain = ARGV.shift
7
- @app_names = ARGV.shift.split(',')
8
- @app_ports = ARGV.shift.split(',')
9
-
10
- File.open(File.join("/usr/share/nginx/html/#{@project}.html"), 'w') do |file|
11
- file.write(ERB.new(File.read('/var/docker/index.html.erb')).result(binding))
12
- end
13
-
14
- File.open(File.join("/etc/nginx/conf.d/#{@project}.conf"), 'w') do |file|
15
- file.write(ERB.new(File.read('/var/docker/index_config.erb')).result(binding))
16
- @app_names.each_with_index do |app, port|
17
- @app = app
18
- @app_port = port
19
- @container_name = @project + '-' + @app
20
- file.write(ERB.new(File.read('/var/docker/app_config.erb')).result(binding))
21
- end
22
- end