ruby_yacht 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +27 -0
  3. data/.gitignore +4 -0
  4. data/.rdoc_options +29 -0
  5. data/.rspec +1 -0
  6. data/.rubocop.yml +1156 -0
  7. data/.travis.yml +4 -0
  8. data/Gemfile +3 -0
  9. data/Gemfile.lock +44 -0
  10. data/LICENSE +8 -0
  11. data/README.md +216 -0
  12. data/doc/CONTRIBUTING.md +12 -0
  13. data/doc/TODO.md +28 -0
  14. data/doc/configuration_sample.rb +87 -0
  15. data/lib/ruby_yacht/dsl/app.rb +59 -0
  16. data/lib/ruby_yacht/dsl/configuration.rb +55 -0
  17. data/lib/ruby_yacht/dsl/database.rb +57 -0
  18. data/lib/ruby_yacht/dsl/dns_server.rb +38 -0
  19. data/lib/ruby_yacht/dsl/dsl.rb +252 -0
  20. data/lib/ruby_yacht/dsl/project.rb +140 -0
  21. data/lib/ruby_yacht/dsl.rb +6 -0
  22. data/lib/ruby_yacht/images/app/Dockerfile.erb +32 -0
  23. data/lib/ruby_yacht/images/app/checkout.rb +7 -0
  24. data/lib/ruby_yacht/images/app/startup.rb +17 -0
  25. data/lib/ruby_yacht/images/app/update_database_config.rb +45 -0
  26. data/lib/ruby_yacht/images/app-dependencies/Dockerfile.erb +23 -0
  27. data/lib/ruby_yacht/images/app-dependencies/install_gems.rb +12 -0
  28. data/lib/ruby_yacht/images/database/Dockerfile.erb +26 -0
  29. data/lib/ruby_yacht/images/database/load_seeds.rb +42 -0
  30. data/lib/ruby_yacht/images/database/setup.rb +19 -0
  31. data/lib/ruby_yacht/images/database/setup_database.sql.erb +12 -0
  32. data/lib/ruby_yacht/images/deploy/Dockerfile.erb +2 -0
  33. data/lib/ruby_yacht/images/web/Dockerfile.erb +25 -0
  34. data/lib/ruby_yacht/images/web/add_app.rb +12 -0
  35. data/lib/ruby_yacht/images/web/add_project.rb +14 -0
  36. data/lib/ruby_yacht/images/web/app_config.erb +11 -0
  37. data/lib/ruby_yacht/images/web/index.html.erb +10 -0
  38. data/lib/ruby_yacht/images/web/index_config.erb +12 -0
  39. data/lib/ruby_yacht/images/web/setup.rb +22 -0
  40. data/lib/ruby_yacht/runner/build.rb +21 -0
  41. data/lib/ruby_yacht/runner/build_images.rb +82 -0
  42. data/lib/ruby_yacht/runner/checkout.rb +68 -0
  43. data/lib/ruby_yacht/runner/command.rb +161 -0
  44. data/lib/ruby_yacht/runner/help.rb +55 -0
  45. data/lib/ruby_yacht/runner/implode.rb +33 -0
  46. data/lib/ruby_yacht/runner/run_containers.rb +105 -0
  47. data/lib/ruby_yacht/runner/runner.rb +42 -0
  48. data/lib/ruby_yacht/runner/services.rb +79 -0
  49. data/lib/ruby_yacht/runner/shell.rb +66 -0
  50. data/lib/ruby_yacht/runner/update_hosts.rb +72 -0
  51. data/lib/ruby_yacht/runner.rb +18 -0
  52. data/lib/ruby_yacht.rb +6 -0
  53. data/ruby_yacht.gemspec +18 -0
  54. data/spec/docker/Dockerfile +5 -0
  55. data/spec/docker/build.bash +10 -0
  56. data/spec/dsl/app_spec.rb +47 -0
  57. data/spec/dsl/configuration_spec.rb +64 -0
  58. data/spec/dsl/database_spec.rb +75 -0
  59. data/spec/dsl/dns_server_spec.rb +25 -0
  60. data/spec/dsl/dsl_spec.rb +298 -0
  61. data/spec/dsl/project_spec.rb +266 -0
  62. data/spec/fixtures/app-dependencies-dockerfile +25 -0
  63. data/spec/fixtures/database-dockerfile +31 -0
  64. data/spec/fixtures/deploy-dockerfile +2 -0
  65. data/spec/fixtures/mars-dockerfile +32 -0
  66. data/spec/fixtures/multi-project-web-dockerfile +35 -0
  67. data/spec/fixtures/web-dockerfile +27 -0
  68. data/spec/runner/build_images_spec.rb +164 -0
  69. data/spec/runner/build_spec.rb +86 -0
  70. data/spec/runner/checkout_spec.rb +128 -0
  71. data/spec/runner/command_spec.rb +94 -0
  72. data/spec/runner/help_spec.rb +73 -0
  73. data/spec/runner/implode_spec.rb +62 -0
  74. data/spec/runner/run_containers_spec.rb +141 -0
  75. data/spec/runner/runner_spec.rb +117 -0
  76. data/spec/runner/services_spec.rb +135 -0
  77. data/spec/runner/shell_spec.rb +123 -0
  78. data/spec/runner/update_hosts_spec.rb +163 -0
  79. data/spec/spec_helper.rb +10 -0
  80. data/spec/support/docker_stubbing.rb +93 -0
  81. data/spec/support/test_project.rb +56 -0
  82. metadata +193 -0
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2
4
+ script: bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ruby_yacht (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ codeclimate-test-reporter (0.5.0)
10
+ simplecov (>= 0.7.1, < 1.0.0)
11
+ diff-lcs (1.2.5)
12
+ docile (1.1.5)
13
+ json (1.8.3)
14
+ rspec (3.4.0)
15
+ rspec-core (~> 3.4.0)
16
+ rspec-expectations (~> 3.4.0)
17
+ rspec-mocks (~> 3.4.0)
18
+ rspec-core (3.4.4)
19
+ rspec-support (~> 3.4.0)
20
+ rspec-expectations (3.4.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.4.0)
23
+ rspec-mocks (3.4.1)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.4.0)
26
+ rspec-support (3.4.1)
27
+ simplecov (0.11.2)
28
+ docile (~> 1.1.0)
29
+ json (~> 1.8)
30
+ simplecov-html (~> 0.10.0)
31
+ simplecov-html (0.10.0)
32
+ timecop (0.8.1)
33
+
34
+ PLATFORMS
35
+ ruby
36
+
37
+ DEPENDENCIES
38
+ codeclimate-test-reporter
39
+ rspec
40
+ ruby_yacht!
41
+ timecop
42
+
43
+ BUNDLED WITH
44
+ 1.11.2
data/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ Copyright (c) 2016 John Brownlee
2
+
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,216 @@
1
+ This gem provides a DSL for creating docker containers for running a family of
2
+ Rails apps.
3
+
4
+ [![Code Climate](https://codeclimate.com/github/brownleej/ruby-yacht/badges/gpa.svg)](https://codeclimate.com/github/brownleej/ruby-yacht)
5
+ [![Test Coverage](https://codeclimate.com/github/brownleej/ruby-yacht/badges/coverage.svg)](https://codeclimate.com/github/brownleej/ruby-yacht/coverage)
6
+
7
+ # Prerequisites
8
+
9
+ 1. Install [Docker](https://www.docker.com/products/docker-toolbox)
10
+ 2. Install ruby and the ruby_yacht gem.
11
+
12
+ # Usage
13
+
14
+ Create a file called `run.rb`, which will be the main file for your docker
15
+ scripts. This file can be called anything, but we will use that name here so we
16
+ have a consistent reference.
17
+
18
+ Enter this in the file:
19
+
20
+ require 'ruby_yacht'
21
+
22
+ RubyYacht.configure do
23
+ end
24
+
25
+ RubyYacht::Runner.run
26
+
27
+ Your `run.rb` file will have two parts: A configuration block and the `Runner`
28
+ command. The configuration block defines your projects and your apps. You can
29
+ read [configuration_sample.rb](https://github.com/brownleej/ruby-yacht/blob/master/doc/configuration_sample.rb)
30
+ for more information on how the configuration DSL.
31
+
32
+ The runner command invokes a RubyYacht script based on the command information.
33
+
34
+ # RubyYacht Scripts
35
+
36
+ RubyYacht provides several scripts to build and manage your application
37
+ environment. You can invoke these scripts by calling `ruby run.rb [command]`.
38
+
39
+ The examples below describe the results for the projects in the configuration
40
+ sample file, which contains the following projects:
41
+
42
+ * Project: apollo
43
+ * apps: mars, saturn
44
+ * database: localhost
45
+ * domain: apollo.docker.local
46
+
47
+ * Project: jupiter
48
+ * apps: venus, saturn
49
+ * database: db.test.com
50
+ * domain: jupiter.docker.local
51
+
52
+ ### help
53
+
54
+ This command lists available commands, and provides information on the
55
+ syntax and options for each command.
56
+
57
+ ### build
58
+
59
+ This command builds images for your projects, runs the containers, and updates
60
+ your hosts file to add entries that point your app's domains toward the local
61
+ docker address. This is a combination of `build_images`, `run_containers`, and
62
+ `update_hosts`, so you can run those commands individually, and in different
63
+ combinations, if you prefer.
64
+
65
+ ### build_images
66
+
67
+ This command builds all of the images for your project. For the example above,
68
+ it will build the following images:
69
+
70
+ <table>
71
+ <tr>
72
+ <td>apollo-app-dependencies</td>
73
+ <td>
74
+ An image with mars and saturn checked out, and all of their dependencies
75
+ installed
76
+ </td>
77
+ </tr>
78
+ <tr>
79
+ <td>apollo-database</td>
80
+ <td>
81
+ An image with mysql installed and a database set up with the schema and
82
+ seeds from mars and saturn
83
+ </td>
84
+ </tr>
85
+ <tr>
86
+ <td>apollo-mars</td>
87
+ <td>
88
+ An image with the mars app installed, and the dependencies for mars
89
+ installed, set up to point to the apollo-database database.
90
+ </td>
91
+ </tr>
92
+ <tr>
93
+ <td>apollo-saturn</td>
94
+ <td>
95
+ An image with the saturn app installed, and the dependencies for saturn
96
+ installed, set up to point to the apollo-database database.
97
+ </td>
98
+ </tr>
99
+ <tr>
100
+ <td>jupiter-app-dependencies</td>
101
+ <td>
102
+ An image with venus and saturn checked out, and all of their dependencies
103
+ installed
104
+ </td>
105
+ </tr>
106
+ <tr>
107
+ <td>jupiter-venus</td>
108
+ <td>
109
+ An image with the venus app installed, and the dependencies for mars
110
+ installed, set up to point to the db.test.com database.
111
+ </td>
112
+ </tr>
113
+ <tr>
114
+ <td>jupiter-saturn</td>
115
+ <td>
116
+ An image with the saturn app installed, and the dependencies for saturn
117
+ installed, set up to point to the db.test.com database.
118
+ </td>
119
+ </tr>
120
+ <tr>
121
+ <td>apollo-web</td>
122
+ <td>
123
+ An image with nginx installed, and set up to proxy the app containers for
124
+ apollo-mars, apollo-saturn, jupiter-venus, and jupiter-saturn. Each app
125
+ will get a subdomain of the project's main domain, with the subdomain named
126
+ after the app.
127
+ </td>
128
+ </tr>
129
+ </table>
130
+
131
+ ### run_containers
132
+
133
+ This command runs all of the containers for the images described above. Each
134
+ container will have the same name as its image. Each container will be on a
135
+ docker network called `apollo`, and will have network aliases corresponding to
136
+ the container names. For instance, the `apollo-web` container will be able to
137
+ access the `apollo-mars` container under the hostname `apollo-mars`. The apps
138
+ will also be able to talk to each other using these network aliases.
139
+
140
+ It will not run a container for the `app-dependencies` images. Those images are
141
+ intended to use as a baseline for the app and database images, to reduce their
142
+ build times.
143
+
144
+ All of the containers will be run as daemons.
145
+
146
+ ### update_hosts
147
+
148
+ This command updates your hosts file to add entries for your containers. This
149
+ is intended to help with development environments, where you won't have a real
150
+ domain that resolves to your local machine.
151
+
152
+ For the examples above, it will add entries for these domains:
153
+
154
+ * apollo.docker.local
155
+ * mars.apollo.docker.local
156
+ * saturn.apollo.docker.local
157
+ * jupiter.docker.local
158
+ * venus.jupiter.docker.local
159
+ * saturn.jupiter.docker.local
160
+
161
+ This will allow you to access your local version of the apps in the web browser
162
+ on your local machine without any additional DNS setup.
163
+
164
+ Before overwriting the hosts file, it will save a copy of the existing hosts
165
+ file to `/etc/hosts.{timestamp}.backup`.
166
+
167
+ This will prompt you for your password, because it needs root privileges to
168
+ update the hosts file. It will only use that privilege to run the commands:
169
+
170
+ sudo cp /etc/hosts /ect/hosts.{timestamp}.backup
171
+ sudo cp tmp/hosts /etc/hosts
172
+
173
+ The `tmp/hosts` file is populated prior to the privilege escalation with the
174
+ updated hosts file contents.
175
+
176
+ ### implode
177
+
178
+ This will remove all of the containers and images for your projects, and also
179
+ remove any dangling docker images. After this is done, you can run the `build`
180
+ command to rebuild your environment from scratch.
181
+
182
+ This will not ruby the `ruby` and `nginx` images. Those are downloaded as
183
+ part of the build process, and are provided by third parties as official docker
184
+ images for those ruby and nginx.
185
+
186
+ ### services
187
+
188
+ This allows you to start, stop, or restart containers. If you run it with the
189
+ `start` sub-command, it will also start docker-machine, if necessary. The most
190
+ common use case for this is to run `ruby run.rb services start` after you reboot
191
+ your machine, to get your docker environment up and running again.
192
+
193
+ ### shell
194
+
195
+ This opens a shell in an app container. By default, this opens a bash shell, but
196
+ any additional commands you pass it will be forwarded to the container and run.
197
+
198
+ For instance, you can run `ruby run.rb shell mars` to open a bash shell in the
199
+ mars app container, or `ruby run.rb shell mars rails c` to open a
200
+ rails console, or `ruby run.rb shell mars tail -f log/development.log` to start
201
+ reading all the content printed to the development log file.
202
+
203
+ ### checkout
204
+
205
+ This checks out a new branch inside an app container, and restarts the app
206
+ container. It will also immediately run any database migrations from the new
207
+ branch.
208
+
209
+ If you run it for a branch that you already have checked out, it will pull down
210
+ the latest changes from the repository.
211
+
212
+ # Additional Information
213
+
214
+ If you're interested in contributing to the project, you can find more
215
+ information in [CONTRIBUTING.md](https://github.com/brownleej/ruby-yacht/blob/master/doc/CONTRIBUTING.md).
216
+ You can also reach out to me on Twitter [@brownleej](https://twitter.com/brownleej)
@@ -0,0 +1,12 @@
1
+ I'm eager to accept contributions to ruby_yacht to fix bugs and empower it to
2
+ handle more people's workflows. I'm preparing a plugin engine as part of the 1.0
3
+ release, and that will likely shape decisions about what gets accepted into the
4
+ core and what should remain in individual's projects. You can start by opening
5
+ a pull request with a fix, or an issue with a suggestion for a new feature.
6
+
7
+ All pull requests must contain test coverage. The nature of this project
8
+ requires caution when developing and running tests. The tests contain extensive
9
+ stubs to prevent them from interacting with a real docker environment, and you
10
+ should use the same techniques in your own tests. I would also recommend that
11
+ you run the tests within their own docker container. You can find tools for
12
+ building such a container in [spec/docker](../spec/docker)
data/doc/TODO.md ADDED
@@ -0,0 +1,28 @@
1
+ # General
2
+
3
+ * Testing behavior of the scripts that run on the image.
4
+ * Do more testing with remote databases and non-development environments
5
+ * Consider whether deploy containers are worth including
6
+ * Consider whether using the same web server for multiple projects is the best
7
+ approach
8
+
9
+ # Transitioning to Gem
10
+
11
+ * Publish gem
12
+
13
+ # More Command Line Options
14
+
15
+ * Getting status of containers
16
+ * Starting / stopping individual containers
17
+ * Clearing backups of the hosts file
18
+
19
+ # More customization
20
+
21
+ * Add customizations for installation
22
+ * Add customization for post-checkout hooks
23
+ * HTTPS access for apps
24
+ * Distinguishing whether we should use local or remote connections for other
25
+ services
26
+ * Different types of app servers, i.e. non-rails apps
27
+ * Using one of the apps for the bare domain
28
+ * Defining custom commands
@@ -0,0 +1,87 @@
1
+ require 'ruby_yacht'
2
+
3
+ RubyYacht.configure do
4
+ project :apollo do
5
+ # All the images and containers for this project will be prefixed with
6
+ # 'apollo-'
7
+ system_prefix :apollo
8
+
9
+ # The web server will place the apps under 'apollo.docker.local'
10
+ #
11
+ # apollo.docker.local will point to a landing page with links to the apps,
12
+ # and individual apps will be available at mars.apollo.docker.local and
13
+ # saturn.apollo.docker.local
14
+ domain "apollo.docker.local"
15
+
16
+ # The repositories for the apps in this project will all be available at the
17
+ # domain github.com.
18
+ #
19
+ # All repositories will be checked out over SSH, so you need to make sure
20
+ # that the containers have SSH keys that can access the repository server.
21
+ #
22
+ # When the images are built, it will automatically copy the SSH key from
23
+ # ~/.ssh/id_rsa into the containers.
24
+ repository "github.com"
25
+
26
+ # The configuration for the database the app uses.
27
+ database do
28
+ # A database host of localhost tells ruby-yacht to build a database
29
+ # container for the apps' local database.
30
+ host "localhost"
31
+
32
+ # The apps will share a database called apollo
33
+ name "apollo"
34
+
35
+ # The credentials for accessing the database.
36
+ username "apollo"
37
+ password "test"
38
+ end
39
+
40
+ app :mars do
41
+ # This app's repository is at github.com/brownleej/mars
42
+ repository_name 'brownleej/mars'
43
+ end
44
+
45
+ app :saturn do
46
+ # This app's repository is at github.com/brownleej/saturn
47
+ repository_name 'brownleej/saturn'
48
+ end
49
+
50
+ # The secret key that we use for session information in the Rails apps.
51
+ secret_key_base 'abc'
52
+ end
53
+
54
+ # This is a second project that runs a different set of apps, with different
55
+ # domains and a separate database.
56
+ project :jupiter do
57
+ system_prefix :jupiter
58
+ domain "jupiter.docker.local"
59
+ repository "github.com"
60
+
61
+ database do
62
+ # Because this host has a real domain, we will not build a database
63
+ # container. The database at this host must be set up in advance with
64
+ # the database and the credentials in this file.
65
+ #
66
+ # When the apps start, they will automatically run database migrations
67
+ # against this database.
68
+ host "db.test.com"
69
+ name "jupiter"
70
+ username "jupiter"
71
+ password "test"
72
+ end
73
+
74
+ app :venus do
75
+ repository_name 'brownleej/venus'
76
+ end
77
+
78
+ app :saturn do
79
+ repository_name 'brownleej/saturn'
80
+ end
81
+
82
+ secret_key_base 'abc'
83
+ end
84
+ end
85
+
86
+ RubyYacht::Runner.run
87
+
@@ -0,0 +1,59 @@
1
+ module RubyYacht
2
+ # This class models an app that's part of the local system.
3
+ #
4
+ # See RubyYacht::App::DSL for information on configuring the app.
5
+ class App
6
+ # The name of the app
7
+ attr_accessor :name
8
+
9
+ # The name of the repository where the app's code is stored, relative
10
+ # To the project's repository domain.
11
+ attr_accessor :repository_name
12
+
13
+ # The port that the app listens on.
14
+ attr_accessor :port
15
+
16
+ # This method gets the name of the image / container that this app will run
17
+ # in.
18
+ #
19
+ # ### Parameters
20
+ #
21
+ # * *project: RubyYacht::Project* The project the app is running in.
22
+ def container_name(project)
23
+ return "#{project.system_prefix}-#{self.name}"
24
+ end
25
+
26
+ # This class provide's the DSL for configuring an app.
27
+ #
28
+ # Inside of the project configuration, you can call `app [name]` to add an
29
+ # app, and then pass it a block to configure the app, which will allow you
30
+ # to call these DSL methods.
31
+ class DSL
32
+ include RubyYacht::DSL::Base
33
+ extend RubyYacht::DSL::Base::ClassMethods
34
+
35
+ # This initializer starts the DSL for the app.
36
+ #
37
+ # ### Parameters
38
+ #
39
+ # * *name: String* The name of the app.
40
+ def initialize(name)
41
+ @name = name.to_sym
42
+ end
43
+
44
+ add_attribute :name
45
+
46
+ ##
47
+ # :method: repository_name
48
+ # You can call `repository_name 'foo/bar'` to set the app's `repository_name`.
49
+ add_attribute :repository_name
50
+
51
+ ##
52
+ # :method: port
53
+ # You can call `port 3000` to set the app's `port`. It defaults to 8080.
54
+ add_attribute :port, 8080
55
+
56
+ creates_object App
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,55 @@
1
+ module RubyYacht
2
+ # This class stores the configuration for the system.
3
+ #
4
+ # For more information on the configuration DSL, see RubyYacht::Configuration::DSL.
5
+ class Configuration
6
+ # This initializer creates an empty configuration.
7
+ def initialize
8
+ self.clear
9
+ end
10
+
11
+ # This method erases all the configuration.
12
+ def clear
13
+ @projects = []
14
+ end
15
+
16
+ # The projects that are part of this system.
17
+ # Each entry is a RubyYacht::Project
18
+ attr_accessor :projects
19
+
20
+ # This method provides a DSL for top-level configuration.
21
+ class DSL
22
+ include RubyYacht::DSL::Base
23
+ extend RubyYacht::DSL::Base::ClassMethods
24
+
25
+ ##
26
+ # :method: project
27
+ #
28
+ # This method adds a project to the configuration.
29
+ #
30
+ # This takes the project name as its first argument. It also takes a block
31
+ # which you can use to configure the project, using
32
+ # RubyYacht::Project::DSL.
33
+ add_object_list :project, 'RubyYacht::Project::DSL'
34
+
35
+ creates_object Configuration
36
+ end
37
+ end
38
+
39
+ # This method adds configuration for the system.
40
+ #
41
+ # If you pass a block to this method, it will be evaluated using the methods
42
+ # in RubyYacht::Configuration::DSL.
43
+ #
44
+ # Any projects you define in that block will be added to the current list
45
+ # of projects.
46
+ def self.configure(&block)
47
+ new_configuration = Configuration::DSL.new.run(block).create_object
48
+ self.configuration.projects += new_configuration.projects
49
+ end
50
+
51
+ # This method gets the current configuration for the system.
52
+ def self.configuration
53
+ @configuration ||= Configuration.new
54
+ end
55
+ end
@@ -0,0 +1,57 @@
1
+ module RubyYacht
2
+ # This class stores the configuration for a project's database server.
3
+ #
4
+ # You can configure a database with RubyYacht::Database::DSL
5
+ class Database
6
+ # The host that the database server is accessed on.
7
+ attr_accessor :host
8
+
9
+ # The name of the database
10
+ attr_accessor :name
11
+
12
+ # The username we use to connect to the database
13
+ attr_accessor :username
14
+
15
+ # The password we use to connect to the database
16
+ attr_accessor :password
17
+
18
+ # Whether the database is running on the same machine as the app servers.
19
+ def local?
20
+ host == 'localhost'
21
+ end
22
+
23
+ # This class provides a DSL for configuring a database.
24
+ #
25
+ # You can access this DSL by calling `database` within `RubyYacht::Project::DSL`.
26
+ # It will create a RubyYacht::Database
27
+ class DSL
28
+ include RubyYacht::DSL::Base
29
+ extend RubyYacht::DSL::Base::ClassMethods
30
+
31
+ ##
32
+ # :method: host
33
+ # You can call `host 'db.test.com'` to set the database's host.
34
+ add_attribute :host
35
+
36
+ #
37
+ # :method: name
38
+ # You can call `name` 'my_database'` to tell the apps to use the database
39
+ # named `my_database`.
40
+ add_attribute :name
41
+
42
+ ##
43
+ # :method: username
44
+ # You can call `username 'db-user'` to tell the apps to connect to the
45
+ # database under the name `db-user`.
46
+ add_attribute :username
47
+
48
+ ##
49
+ # :method: password
50
+ # You can call `password 'testpass'` to tell the apps to connect to the
51
+ # password `testpass`.
52
+ add_attribute :password
53
+
54
+ creates_object Database
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,38 @@
1
+ module RubyYacht
2
+ # This class provides configuration for DNS servers for your apps.
3
+ #
4
+ # This is optional. If you don't provide any DNS server configuration, we will
5
+ # use docker's default DNS configuration.
6
+ #
7
+ # You can configure this with RubyYacht::DnsServer::DSL
8
+ class DnsServer
9
+ # The servers that we use for DNS. Each entry is a String.
10
+ attr_accessor :servers
11
+
12
+ # The domains that we use for default DNS lookup. Each entry is a String.
13
+ attr_accessor :search_domains
14
+
15
+ # This class provides a DSL for configuring DNS server options.
16
+ #
17
+ # You can access this by calling `dns_server` within RubyYacht::Project::DSL.
18
+ # It will create a RubyYacht::DnsServer.
19
+ class DSL
20
+ include RubyYacht::DSL::Base
21
+ extend RubyYacht::DSL::Base::ClassMethods
22
+
23
+ ##
24
+ # :method: server
25
+ # You can call `server '1.2.3.4'` to add `1.2.3.4` to the project's list of
26
+ # DNS servers.
27
+ add_list :server
28
+
29
+ ##
30
+ # :method: search_domain
31
+ # You can call `search_domain 'apps.test.com'` to add `apps.test.com` to
32
+ # the list of domains that we automatically search for in the DNS.
33
+ add_list :search_domain
34
+
35
+ creates_object DnsServer
36
+ end
37
+ end
38
+ end