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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/doc/TODO.md +1 -8
- data/lib/ruby_yacht/dsl/app.rb +37 -10
- data/lib/ruby_yacht/dsl/configuration.rb +21 -21
- data/lib/ruby_yacht/dsl/database.rb +53 -0
- data/lib/ruby_yacht/dsl/dsl.rb +14 -8
- data/lib/ruby_yacht/dsl/hook.rb +35 -15
- data/lib/ruby_yacht/dsl/project.rb +23 -10
- data/lib/ruby_yacht/dsl/{app_type.rb → server_type.rb} +39 -29
- data/lib/ruby_yacht/dsl.rb +1 -1
- data/lib/ruby_yacht/images/app/Dockerfile.erb +9 -5
- data/lib/ruby_yacht/images/app-dependencies/Dockerfile.erb +2 -2
- data/lib/ruby_yacht/images/database/Dockerfile.erb +12 -11
- data/lib/ruby_yacht/images/web/Dockerfile.erb +6 -2
- data/lib/ruby_yacht/images/web/add_app.rb +7 -1
- data/lib/ruby_yacht/images/web/app_config.erb +2 -0
- data/lib/ruby_yacht/plugins/mysql/scripts/setup.bash +11 -0
- data/lib/ruby_yacht/plugins/mysql.rb +27 -0
- data/lib/ruby_yacht/plugins/rails/scripts/install_gems.rb +6 -1
- data/lib/ruby_yacht/plugins/rails/scripts/load_seeds.rb +6 -4
- data/lib/ruby_yacht/plugins/rails/scripts/prepare_rails_for_launch.rb +1 -0
- data/lib/ruby_yacht/plugins/rails/scripts/update_rails_config.rb +1 -5
- data/lib/ruby_yacht/plugins/rails.rb +12 -4
- data/lib/ruby_yacht/plugins.rb +2 -1
- data/lib/ruby_yacht/runner/build_images.rb +32 -26
- data/lib/ruby_yacht/runner/checkout.rb +5 -4
- data/lib/ruby_yacht/runner/run_containers.rb +7 -6
- data/lib/ruby_yacht/runner/services.rb +2 -2
- data/lib/ruby_yacht/runner/shell.rb +5 -4
- data/lib/ruby_yacht/runner/update_hosts.rb +2 -1
- data/ruby_yacht.gemspec +1 -1
- data/spec/dsl/app_spec.rb +96 -10
- data/spec/dsl/configuration_spec.rb +53 -55
- data/spec/dsl/database_spec.rb +70 -12
- data/spec/dsl/hook_spec.rb +36 -19
- data/spec/dsl/project_spec.rb +26 -18
- data/spec/dsl/{app_type_spec.rb → server_type_spec.rb} +52 -28
- data/spec/fixtures/app-dependencies-dockerfile-rails +3 -0
- data/spec/fixtures/database-dockerfile +1 -8
- data/spec/fixtures/database-dockerfile-mysql +30 -0
- data/spec/fixtures/database-dockerfile-rails +1 -5
- data/spec/fixtures/database-dockerfile-with-seed-hooks +1 -8
- data/spec/fixtures/mars-before-startup-with-custom-file-copy +6 -0
- data/spec/fixtures/mars-dockerfile +0 -4
- data/spec/fixtures/mars-dockerfile-rails +2 -2
- data/spec/fixtures/mars-dockerfile-with-after-checkout-hooks +0 -4
- data/spec/fixtures/mars-dockerfile-with-before-startup-hooks +0 -4
- data/spec/fixtures/mars-dockerfile-with-custom-file-copy +23 -0
- data/spec/fixtures/mars-dockerfile-with-local-database +27 -0
- data/spec/fixtures/mars-dockerfile-with-remote-database +27 -0
- data/spec/fixtures/web-dockerfile-with-eponymous-app +20 -0
- data/spec/plugins/mysql_spec.rb +64 -0
- data/spec/plugins/rails_spec.rb +103 -43
- data/spec/runner/build_images_spec.rb +142 -11
- data/spec/runner/checkout_spec.rb +4 -4
- data/spec/runner/run_containers_spec.rb +21 -2
- data/spec/runner/runner_spec.rb +1 -1
- data/spec/runner/services_spec.rb +7 -2
- data/spec/runner/shell_spec.rb +3 -3
- data/spec/runner/update_hosts_spec.rb +26 -0
- data/spec/support/test_project.rb +16 -20
- metadata +20 -5
- data/lib/ruby_yacht/images/database/setup.bash +0 -15
@@ -1,69 +1,72 @@
|
|
1
1
|
module RubyYacht
|
2
|
-
# This class represents a type of
|
2
|
+
# This class represents a type of server that the user can configure.
|
3
3
|
#
|
4
|
-
# An
|
5
|
-
# types are defined by plugins, which also provide the logic for
|
6
|
-
# and running the
|
4
|
+
# An server type corresponds to a major server framework, like Ruby on Rails.
|
5
|
+
# Server types are defined by plugins, which also provide the logic for
|
6
|
+
# installing and running the server.
|
7
7
|
#
|
8
|
-
# You can configure this with RubyYacht::
|
9
|
-
class
|
8
|
+
# You can configure this with RubyYacht::ServerType::DSL
|
9
|
+
class ServerType
|
10
10
|
# The name of the type.
|
11
11
|
attr_accessor :name
|
12
12
|
|
13
|
-
# The
|
13
|
+
# The type of container that this should be applied to.
|
14
|
+
attr_accessor :container_type
|
15
|
+
|
16
|
+
# The attributes that we define on the project DSL once this server type has
|
14
17
|
# been loaded.
|
15
18
|
#
|
16
19
|
# Each entry will be a hash with a key for `name`, and optionally a key for
|
17
20
|
# `default` and `required`. These values will be given to the
|
18
21
|
# `add_attribute` method in the project DSL.
|
19
22
|
#
|
20
|
-
# The attribute names will be prefixed with the
|
21
|
-
# instance, if the `rails`
|
23
|
+
# The attribute names will be prefixed with the server type's name. For
|
24
|
+
# instance, if the `rails` server type provides an `environment` attribute,
|
22
25
|
# it will be called `rails_environment` on the project's DSL. This prevents
|
23
26
|
# conflicts with attributes from other plugins.
|
24
27
|
attr_accessor :project_attributes
|
25
28
|
|
26
|
-
# The attributes that we define on the
|
29
|
+
# The attributes that we define on the server DSL once this server type has
|
27
30
|
# been loaded.
|
28
31
|
#
|
29
32
|
# Each entry will be a hash with a key for `name`, and optionally a key for
|
30
33
|
# `default` and `required`. These values will be given to the
|
31
34
|
# `add_attribute` method in the project DSL.
|
32
35
|
#
|
33
|
-
# The attributes will only be defined on
|
36
|
+
# The attributes will only be defined on servers with this server type.
|
34
37
|
#
|
35
|
-
# The attribute names will be prefixed with the
|
36
|
-
# instance, if the `rails`
|
37
|
-
# it will be called `rails_environment` on the
|
38
|
+
# The attribute names will be prefixed with the server type's name. For
|
39
|
+
# instance, if the `rails` server type provides an `environment` attribute,
|
40
|
+
# it will be called `rails_environment` on the server's DSL. This prevents
|
38
41
|
# conflicts with attributes from other plugins.
|
39
|
-
attr_accessor :
|
42
|
+
attr_accessor :server_attributes
|
40
43
|
|
41
|
-
# The docker image that we use as the source for the
|
44
|
+
# The docker image that we use as the source for the server images.
|
42
45
|
attr_accessor :baseline_image
|
43
46
|
|
44
|
-
# The custom environment variables that we set in the images for this
|
47
|
+
# The custom environment variables that we set in the images for this server
|
45
48
|
# type.
|
46
49
|
#
|
47
50
|
# Each entry will be a hash with the following keys:
|
48
51
|
#
|
49
52
|
# * **name: String** The name of the environment variable
|
50
|
-
# * **image: String** The type of image that this is set in (e.g.
|
53
|
+
# * **image: String** The type of image that this is set in (e.g. server
|
51
54
|
# or database).
|
52
55
|
# * **block** A block that will be called inside the Dockerfile
|
53
56
|
# ERB for providing the value of the environment
|
54
57
|
# variable.
|
55
58
|
attr_accessor :environment_variables
|
56
59
|
|
57
|
-
# This class provides a DSL for configuring a RubyYacht::
|
60
|
+
# This class provides a DSL for configuring a RubyYacht::ServerType.
|
58
61
|
class DSL
|
59
62
|
include RubyYacht::DSL::Base
|
60
63
|
extend RubyYacht::DSL::Base::ClassMethods
|
61
64
|
|
62
|
-
# This initiailzer creates the
|
65
|
+
# This initiailzer creates the server type DSL.
|
63
66
|
#
|
64
67
|
# ### Parameters
|
65
68
|
#
|
66
|
-
# * **name: Symbol** The name of the
|
69
|
+
# * **name: Symbol** The name of the server type.
|
67
70
|
def initialize(name)
|
68
71
|
@name = name
|
69
72
|
@environment_variables = []
|
@@ -72,10 +75,16 @@ module RubyYacht
|
|
72
75
|
|
73
76
|
add_attribute :name
|
74
77
|
|
78
|
+
#
|
79
|
+
# :method: container_type
|
80
|
+
# You can call `container_type :app` to say that this server type is for
|
81
|
+
# apps. Other acceptable values are `database` and `web`.
|
82
|
+
add_attribute :container_type
|
83
|
+
|
75
84
|
#
|
76
85
|
# :method: baseline_image
|
77
86
|
# You can call `baseline_image 'ubuntu'` to use ubuntu as the source
|
78
|
-
# image for the
|
87
|
+
# image for the server containers for this server type.
|
79
88
|
add_attribute :baseline_image
|
80
89
|
|
81
90
|
#
|
@@ -85,13 +94,14 @@ module RubyYacht
|
|
85
94
|
add_list :project_attribute
|
86
95
|
|
87
96
|
#
|
88
|
-
# :method:
|
89
|
-
# You can call `
|
97
|
+
# :method: server_attribute
|
98
|
+
# You can call `server_attribute name: :environment, default: 'staging'`
|
90
99
|
# to add an attribute to the app DSL.
|
91
|
-
add_list :
|
100
|
+
add_list :server_attribute
|
92
101
|
|
93
|
-
creates_object RubyYacht::
|
94
|
-
:
|
102
|
+
creates_object RubyYacht::ServerType, [:name, :baseline_image,
|
103
|
+
:container_type, :project_attributes, :server_attributes,
|
104
|
+
:environment_variables]
|
95
105
|
|
96
106
|
# This method defines a new environment variable set for this app type.
|
97
107
|
#
|
@@ -102,8 +112,8 @@ module RubyYacht
|
|
102
112
|
# * **name: String** The name of the environment variable.
|
103
113
|
# * **block** A block for generating the environment variable.
|
104
114
|
# This will have access to the project (as @project)
|
105
|
-
# and the
|
106
|
-
# image for.
|
115
|
+
# and the server (as @server) that we are building
|
116
|
+
# the image for.
|
107
117
|
def environment_variable(image, name, &block)
|
108
118
|
@environment_variables << {image: image, name: name, block: block}
|
109
119
|
end
|
data/lib/ruby_yacht/dsl.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
-
FROM <%= @project.system_prefix %>-<%= @app.
|
1
|
+
FROM <%= @project.system_prefix %>-<%= @app.server_type %>-app-dependencies
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
ENV
|
6
|
-
ENV
|
3
|
+
<% database = @app.database(@project) %>
|
4
|
+
<% if database %>
|
5
|
+
ENV DATABASE_HOST <%= database.local? ? database.container_name(@project) : database.host %>
|
6
|
+
ENV DATABASE_NAME <%= database.name %>
|
7
|
+
ENV DATABASE_PASSWORD <%= database.password %>
|
8
|
+
ENV DATABASE_USERNAME <%= database.username %>
|
9
|
+
ENV DATABASE_TYPE <%= database.server_type %>
|
10
|
+
<% end %>
|
7
11
|
ENV APP_PORT <%= @app.port %>
|
8
12
|
ENV REPOSITORY_HOST <%= @project.repository %>
|
9
13
|
ENV REPOSITORY_NAME <%= @app.repository_name %>
|
@@ -4,7 +4,7 @@
|
|
4
4
|
# This is a slow process, so this should be kept as simple as possible so that
|
5
5
|
# it can remain unchanged.
|
6
6
|
|
7
|
-
FROM <%= @
|
7
|
+
FROM <%= @server_type.baseline_image %>
|
8
8
|
|
9
9
|
<%= include_environment_variables :app_dependencies %>
|
10
10
|
|
@@ -20,7 +20,7 @@ RUN touch /var/docker/.keep
|
|
20
20
|
RUN chmod u+x /var/docker/*
|
21
21
|
|
22
22
|
<% @project.apps.each do |app| %>
|
23
|
-
<% next unless app.
|
23
|
+
<% next unless app.server_type == @server_type.name %>
|
24
24
|
|
25
25
|
RUN git clone git@<%= @project.repository %>:<%= app.repository_name %> /var/code/<%= app.name %>
|
26
26
|
WORKDIR /var/code/<%= app.name %>
|
@@ -1,16 +1,16 @@
|
|
1
|
-
FROM <%= @project.system_prefix %>-<%= @
|
2
|
-
<% database = @project.database %>
|
1
|
+
FROM <%= @project.system_prefix %>-<%= @app_server_type.name %>-app-dependencies
|
3
2
|
|
4
|
-
ENV
|
5
|
-
|
6
|
-
|
7
|
-
ENV
|
8
|
-
|
9
|
-
ENV DATABASE_NAME <%= @project.database.name %>
|
3
|
+
ENV DATABASE_USERNAME <%= @database.username %>
|
4
|
+
ENV DATABASE_PASSWORD <%= @database.password %>
|
5
|
+
ENV DATABASE_NAME <%= @database.name %>
|
6
|
+
ENV DATABASE_TYPE <%= @database.server_type %>
|
7
|
+
<%= include_environment_variables :database %>
|
10
8
|
<% with_each_app_type do %>
|
11
9
|
<%= include_environment_variables :database %>
|
12
10
|
<% end %>
|
13
11
|
|
12
|
+
<%= include_event :install_libraries %>
|
13
|
+
|
14
14
|
COPY setup.bash /var/docker/setup.bash
|
15
15
|
COPY checkout.bash /var/docker/checkout.bash
|
16
16
|
<% with_each_app_type do %>
|
@@ -19,10 +19,11 @@ COPY checkout.bash /var/docker/checkout.bash
|
|
19
19
|
|
20
20
|
RUN chmod u+x /var/docker/*
|
21
21
|
|
22
|
-
|
22
|
+
<%= include_event :create_databases %>
|
23
23
|
|
24
|
-
<% @project.apps.
|
25
|
-
<%
|
24
|
+
<% apps = @project.apps.select { |app| app.database_name == @database.name } %>
|
25
|
+
<% apps.each do |app| %>
|
26
|
+
<% @server_type = RubyYacht.configuration.find_server_type(app.server_type) %>
|
26
27
|
|
27
28
|
RUN /var/docker/checkout.bash <%= @project.repository %> <%= app.name %> <%= app.repository_name %>
|
28
29
|
WORKDIR /var/code/<%= app.name %>
|
@@ -13,13 +13,17 @@ 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
|
+
<% primary_app = project.primary_app %>
|
17
|
+
<% if project.apps.any? { |app| app.name == project.system_prefix } %>
|
18
|
+
<% primary_app = project.system_prefix %>
|
19
|
+
<% end %>
|
20
|
+
<% if primary_app == nil %>
|
17
21
|
<% app_list = project.apps.map(&:name).join(',') %>
|
18
22
|
|
19
23
|
RUN ruby /var/docker/add_project.rb <%= project.system_prefix %> <%= project.domain %> <%= app_list %>
|
20
24
|
<% end %>
|
21
25
|
<% project.apps.each do |app| %>
|
22
|
-
RUN ruby /var/docker/add_app.rb <%= project.system_prefix %> <%= project.domain %> <%= app.name %> <%= app.port %> <%= app.name ==
|
26
|
+
RUN ruby /var/docker/add_app.rb <%= project.system_prefix %> <%= project.domain %> <%= app.name %> <%= app.port %> <%= app.name == primary_app %>
|
23
27
|
<% end %>
|
24
28
|
<% end %>
|
25
29
|
|
@@ -5,7 +5,13 @@ require 'erb'
|
|
5
5
|
@domain = ARGV.shift
|
6
6
|
@app = ARGV.shift
|
7
7
|
@port = ARGV.shift
|
8
|
-
|
8
|
+
|
9
|
+
if @project == @app
|
10
|
+
@container_name = @project
|
11
|
+
else
|
12
|
+
@container_name = "#{@project}-#{@app}"
|
13
|
+
end
|
14
|
+
|
9
15
|
@is_primary_app = ARGV.shift == 'true'
|
10
16
|
|
11
17
|
File.open(File.join("/etc/nginx/conf.d/#{@container_name}.conf"), 'w') do |file|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
<% if @app != @project %>
|
1
2
|
server {
|
2
3
|
listen 80;
|
3
4
|
server_name <%= @app %>.<%= @domain %>;
|
@@ -9,6 +10,7 @@ server {
|
|
9
10
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
10
11
|
}
|
11
12
|
}
|
13
|
+
<% end %>
|
12
14
|
<% if @is_primary_app %>
|
13
15
|
server {
|
14
16
|
listen 80;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
#! /bin/bash
|
2
|
+
|
3
|
+
service mysql start;
|
4
|
+
COMMAND="CREATE USER '$DATABASE_USERNAME'@'localhost' IDENTIFIED BY '$DATABASE_PASSWORD';";
|
5
|
+
COMMAND="$COMMAND CREATE USER '$DATABASE_USERNAME'@'%' IDENTIFIED BY '$DATABASE_PASSWORD';";
|
6
|
+
|
7
|
+
COMMAND="$COMMAND GRANT ALL ON $DATABASE_NAME.* to '$DATABASE_USERNAME'@'localhost';";
|
8
|
+
COMMAND="$COMMAND GRANT ALL ON $DATABASE_NAME.* to '$DATABASE_USERNAME'@'%';";
|
9
|
+
COMMAND="$COMMAND CREATE DATABASE $DATABASE_NAME;";
|
10
|
+
|
11
|
+
mysql -uroot -e "$COMMAND";
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module RubyYacht::Plugins
|
2
|
+
# This module provides the plugin for managing MySQL databases.
|
3
|
+
module MySQL
|
4
|
+
# This method loads the configuration for the MySQL plugin.
|
5
|
+
def self.load
|
6
|
+
RubyYacht.configure do
|
7
|
+
server_type :mysql do
|
8
|
+
container_type :database
|
9
|
+
baseline_image 'mysql'
|
10
|
+
|
11
|
+
environment_variable :database, 'DEBIAN_FRONTEND' do
|
12
|
+
'noninteractive'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
RubyYacht.configure do
|
18
|
+
add_hooks(server_type: :mysql, folder: File.join(File.dirname(__FILE__), 'mysql', 'scripts')) do
|
19
|
+
during(:install_libraries) { command 'apt-get install -y mysql-server' }
|
20
|
+
during(:create_databases) { run_script 'setup.bash' }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
RubyYacht::Plugins::MySQL.load
|
@@ -12,10 +12,10 @@ config_path = "./config/database.yml"
|
|
12
12
|
username = ENV['DATABASE_USERNAME']
|
13
13
|
password = ENV['DATABASE_PASSWORD']
|
14
14
|
database = ENV['DATABASE_NAME']
|
15
|
-
|
15
|
+
rails_env = ENV['RAILS_ENV']
|
16
16
|
|
17
17
|
database_config = {
|
18
|
-
|
18
|
+
rails_env => {
|
19
19
|
'adapter' => 'mysql2',
|
20
20
|
'encoding' => 'utf8',
|
21
21
|
'reconnect' => true,
|
@@ -33,8 +33,10 @@ end
|
|
33
33
|
system "bundle install"
|
34
34
|
tables = `mysql -uroot -e "SHOW TABLES" #{database}`
|
35
35
|
if tables == ''
|
36
|
-
|
37
|
-
|
36
|
+
if rails_env == 'development'
|
37
|
+
test_database_command = "CREATE DATABASE #{database}_test; GRANT ALL ON #{database}_test.* TO '#{username}'@'%';"
|
38
|
+
system "mysql -uroot -e \"#{test_database_command}\""
|
39
|
+
end
|
38
40
|
system "bundle exec rake db:reset"
|
39
41
|
else
|
40
42
|
system "bundle exec rake db:migrate; bundle exec rake db:seed"
|
@@ -2,10 +2,6 @@
|
|
2
2
|
require 'yaml'
|
3
3
|
|
4
4
|
database_host = ENV['DATABASE_HOST']
|
5
|
-
local_database = (database_host == 'localhost')
|
6
|
-
if local_database
|
7
|
-
database_host = ENV['SYSTEM_PREFIX'] + '-database'
|
8
|
-
end
|
9
5
|
|
10
6
|
common_config = {
|
11
7
|
'adapter' => 'mysql2',
|
@@ -20,7 +16,7 @@ database_config = {
|
|
20
16
|
ENV['RAILS_ENV'] => common_config
|
21
17
|
}
|
22
18
|
|
23
|
-
if ENV['RAILS_ENV'] == 'development'
|
19
|
+
if ENV['RAILS_ENV'] == 'development'
|
24
20
|
database_config['test'] = common_config.dup
|
25
21
|
database_config['test']['database'] += '_test'
|
26
22
|
end
|
@@ -4,26 +4,34 @@ module RubyYacht::Plugins
|
|
4
4
|
# This method loads the configuration for the Rails plugin.
|
5
5
|
def self.load
|
6
6
|
RubyYacht.configure do
|
7
|
-
|
7
|
+
server_type :rails do
|
8
|
+
container_type :app
|
8
9
|
baseline_image 'ruby:2.3'
|
9
10
|
project_attribute name: :environment, default: 'development'
|
11
|
+
project_attribute name: :excluded_gem_groups, default: []
|
10
12
|
project_attribute name: :secret_key_base
|
11
13
|
|
12
|
-
environment_variable :
|
14
|
+
environment_variable :app_dependencies, 'RAILS_ENV' do
|
13
15
|
@project.rails_environment
|
14
16
|
end
|
15
17
|
|
16
18
|
environment_variable :app, 'SECRET_KEY_BASE' do
|
17
19
|
@project.rails_secret_key_base
|
18
20
|
end
|
21
|
+
|
22
|
+
environment_variable :app_dependencies, 'EXCLUDED_GEM_GROUPS' do
|
23
|
+
groups = @project.rails_excluded_gem_groups.join(' ')
|
24
|
+
groups = '""' if groups == ''
|
25
|
+
groups
|
26
|
+
end
|
19
27
|
end
|
20
28
|
end
|
21
29
|
|
22
30
|
RubyYacht.configure do
|
23
|
-
add_hooks(
|
31
|
+
add_hooks(server_type: :rails, folder: File.join(File.dirname(__FILE__), 'rails', 'scripts')) do
|
24
32
|
during(:install_libraries) { run_script 'install_gems.rb' }
|
25
33
|
|
26
|
-
after(:build_checkout) { command 'bundle install
|
34
|
+
after(:build_checkout) { command 'bundle install --clean' }
|
27
35
|
|
28
36
|
during(:load_database_seeds) { run_script 'load_seeds.rb' }
|
29
37
|
|
data/lib/ruby_yacht/plugins.rb
CHANGED
@@ -24,21 +24,24 @@ module RubyYacht::Runner
|
|
24
24
|
|
25
25
|
id_path = File.join(ENV['HOME'], '.ssh', 'id_rsa')
|
26
26
|
tmp_id_path = File.join('tmp', 'id_rsa')
|
27
|
-
if File.exist?(id_path)
|
28
|
-
FileUtils.cp(id_path, tmp_id_path)
|
29
|
-
end
|
27
|
+
FileUtils.cp(id_path, tmp_id_path) if File.exist?(id_path)
|
30
28
|
|
31
|
-
project.apps.map(&:
|
32
|
-
@
|
33
|
-
build_image 'app-dependencies', "#{@project.system_prefix}-#{@
|
29
|
+
project.apps.map(&:server_type).uniq.each do |type_name|
|
30
|
+
@server_type = RubyYacht.configuration.find_server_type(type_name)
|
31
|
+
build_image 'app-dependencies', "#{@project.system_prefix}-#{@server_type.name}-app-dependencies"
|
34
32
|
end
|
35
33
|
|
36
|
-
|
34
|
+
project.databases.select(&:local?).each do |database|
|
35
|
+
@app_server_type = @server_type
|
36
|
+
@database = database
|
37
|
+
@server_type = RubyYacht.configuration.find_server_type(@database.server_type)
|
38
|
+
build_image 'database', @database.container_name(@project)
|
39
|
+
end
|
37
40
|
|
38
41
|
@project.apps.each do |app|
|
39
42
|
@app = app
|
40
|
-
@
|
41
|
-
build_image 'app',
|
43
|
+
@server_type = RubyYacht.configuration.find_server_type(@app.server_type)
|
44
|
+
build_image 'app', @app.container_name(@project)
|
42
45
|
end
|
43
46
|
@app = nil
|
44
47
|
end
|
@@ -77,10 +80,10 @@ module RubyYacht::Runner
|
|
77
80
|
set_image_settings(folder_name)
|
78
81
|
|
79
82
|
@hook_events.each do |event|
|
80
|
-
@
|
81
|
-
RubyYacht.configuration.fetch_hooks(
|
82
|
-
next unless hook.
|
83
|
-
FileUtils.cp hook.
|
83
|
+
@server_types.each do |server_type|
|
84
|
+
RubyYacht.configuration.fetch_hooks(server_type: server_type, event_type: event).each do |hook|
|
85
|
+
next unless hook.copied_file_path
|
86
|
+
FileUtils.cp hook.copied_file_path, "tmp"
|
84
87
|
end
|
85
88
|
end
|
86
89
|
end
|
@@ -96,6 +99,7 @@ module RubyYacht::Runner
|
|
96
99
|
end
|
97
100
|
|
98
101
|
image_name ||= "#{@project.system_prefix}-#{folder_name}"
|
102
|
+
|
99
103
|
docker "build -t #{image_name} tmp"
|
100
104
|
|
101
105
|
FileUtils.rm(Dir[File.join("tmp", "*")])
|
@@ -103,7 +107,7 @@ module RubyYacht::Runner
|
|
103
107
|
|
104
108
|
# This method establishes settings for building an image.
|
105
109
|
#
|
106
|
-
# This will set the `@templates`, `@hook_events`, and `@
|
110
|
+
# This will set the `@templates`, `@hook_events`, and `@server_types` instance
|
107
111
|
# variables.
|
108
112
|
#
|
109
113
|
# ### Parameters
|
@@ -121,14 +125,14 @@ module RubyYacht::Runner
|
|
121
125
|
case folder_name
|
122
126
|
when 'app' then [:startup, :build_checkout]
|
123
127
|
when 'app-dependencies' then [:install_libraries]
|
124
|
-
when 'database' then [:load_database_seeds]
|
128
|
+
when 'database' then [:create_databases, :install_libraries, :load_database_seeds]
|
125
129
|
else []
|
126
130
|
end
|
127
131
|
|
128
|
-
@
|
132
|
+
@server_types =
|
129
133
|
case folder_name
|
130
|
-
when 'database' then @project.apps.map(&:
|
131
|
-
else [@
|
134
|
+
when 'database' then [@server_type.name] + @project.apps.map(&:server_type).uniq
|
135
|
+
else [@server_type.name]
|
132
136
|
end
|
133
137
|
end
|
134
138
|
|
@@ -167,7 +171,7 @@ module RubyYacht::Runner
|
|
167
171
|
result += "\n"
|
168
172
|
next
|
169
173
|
end
|
170
|
-
RubyYacht.configuration.fetch_hooks(
|
174
|
+
RubyYacht.configuration.fetch_hooks(server_type: @server_type.name, event_type: event_type, event_time: time).each do |hook|
|
171
175
|
if options[:in_bash]
|
172
176
|
result += "#{hook.command};\n"
|
173
177
|
else
|
@@ -193,7 +197,7 @@ module RubyYacht::Runner
|
|
193
197
|
# variables.
|
194
198
|
def include_environment_variables(image_type)
|
195
199
|
result = ""
|
196
|
-
@
|
200
|
+
@server_type.environment_variables.select { |variable| variable[:image] == image_type }.each do |variable|
|
197
201
|
result += "ENV #{variable[:name]} #{instance_eval(&variable[:block])}\n"
|
198
202
|
end
|
199
203
|
result
|
@@ -211,22 +215,24 @@ module RubyYacht::Runner
|
|
211
215
|
# A String with the contents of the Dockerfile for copying the script.
|
212
216
|
def copy_hooks(event_types)
|
213
217
|
result = ""
|
214
|
-
RubyYacht.configuration.fetch_hooks(
|
215
|
-
next if hook.
|
218
|
+
RubyYacht.configuration.fetch_hooks(server_type: @server_type.name).each do |hook|
|
219
|
+
next if hook.copied_file_name == ''
|
216
220
|
next unless event_types.include?(hook.event_type)
|
217
|
-
result += "COPY #{hook.
|
221
|
+
result += "COPY #{hook.copied_file_name} /var/docker/#{hook.copied_file_name}\n"
|
218
222
|
end
|
219
223
|
result
|
220
224
|
end
|
221
225
|
|
222
226
|
# This method goes through all the app types for the apps in the project,
|
223
|
-
# sets each one as the `@
|
227
|
+
# sets each one as the `@server_type` instance variable, and then yields to the
|
224
228
|
# block passed to the method.
|
225
229
|
def with_each_app_type
|
226
|
-
|
227
|
-
|
230
|
+
original_server_type = @server_type
|
231
|
+
@project.apps.map(&:server_type).uniq.each do |server_type|
|
232
|
+
@server_type = RubyYacht.configuration.find_server_type(server_type)
|
228
233
|
yield
|
229
234
|
end
|
235
|
+
@server_type = original_server_type
|
230
236
|
end
|
231
237
|
end
|
232
238
|
end
|
@@ -13,7 +13,7 @@ module RubyYacht::Runner
|
|
13
13
|
attr_accessor :project_name
|
14
14
|
|
15
15
|
# The name of the app.
|
16
|
-
attr_accessor :
|
16
|
+
attr_accessor :app_name
|
17
17
|
|
18
18
|
# The branch that we are checking out.
|
19
19
|
attr_accessor :branch
|
@@ -36,13 +36,13 @@ module RubyYacht::Runner
|
|
36
36
|
#
|
37
37
|
# This will take the app name and branch from the command line.
|
38
38
|
def parse_positional_arguments(arguments)
|
39
|
-
self.
|
39
|
+
self.app_name = arguments.shift
|
40
40
|
self.branch = arguments.shift
|
41
41
|
end
|
42
42
|
|
43
43
|
# This method runs the logic for the command.
|
44
44
|
def run
|
45
|
-
if
|
45
|
+
if app_name.nil?
|
46
46
|
log "You must provide an app name"
|
47
47
|
log "Run #{Command.short_script_name} help checkout for more information"
|
48
48
|
return false
|
@@ -56,7 +56,8 @@ module RubyYacht::Runner
|
|
56
56
|
project = self.project_named(self.project_name)
|
57
57
|
return false unless project
|
58
58
|
|
59
|
-
|
59
|
+
app = project.apps.find { |a| a.name == app_name.to_sym }
|
60
|
+
container_name = app.container_name(project)
|
60
61
|
|
61
62
|
docker "exec #{container_name} bash -c 'cd /var/code; git fetch; git checkout .; git checkout #{branch}; git pull'"
|
62
63
|
docker "exec #{container_name} /var/docker/before_startup.bash"
|
@@ -15,12 +15,9 @@ module RubyYacht::Runner
|
|
15
15
|
|
16
16
|
projects.each do |project|
|
17
17
|
@project = project
|
18
|
-
if @project.check_out_locally
|
19
|
-
FileUtils.mkdir_p File.join(ENV["PWD"], '..', 'code')
|
20
|
-
end
|
21
18
|
|
22
|
-
|
23
|
-
run_container
|
19
|
+
project.databases.select(&:local?).each do |database|
|
20
|
+
run_container database.container_label
|
24
21
|
end
|
25
22
|
|
26
23
|
project.apps.each do |app|
|
@@ -70,7 +67,11 @@ module RubyYacht::Runner
|
|
70
67
|
# * **name: Symbol** The name of the container, not including the system
|
71
68
|
# prefix.
|
72
69
|
def run_container(name)
|
73
|
-
|
70
|
+
if name == @project.system_prefix
|
71
|
+
container_name = name
|
72
|
+
else
|
73
|
+
container_name = "#{@project.system_prefix}-#{name}"
|
74
|
+
end
|
74
75
|
remove_container container_name
|
75
76
|
|
76
77
|
flags = ["-d"]
|
@@ -51,8 +51,8 @@ module RubyYacht::Runner
|
|
51
51
|
end
|
52
52
|
|
53
53
|
projects.each do |project|
|
54
|
-
|
55
|
-
docker "#{command} #{project
|
54
|
+
project.databases.select(&:local?).each do |database|
|
55
|
+
docker "#{command} #{database.container_name(project)}"
|
56
56
|
end
|
57
57
|
|
58
58
|
project.apps.each do |app|
|