orchestration 0.3.17 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/LICENSE +7 -0
  4. data/MANIFEST +76 -0
  5. data/Makefile +3 -3
  6. data/README.md +162 -137
  7. data/Rakefile +2 -2
  8. data/config/locales/en.yml +3 -1
  9. data/lib/orchestration/docker_compose/app_service.rb +84 -13
  10. data/lib/orchestration/docker_compose/compose_configuration.rb +69 -0
  11. data/lib/orchestration/docker_compose/database_service.rb +15 -13
  12. data/lib/orchestration/docker_compose/install_generator.rb +3 -2
  13. data/lib/orchestration/docker_compose/mongo_service.rb +5 -5
  14. data/lib/orchestration/docker_compose/rabbitmq_service.rb +2 -3
  15. data/lib/orchestration/docker_compose.rb +1 -0
  16. data/lib/orchestration/environment.rb +19 -6
  17. data/lib/orchestration/errors.rb +1 -1
  18. data/lib/orchestration/file_helpers.rb +27 -4
  19. data/lib/orchestration/install_generator.rb +85 -20
  20. data/lib/orchestration/services/app/configuration.rb +9 -5
  21. data/lib/orchestration/services/app/healthcheck.rb +1 -22
  22. data/lib/orchestration/services/database/adapters/mysql2.rb +13 -2
  23. data/lib/orchestration/services/database/adapters/postgresql.rb +0 -1
  24. data/lib/orchestration/services/database/configuration.rb +68 -75
  25. data/lib/orchestration/services/database/healthcheck.rb +10 -1
  26. data/lib/orchestration/services/listener/configuration.rb +1 -1
  27. data/lib/orchestration/services/listener/healthcheck.rb +2 -2
  28. data/lib/orchestration/services/{configuration_base.rb → mixins/configuration_base.rb} +15 -13
  29. data/lib/orchestration/services/{healthcheck_base.rb → mixins/healthcheck_base.rb} +3 -2
  30. data/lib/orchestration/services/mixins/http_healthcheck.rb +38 -0
  31. data/lib/orchestration/services/mongo/configuration.rb +37 -63
  32. data/lib/orchestration/services/mongo/healthcheck.rb +3 -32
  33. data/lib/orchestration/services/rabbitmq/configuration.rb +11 -22
  34. data/lib/orchestration/services/rabbitmq/healthcheck.rb +2 -2
  35. data/lib/orchestration/services.rb +3 -2
  36. data/lib/orchestration/templates/Dockerfile.erb +8 -4
  37. data/lib/orchestration/templates/database.yml.erb +32 -0
  38. data/lib/orchestration/templates/deploy.mk.erb +2 -2
  39. data/lib/orchestration/templates/entrypoint.sh.erb +13 -4
  40. data/lib/orchestration/templates/env.erb +10 -2
  41. data/lib/orchestration/templates/healthcheck.rb.erb +56 -0
  42. data/lib/orchestration/templates/makefile_macros.mk.erb +108 -0
  43. data/lib/orchestration/templates/mongoid.yml.erb +18 -0
  44. data/lib/orchestration/templates/orchestration.mk.erb +242 -120
  45. data/lib/orchestration/templates/puma.rb.erb +19 -0
  46. data/lib/orchestration/templates/rabbitmq.yml.erb +12 -0
  47. data/lib/orchestration/templates/unicorn.rb.erb +5 -5
  48. data/lib/orchestration/terminal.rb +13 -15
  49. data/lib/orchestration/version.rb +1 -1
  50. data/lib/orchestration.rb +20 -2
  51. data/lib/tasks/orchestration.rake +3 -1
  52. data/orchestration.gemspec +3 -5
  53. metadata +23 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a45477bd5cd5d3aaf948247ed294c24509c59b55c3244d2bdb34d7adb50bf7d8
4
- data.tar.gz: cc1be97aec363dabbe212d4bc5160651ec78b2f46ed3fe5461950c8392522adc
3
+ metadata.gz: 2186d476519af97c595c422ec2e8e85244de7a21ba38ac57a9dac6078508147e
4
+ data.tar.gz: d62c7ae58f1c20eb34e94cf0120d1ccd2dafbfa5820a4f9cdde0a36e51a4942d
5
5
  SHA512:
6
- metadata.gz: e151308a54ac3048249820773ee5c2657fd1e6f1cfa2d8429ccfae1782bb77bc6413dcdd55a010004fc6b869eae9e057f89b52101eb9af5e9c236d34c08ccb49
7
- data.tar.gz: 472e8a63dbd0277c2bc6a5e6cfc5c24ab69b27a132109f08f097288c8958c6ad0f7c1565c60db5b6075f4ee7dc1eaa49b1c7d46908995cb7b7e4c55cccb4c2ca
6
+ metadata.gz: 3c04057ada42ee20e573629778b56c4b35fc160325e1314e5055e30931b4e21c6948b1cdde40b6d0aff56e5076e708fd07af8ef55322d812f9b555f6ee7dbb03
7
+ data.tar.gz: 60a0c33ee614f8fb71a5feaae10e5788bd9f5cd8b45fbeb2a39b7cdcad0aa870bb5d61464a06c5478229a7ebf1f96a1a226ed0ff4ef0dc69280e0a617731310c
data/.gitignore CHANGED
@@ -21,9 +21,13 @@ spec/dummy/.gitignore
21
21
  spec/dummy/Makefile
22
22
  spec/dummy/orchestration/*
23
23
  spec/dummy/config/unicorn.rb
24
+ spec/dummy/config/*.bak
24
25
 
25
26
  orchestration-*.gem
26
27
 
27
28
  .byebug_history
28
29
 
29
30
  TODO
31
+
32
+ docker/.build/
33
+ docker/.context.tar
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2018-2019 Robert Farrell
2
+
3
+ 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:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ 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/MANIFEST ADDED
@@ -0,0 +1,76 @@
1
+ .gitignore
2
+ .rspec
3
+ .rubocop.yml
4
+ .strong_versions.yml
5
+ .travis.yml
6
+ Gemfile
7
+ LICENSE
8
+ MANIFEST
9
+ Makefile
10
+ README.md
11
+ Rakefile
12
+ bin/console
13
+ bin/rspec
14
+ bin/rubocop
15
+ bin/setup
16
+ bin/strong_versions
17
+ config/locales/en.yml
18
+ lib/Rakefile
19
+ lib/orchestration.rb
20
+ lib/orchestration/docker_compose.rb
21
+ lib/orchestration/docker_compose/app_service.rb
22
+ lib/orchestration/docker_compose/compose_configuration.rb
23
+ lib/orchestration/docker_compose/configuration.rb
24
+ lib/orchestration/docker_compose/database_service.rb
25
+ lib/orchestration/docker_compose/install_generator.rb
26
+ lib/orchestration/docker_compose/mongo_service.rb
27
+ lib/orchestration/docker_compose/rabbitmq_service.rb
28
+ lib/orchestration/environment.rb
29
+ lib/orchestration/errors.rb
30
+ lib/orchestration/file_helpers.rb
31
+ lib/orchestration/install_generator.rb
32
+ lib/orchestration/railtie.rb
33
+ lib/orchestration/service_check.rb
34
+ lib/orchestration/services.rb
35
+ lib/orchestration/services/app.rb
36
+ lib/orchestration/services/app/configuration.rb
37
+ lib/orchestration/services/app/healthcheck.rb
38
+ lib/orchestration/services/database.rb
39
+ lib/orchestration/services/database/adapters.rb
40
+ lib/orchestration/services/database/adapters/mysql2.rb
41
+ lib/orchestration/services/database/adapters/postgresql.rb
42
+ lib/orchestration/services/database/adapters/sqlite3.rb
43
+ lib/orchestration/services/database/configuration.rb
44
+ lib/orchestration/services/database/healthcheck.rb
45
+ lib/orchestration/services/listener.rb
46
+ lib/orchestration/services/listener/configuration.rb
47
+ lib/orchestration/services/listener/healthcheck.rb
48
+ lib/orchestration/services/mixins/configuration_base.rb
49
+ lib/orchestration/services/mixins/healthcheck_base.rb
50
+ lib/orchestration/services/mixins/http_healthcheck.rb
51
+ lib/orchestration/services/mongo.rb
52
+ lib/orchestration/services/mongo/configuration.rb
53
+ lib/orchestration/services/mongo/healthcheck.rb
54
+ lib/orchestration/services/rabbitmq.rb
55
+ lib/orchestration/services/rabbitmq/configuration.rb
56
+ lib/orchestration/services/rabbitmq/healthcheck.rb
57
+ lib/orchestration/settings.rb
58
+ lib/orchestration/templates/Dockerfile.erb
59
+ lib/orchestration/templates/application.mk.erb
60
+ lib/orchestration/templates/database.yml.erb
61
+ lib/orchestration/templates/deploy.mk.erb
62
+ lib/orchestration/templates/docker-compose.override.yml.erb
63
+ lib/orchestration/templates/entrypoint.sh.erb
64
+ lib/orchestration/templates/env.erb
65
+ lib/orchestration/templates/healthcheck.rb.erb
66
+ lib/orchestration/templates/makefile_macros.mk.erb
67
+ lib/orchestration/templates/mongoid.yml.erb
68
+ lib/orchestration/templates/orchestration.mk.erb
69
+ lib/orchestration/templates/puma.rb.erb
70
+ lib/orchestration/templates/rabbitmq.yml.erb
71
+ lib/orchestration/templates/unicorn.rb.erb
72
+ lib/orchestration/templates/yaml.bash.erb
73
+ lib/orchestration/terminal.rb
74
+ lib/orchestration/version.rb
75
+ lib/tasks/orchestration.rake
76
+ orchestration.gemspec
data/Makefile CHANGED
@@ -1,9 +1,9 @@
1
1
  .PHONY: test
2
-
3
2
  test:
4
3
  ./bin/rspec
5
4
  ./bin/rubocop
6
5
  ./bin/strong_versions
7
6
 
8
- readme:
9
- markdown-toc -i README.md
7
+ .PHONY: manifest
8
+ manifest:
9
+ git ls-files | GREP_OPTIONS='' grep -v '^spec' > MANIFEST
data/README.md CHANGED
@@ -1,6 +1,17 @@
1
1
  # Orchestration
2
2
 
3
- _Orchestration_ is a toolkit for testing, building, and deploying _Ruby_ (including _Rails_) applications in _Docker_.
3
+ ## Overview
4
+
5
+ _Orchestration_ aims to provide a convenient and consistent process for working with _Rails_ and _Docker_ without obscuring underlying components.
6
+
7
+ At its core _Orchestration_ is just a `Makefile` and a set of `docker-compose.yml` files with sensible, general-purpose default settings. Users are encouraged to tailor the generated build-out to suit their application; once the build-out has been generated it belongs to the application.
8
+
9
+ A typical _Rails_ application can be tested, built, pushed to _Docker Hub_, and deployed to _Docker Swarm_ with the following commands:
10
+
11
+ ```bash
12
+ make test build push
13
+ make deploy manager=user@swarm.example.com env_file=/var/configs/myapp.env
14
+ ```
4
15
 
5
16
  ## Getting Started
6
17
 
@@ -11,7 +22,7 @@ _Orchestration_ is a toolkit for testing, building, and deploying _Ruby_ (includ
11
22
  Add _Orchestration_ to your Gemfile:
12
23
 
13
24
  ```ruby
14
- gem 'orchestration', '~> 0.3.17'
25
+ gem 'orchestration', '~> 0.4.0'
15
26
  ```
16
27
 
17
28
  Install:
@@ -22,13 +33,33 @@ bundle install
22
33
 
23
34
  ### Setup
24
35
 
25
- Generate configuration files:
36
+ Generate configuration files and select your deployment server:
37
+
38
+ #### Generate build-out
26
39
 
27
40
  ```bash
28
- bin/rake orchestration:install
41
+ rake orchestration:install server=unicorn # (or 'puma' [default], etc.)
29
42
  ```
30
43
 
31
- Commit changes:
44
+ To rebuild all build-out at any time, pass `force=yes` to the above install command.
45
+
46
+ You will be prompted to enter values for your _Docker_ organisation and repository name. For example, the _organisation_ and _repository_ for https://hub.docker.com/r/redislabs/redis/ are `redislabs` and `redis` respectively. If you are unsure of these values, they can be modified later by editing `.orchestration.yml` in the root of your project directory.
47
+
48
+ #### Configuration files
49
+
50
+ _Orchestration_ generates the following files where appropriate. Backups are created if a file is replaced.
51
+
52
+ * `config/database.yml`
53
+ * `config/mongoid.yml`
54
+ * `config/rabbitmq.yml` (see [RabbitMQ Configuration](#markdown-header-rabbitmq-configuration) for more details)
55
+ * `config/unicorn.rb`
56
+ * `config/puma.rb`
57
+
58
+ You may need to merge your previous configurations with the generated files. You will only need to do this once.
59
+
60
+ Test and development dependency containers bind to a randomly-generated [at install time] local port to avoid collisions. You may compare e.g. `orchestration/docker-compose.test.yml` with the `test` section of the generated `config/database.yml` to see how things fit together.
61
+
62
+ When setup is complete, add the generated build-out to _Git_:
32
63
 
33
64
  ```bash
34
65
  git add .
@@ -37,201 +68,195 @@ git commit -m "Add Orchestration gem"
37
68
 
38
69
  ## Usage
39
70
 
40
- Start your dependencies:
71
+ All `make` commands provided by _Orchestration_ (with the exception of `test` and `deploy`) recognise the `env` parameter. This is equivalent to setting the `RAILS_ENV` environment variable.
41
72
 
42
- ```bash
43
- make start
73
+ e.g.:
44
74
  ```
45
-
46
- Log in to your _Docker_ registry, then build and push your image:
47
- ```bash
48
- docker login
49
- make build push
75
+ # Stop all test containers
76
+ make stop env=test
50
77
  ```
51
78
 
52
- Make a compact, portable, production-ready tarball:
79
+ The default value for `env` is `development`.
80
+
81
+ As with any `Makefile` targets can be chained together, e.g.:
53
82
  ```
54
- make bundle
83
+ # Run tests, build, and push image
84
+ make test build push
55
85
  ```
56
86
 
57
- Copy tarball to your server and unpack:
87
+ ### Containers
88
+
89
+ All auto-detected services will be added to the relevant `docker-compose.<environment>.yml` files at installation time.
90
+
91
+ #### Start services
92
+
58
93
  ```bash
59
- tar xf deploy.tar
60
- cd <your-app-name>/
94
+ make start
61
95
  ```
62
96
 
63
- Add required config to `.env` file:
97
+ #### Stop services
98
+
99
+ ```bash
100
+ make stop
64
101
  ```
65
- # .env
66
- SECRET_KEY_BASE=<your-secure-token>
67
- LISTEN_PORT=8080
68
- VIRTUAL_HOST=yourdomain.com
102
+
103
+ #### Interface directly with `docker-compose`
104
+
105
+ ```bash
106
+ $(make compose env=test) logs -f database
69
107
  ```
70
108
 
71
- Load three instances of your container, load-balanced by _Nginx_, with dependecies:
109
+ ### Images
110
+
111
+ Image tags are generated using the following convention:
112
+
72
113
  ```
73
- make start instances=3
114
+ # See .orchestration.yml for `organization` and `repository` values.
115
+ <organization>/<repository>:<git-commit-hash>
116
+
117
+ # e.g.
118
+ acme/anvil:abcd1234
74
119
  ```
75
120
 
76
- Or deploy to _Docker Swarm_:
121
+ #### Build an application image
122
+
123
+ Note that `git archive` is used to generate the build context. Any uncommitted changes will _not_ be included in the image.
77
124
  ```
78
- make deploy
125
+ make build
79
126
  ```
80
127
 
81
- ## Table of Contents
82
-
83
- <!-- toc -->
128
+ See [build environment](#markdown-header-build-environment) for more details.
84
129
 
85
- - [Configuration Files](#configuration-files)
86
- * [Makefile](#makefile)
87
- * [.orchestration.yml](#orchestrationyml)
88
- * [.env](#env)
89
- * [orchestration/Dockerfile](#orchestrationdockerfile)
90
- * [orchestration/entrypoint.sh](#orchestrationentrypointsh)
91
- * [orchestration/docker-compose.yml](#orchestrationdocker-composeyml)
92
- * [config/unicorn.rb](#configunicornrb)
93
- - [Building](#building)
94
- - [Build Environment](#build-environment)
95
- - [Commands](#commands)
96
- - [Dependencies](#dependencies)
130
+ #### Push latest image
97
131
 
98
- <!-- tocstop -->
132
+ You must be logged in to a _Docker_ registry. Use the `docker login` command (see [Docker documentation](https://docs.docker.com/engine/reference/commandline/login/) for further reference).
99
133
 
100
- ## Configuration Files
134
+ ```
135
+ make push
136
+ ```
101
137
 
102
- _Orchestration_ autogenerates boilerplate configuration based on your application's requirements and configuration.
138
+ ### Development
103
139
 
104
- When supported dependencies are detected they will be created as services in your _Docker Compose_ configurations ready for use in testing, development, and production.
140
+ An [`.env`](https://docs.docker.com/compose/env-file/) is created automatically in your project root. This file is _not_ stored in version control. Set all application environment variables in this file.
105
141
 
106
- The following files are created on setup:
142
+ #### Launching a development server
107
143
 
108
- ### Makefile
144
+ To load all variables from `.env` and launch a development server, run the following command:
109
145
 
110
- Contains an `include` for the main _Orchestration_ `Makefile`. If this file already exists then the `include` will be added to the top of the file.
146
+ ```bash
147
+ make serve
148
+ ```
111
149
 
112
- ### .orchestration.yml
150
+ The application environment will be output on launch for convenience.
113
151
 
114
- _Orchestration_-specific configuration such as your _Docker_ registry and username.
152
+ To pass extra commands to the _Rails_ server:
153
+ ```bash
154
+ # Custom server, custom port
155
+ make serve server='webrick -p 3001'
115
156
 
116
- ### .env
157
+ # Default server, custom port, custom bind address
158
+ make serve server='-p 3001 -b 192.168.0.1'
159
+ ```
117
160
 
118
- Specify any environment variables (e.g. `SECRET_KEY_BASE`) your application will need to run in production mode.
161
+ ### Testing
119
162
 
120
- The following two variables _must_ be defined:
163
+ A default `test` target is provided in your application's main `Makefile`. You are encouraged to modify this target to suit your application's requirements.
121
164
 
122
- ```bash
123
- VIRTUAL_HOST=localhost
124
- LISTEN_PORT=3000
165
+ To launch all dependency containers, run database migrations, and run tests:
166
+ ```
167
+ make test
125
168
  ```
126
169
 
127
- When running in production mode your application will be load-balanced by _Nginx_ proxy and available at http://localhost:3000/
170
+ Note that _Orchestration_ will wait for all services to become fully available (i.e. running and providing valid responses) before attempting to run tests. This is specifically intended to facilitate testing in continuous integration environments.
128
171
 
129
- Take a look at `orchestration/docker-compose.production.yml` to see what variables will be exposed to various containers.
172
+ ### Deployment to Docker Swarm
130
173
 
131
- ### orchestration/Dockerfile
174
+ To deploy your application to _Docker Swarm_:
175
+ ```
176
+ make deploy manager=user@manager.swarm.example.com
177
+ ```
132
178
 
133
- The basic requirements of a typical _Rails_ application. It is optimised for build speed and will automatically build assets (with our without `Webpacker`).
179
+ To use a custom `.env` file:
180
+ ```
181
+ make deploy env_file=/path/to/.env manager=user@manager.swarm.example.com
182
+ ```
134
183
 
135
- ### orchestration/entrypoint.sh
184
+ Note that the following two variables _must_ be set in the relevant `.env` file (will look in the current working directory if no path provided):
136
185
 
137
- Entrypoint script to handle user switching, permissions, stale pidfiles, etc.
186
+ ```
187
+ # Published port for your application service:
188
+ CONTAINER_PORT=3000
138
189
 
139
- ### orchestration/docker-compose.yml
190
+ # Number of replicas of your application service:
191
+ REPLICAS=5
192
+ ```
140
193
 
141
- Along with the base `docker-compose.yml` a separate configuration is created for each environment. An override file is also generated.
194
+ It is also recommended to set `SECRET_KEY_BASE` etc. in this file.
142
195
 
143
- See related documentation:
196
+ ## Build Environment
144
197
 
145
- https://docs.docker.com/compose/extends/
198
+ The following environment variables will be passed as `ARG` variables when building images:
146
199
 
147
- * `orchestration/docker-compose.yml`
148
- * `orchestration/docker-compose.test.yml`
149
- * `orchestration/docker-compose.development.yml`
150
- * `orchestration/docker-compose.production.yml`
151
- * `orchestration/docker-compose.override.yml`
200
+ ```
201
+ BUNDLE_BITBUCKET__ORG
202
+ BUNDLE_GITHUB__COM
203
+ ```
152
204
 
153
- You can modify these files to suit your requirements.
205
+ Set these variables in your shell if your `Gemfile` references privately-hosted gems on either _Bitbucket_ or _GitHub_.
154
206
 
155
- The famous [`jwilder/nginx-proxy`](https://github.com/jwilder/nginx-proxy) is used to load-balance replicas of your application when running in production.
207
+ See related documentation:
156
208
 
157
- ### config/unicorn.rb
209
+ * https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/
210
+ * https://confluence.atlassian.com/bitbucket/app-passwords-828781300.html
158
211
 
159
- If not already present, a [Unicorn](https://bogomips.org/unicorn/) configuration will be created. This is the default server when running in production.
212
+ ## Healthchecks
160
213
 
161
- ## Building
214
+ [Healthchecks](https://docs.docker.com/engine/reference/builder/#healthcheck) are automatically configured for your application. A healthcheck utility is provided in `orchestration/healthcheck.rb`. The following environment variables can be configured (in the `app` service of `orchestration/docker-compose.production.yml`):
162
215
 
163
- _Orchestration_ provides tools for building your application as a _Docker_ image.
216
+ | Variable | Meaning | Default Value |
217
+ |-|-|-|
218
+ | `WEB_HOST` | Host to reach application (relevant to application container) | `localhost` |
219
+ | `WEB_PORT` | Port to reach application (relevant to application container) | `8080` |
220
+ | `WEB_HEALTHCHECK_PATH` | Path of expected successful response | `/` |
221
+ | `WEB_HEALTHCHECK_READ_TIMEOUT` | Number of seconds to wait for data before failing healthcheck | `10` |
222
+ | `WEB_HEALTHCHECK_OPEN_TIMEOUT` | Number of seconds to wait for connection before failing healthcheck | `10` |
223
+ | `WEB_HEALTHCHECK_SUCCESS_CODES` | Comma-separated list of HTTP status codes that will be deemed a success | `200,202,204` |
164
224
 
165
- ```bash
166
- make build
225
+ If your application does not have a suitable always-available route to use as a healthcheck, the following one-liner may be useful:
226
+
227
+ ```ruby
228
+ # config/routes.rb
229
+ get '/healthcheck', to: proc { [200, { 'Content-Type' => 'text/html' }, ['']] }
167
230
  ```
168
231
 
169
- Running `make build` does the following:
232
+ In this case, `WEB_HEALTHCHECK_PATH` must be set to `/healthcheck`.
170
233
 
171
- * Takes a snapshot of your application from current _Git_ `HEAD`. Only committed files are included.
172
- * Copies your `Gemfile` and installs your bundle (optimised for _Docker_ image caching).
173
- * Tags your image with your configured username/organisation, repository, and the current commit hash (abbreviated) of `HEAD`, e.g. `myorg/myapp:abc123`
234
+ ## Entrypoint
174
235
 
175
- Your image can then be pushed to your configured registry (use `docker login` before running):
236
+ An [entrypoint](https://docs.docker.com/engine/reference/builder/#entrypoint) script for your application is provided which does the following:
176
237
 
177
- ```
178
- make push
179
- ```
238
+ * Runs the `CMD` process as the same system user that launched the container (rather than the default `root` user);
239
+ * Creates various required temporary directories and removes stale `pid` files;
240
+ * Adds a route `host.docker.internal` to the host machine running the container (mimicking the same route provided by _Docker_ itself on _Windows_ and _OS
241
+ X_).
180
242
 
181
- ## Build Environment
243
+ ## RabbitMQ Configuration
182
244
 
183
- The following environment variables will be passed as `ARG` variables when building your image:
245
+ The [Bunny](https://github.com/ruby-amqp/bunny) _RabbitMQ_ gem does not recognise `config/rabbitmq.yml`. If your application uses _RabbitMQ_ then you must manually update your code to reference this file, e.g.:
184
246
 
185
- ```
186
- BUNDLE_BITBUCKET__ORG
187
- BUNDLE_GITHUB__COM
247
+ ```ruby
248
+ connection = Bunny.new(config_for(:rabbit_mq)['url'])
249
+ connection.start
188
250
  ```
189
251
 
190
- See related documentation:
252
+ The environment variable `RABBITMQ_URL` can be used to configure _Bunny_ in production (similar to `DATABASE_URL` and `MONGO_URL`).
191
253
 
192
- * https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/
193
- * https://confluence.atlassian.com/bitbucket/app-passwords-828781300.html
254
+ This is a convention of the _Orchestration_ gem intended to make _RabbitMQ_ configuration consistent with other services.
194
255
 
195
- ## Commands
256
+ ## License
196
257
 
197
- _Orchestration_ provides a number of `make` commands to help you work with your application in _Docker_.
258
+ [MIT License](LICENSE)
198
259
 
199
- All commands respect `RAILS_ENV` or `RACK_ENV`. Alternatively you can pass `env` to any command:
200
- ```bash
201
- make config env=production
202
- ```
203
-
204
- The following commands are implemented:
205
-
206
- | Command | Description |
207
- |---|---|
208
- | `start` | Start all containers and wait for their services to become available. In production mode, pass `instances=N` to start `N` replicas of your app. |
209
- | `stop` | Stop all containers. |
210
- | `logs` | Tail logs for all containers. |
211
- | `config` | Output the full configuration for the current environment with all variables substituted. |
212
- | `compose` | Output full `docker-compose` command. Run arbitrary commands for your environment, e.g. `$(make compose env=test) ps --services` |
213
- | `test-setup` | Launch test dependency containers, wait for them to become ready, run database migrations. Call before running tests in a CI environment. |
214
- | `wait` | Wait for all dependencies to be ready (i.e. verify that database is up and accepting connections, etc.). |
215
- | `wait-database` | Wait for database container (supported: _PostgreSQL_ and _MySQL_) to become available. |
216
- | `wait-mongo` | Wait for _Mongo_ container to become available.
217
- | `wait-rabbitmq` | Wait for _RabbitMQ_ container to become available. |
218
- | `wait-nginx_proxy` | Wait for _Nginx_ container to become available (`production` only). |
219
- | `wait-app` | Wait for main application container to become available (`production` only). |
220
- | `build` | Build your application as a _Docker_ image. |
221
- | `push` | Push the current version of your application image to a _Docker_ registry. |
222
- | `bundle` | Create `deploy.tar` which contains pre-cooked production configurations and `Makefile` ready to deploy your application on any machine with _Docker_ and _Docker Compose_ installed.
223
-
224
- ## Dependencies
225
-
226
- Dependencies are automatically detected. The following services are currently supported:
227
-
228
- | Service | Configuration File |
229
- |---|---|
230
- | _PostrgeSQL_ | `config/database.yml` |
231
- | _MySQL_ | `config/database.yml` |
232
- | _RabbitMQ_ | `config/rabbitmq.yml` |
233
- | _Mongo_ | `config/mongoid.yml` |
234
-
235
- Running `bin/rake orchestration:install` will automatically add services to your _Compose_ configurations that reflect your configuration files.
236
-
237
- For _RabbitMQ_, `config/rabbitmq.yml` should contain `host` and `port` fields for each environment.
260
+ ## Contributing
261
+
262
+ Feel free to make a pull request. Use `make test` to ensure that all tests, _Rubocop_ checks, and dependency validations pass correctly.
data/Rakefile CHANGED
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
4
+ require 'rspec/core/rake_task' unless ENV.key?('ORCHESTRATION_TOOLKIT_ONLY')
5
5
 
6
- RSpec::Core::RakeTask.new(:spec)
6
+ RSpec::Core::RakeTask.new(:spec) if defined?(RSpec)
7
7
 
8
8
  task default: :spec
@@ -12,6 +12,7 @@ en:
12
12
  waiting: "Waiting for database: %{config}"
13
13
  ready: "Database is ready."
14
14
  unknown_environment: "Environment not defined in database configuration: %{environment}"
15
+ unknown_adapter: "Unable to determine adapter from database.yml: %{adapter}"
15
16
 
16
17
  mongo:
17
18
  waiting: "Waiting for Mongo: %{config}"
@@ -33,7 +34,7 @@ en:
33
34
  settings:
34
35
  docker:
35
36
  organization:
36
- description: "Registry organization/username"
37
+ description: "Docker registry organization/username"
37
38
  prompt: "organization"
38
39
 
39
40
  repository:
@@ -43,6 +44,7 @@ en:
43
44
  rake:
44
45
  app:
45
46
  wait: "Wait for app to become available"
47
+ unknown_web_server: "Unrecognised web server '%{server}'. Expected: %{expected}"
46
48
 
47
49
  database:
48
50
  wait: "Wait for database to become available"