orchestration 0.5.0 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Makefile +0 -9
- data/README.md +24 -12
- data/config/locales/en.yml +4 -23
- data/lib/orchestration.rb +2 -1
- data/lib/orchestration/docker_compose/app_service.rb +2 -2
- data/lib/orchestration/docker_compose/install_generator.rb +0 -16
- data/lib/orchestration/docker_healthcheck.rb +65 -0
- data/lib/orchestration/environment.rb +2 -2
- data/lib/orchestration/file_helpers.rb +1 -2
- data/lib/orchestration/install_generator.rb +25 -22
- data/lib/orchestration/service_check.rb +3 -9
- data/lib/orchestration/services/database/configuration.rb +2 -2
- data/lib/orchestration/services/database/healthcheck.rb +13 -1
- data/lib/orchestration/services/mixins/healthcheck_base.rb +4 -0
- data/lib/orchestration/templates/Dockerfile.erb +2 -2
- data/lib/orchestration/templates/application.mk.erb +10 -0
- data/lib/orchestration/templates/database.yml.erb +2 -2
- data/lib/orchestration/templates/deploy.mk.erb +4 -6
- data/lib/orchestration/templates/entrypoint.sh.erb +1 -1
- data/lib/orchestration/templates/env.erb +4 -7
- data/lib/orchestration/templates/makefile_macros.mk.erb +13 -11
- data/lib/orchestration/templates/orchestration.mk.erb +67 -26
- data/lib/orchestration/version.rb +1 -1
- data/lib/tasks/orchestration.rake +14 -47
- data/orchestration.gemspec +4 -1
- metadata +3 -9
- data/MANIFEST +0 -78
- data/bin/rspec +0 -29
- data/bin/rubocop +0 -29
- data/bin/strong_versions +0 -29
- data/lib/orchestration/templates/docker-compose.override.yml.erb +0 -1
- data/lib/orchestration/templates/healthcheck.rb.erb +0 -56
- data/lib/orchestration/templates/yaml.bash.erb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e312ede29eb601b4e9413df1b711881997f81629b6f208c0ea7e62102d4a6b44
|
4
|
+
data.tar.gz: 4483fd3532b1bf27bb9a6b76e38c996a02f046164ed23ce85d5df5720e933ff3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6539ea72eabd6683691749179cb4bd08c9f9e3f334ced7348236058a2926a6e25f6a09176c47efb1f40a0b22f57f96c9d1fb9ba4274c25036a4cd03e3d3f6ead
|
7
|
+
data.tar.gz: caed0598c1dc565457e0437943a0c031b78c3bef1ab99d5ae313368af6a4e0a84e7451bc46560e454457a5fa5c8e83c5ff6019fc114c3fd22e0a0dfac00d9c61
|
data/Makefile
CHANGED
@@ -3,12 +3,3 @@ test:
|
|
3
3
|
bundle exec rspec
|
4
4
|
bundle exec rubocop
|
5
5
|
bundle exec strong_versions
|
6
|
-
|
7
|
-
.PHONY: manifest
|
8
|
-
manifest:
|
9
|
-
git ls-files | GREP_OPTIONS='' grep -v '^spec' > MANIFEST
|
10
|
-
git diff-index --quiet HEAD || (git add MANIFEST && git commit -m "Update manifest" || :)
|
11
|
-
|
12
|
-
.PHONY: release
|
13
|
-
release: manifest
|
14
|
-
gem build orchestration.gemspec
|
data/README.md
CHANGED
@@ -1,13 +1,5 @@
|
|
1
1
|
# Orchestration
|
2
2
|
|
3
|
-
```
|
4
|
-
I've got two tickets to the game
|
5
|
-
It'd be great if I could take you to it this Sunday
|
6
|
-
--Nickelback
|
7
|
-
```
|
8
|
-
|
9
|
-
## Overview
|
10
|
-
|
11
3
|
_Orchestration_ aims to provide a convenient and consistent process for working with _Rails_ and _Docker_ without obscuring underlying components.
|
12
4
|
|
13
5
|
At its core _Orchestration_ is simply 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.
|
@@ -35,7 +27,7 @@ The below screenshot demonstrates _Orchestration_ being installed in a brand new
|
|
35
27
|
Add _Orchestration_ to your Gemfile:
|
36
28
|
|
37
29
|
```ruby
|
38
|
-
gem 'orchestration', '~> 0.5.
|
30
|
+
gem 'orchestration', '~> 0.5.5'
|
39
31
|
```
|
40
32
|
|
41
33
|
Install:
|
@@ -56,6 +48,11 @@ rake orchestration:install server=unicorn # (or 'puma' [default], etc.)
|
|
56
48
|
|
57
49
|
To rebuild all build-out at any time, pass `force=yes` to the above install command.
|
58
50
|
|
51
|
+
To rebuild just `orchestration/Makefile` (useful after upgrading the _Orchestration_ gem):
|
52
|
+
```bash
|
53
|
+
rake orchestration:install:makefile
|
54
|
+
```
|
55
|
+
|
59
56
|
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/rubyorchestration/sampleapp are `rubyorchestration` and `sampleapp` respectively. If you are unsure of these values, they can be modified later by editing `.orchestration.yml` in the root of your project directory.
|
60
57
|
|
61
58
|
#### Configuration files
|
@@ -138,7 +135,20 @@ Note that `git archive` is used to generate the build context. Any uncommitted c
|
|
138
135
|
make build
|
139
136
|
```
|
140
137
|
|
141
|
-
|
138
|
+
The `include` option can also be passed to provide a manifest file. Any files listed in this file will also be built into the _Docker_ image. Files **must** be located within the project directory.
|
139
|
+
|
140
|
+
```bash
|
141
|
+
make build include=manifest.txt
|
142
|
+
```
|
143
|
+
|
144
|
+
```bash
|
145
|
+
# manifest.txt
|
146
|
+
doc/api/swagger.json
|
147
|
+
doc/api/soap.xml
|
148
|
+
doc/api/doc.html
|
149
|
+
```
|
150
|
+
|
151
|
+
See also [build environment](#build-environment) if you use gems hosted on private _GitHub_/_Bitbucket_ repositories.
|
142
152
|
|
143
153
|
#### Push latest image
|
144
154
|
|
@@ -217,6 +227,8 @@ To connect via _SSH_ to a remote swarm and deploy, pass the `manager` parameter:
|
|
217
227
|
make deploy manager=user@manager.swarm.example.com
|
218
228
|
```
|
219
229
|
|
230
|
+
The file `orchestration/docker-compose.production.yml` is created automatically. If your `RAILS_ENV` is set to something other than `production` then another file will need to be created (e.g. `orchestration/docker-compose.staging.yml`). In most cases this file can be a _symlink_ to the original `production` configuration and environment variables can be used to customise the content.
|
231
|
+
|
220
232
|
#### Roll back a deployment
|
221
233
|
|
222
234
|
Roll back the `app` service of your stack:
|
@@ -260,7 +272,7 @@ Note that the following two variables _must_ be set in the relevant `.env` file
|
|
260
272
|
|
261
273
|
```
|
262
274
|
# Published port for your application service:
|
263
|
-
|
275
|
+
PUBLISH_PORT=3000
|
264
276
|
|
265
277
|
# Number of replicas of your application service:
|
266
278
|
REPLICAS=5
|
@@ -315,7 +327,7 @@ See related documentation:
|
|
315
327
|
| `WEB_HEALTHCHECK_PATH` | Path expected to return a successful response | `/` |
|
316
328
|
| `WEB_HEALTHCHECK_READ_TIMEOUT` | Number of seconds to wait for data before failing healthcheck | `10` |
|
317
329
|
| `WEB_HEALTHCHECK_OPEN_TIMEOUT` | Number of seconds to wait for connection before failing healthcheck | `10` |
|
318
|
-
| `WEB_HEALTHCHECK_SUCCESS_CODES` | Comma-separated list of HTTP status codes that will be deemed a success | `200,202,204` |
|
330
|
+
| `WEB_HEALTHCHECK_SUCCESS_CODES` | Comma-separated list of HTTP status codes that will be deemed a success | `200,201,202,204` |
|
319
331
|
|
320
332
|
If your application does not have a suitable always-available route to use as a healthcheck, the following one-liner may be useful:
|
321
333
|
|
data/config/locales/en.yml
CHANGED
@@ -2,6 +2,7 @@ en:
|
|
2
2
|
orchestration:
|
3
3
|
attempt_limit: "Unable to reconnect after %{limit} attempts. Aborting."
|
4
4
|
default: "default"
|
5
|
+
auto_update: "Orchestration Makefile was automatically updated to the latest version."
|
5
6
|
|
6
7
|
app:
|
7
8
|
waiting: "Waiting for app: %{config}"
|
@@ -19,10 +20,6 @@ en:
|
|
19
20
|
ready: "Mongo is ready."
|
20
21
|
bad_config: "Unable to parse Mongo config: %{path}. Expected section for one of: %{expected}"
|
21
22
|
|
22
|
-
haproxy:
|
23
|
-
waiting: "Waiting for HAProxy: %{config}"
|
24
|
-
ready: "HAProxy is ready."
|
25
|
-
|
26
23
|
rabbitmq:
|
27
24
|
waiting: "Waiting for RabbitMQ: %{config}"
|
28
25
|
ready: "RabbitMQ is ready."
|
@@ -42,24 +39,8 @@ en:
|
|
42
39
|
prompt: "project name"
|
43
40
|
|
44
41
|
rake:
|
45
|
-
|
46
|
-
|
47
|
-
unknown_web_server: "Unrecognised web server '%{server}'. Expected: %{expected}"
|
48
|
-
|
49
|
-
database:
|
50
|
-
wait: "Wait for database to become available"
|
51
|
-
|
52
|
-
listener:
|
53
|
-
wait: "Wait for a locally-bound service to accept connections (pass `service=NAME`)"
|
54
|
-
|
55
|
-
mongo:
|
56
|
-
wait: "Wait for Mongo to become available"
|
57
|
-
|
58
|
-
haproxy:
|
59
|
-
wait: "Wait for HAProxy to become available"
|
60
|
-
|
61
|
-
rabbitmq:
|
62
|
-
wait: "Wait for RabbitMQ to become available"
|
63
|
-
|
42
|
+
config: "Parse and output Orchestration config (internal use)"
|
43
|
+
healthcheck: "Execute healthcheck; used for HEALTHCHECK command in Docker image"
|
64
44
|
install: "Install Orchestration tools"
|
65
45
|
install_makefile: "(Re)create orchestration/Makefile"
|
46
|
+
wait: "Wait for development/test dependencies to be available"
|
data/lib/orchestration.rb
CHANGED
@@ -11,7 +11,7 @@ require 'paint'
|
|
11
11
|
begin
|
12
12
|
require 'rails'
|
13
13
|
rescue LoadError
|
14
|
-
warn('[orchestration]
|
14
|
+
warn('[orchestration] Running in non-Rails mode.')
|
15
15
|
end
|
16
16
|
|
17
17
|
I18n.load_path += Dir[File.join(File.expand_path('..', __dir__),
|
@@ -22,6 +22,7 @@ require 'orchestration/file_helpers'
|
|
22
22
|
require 'orchestration/docker_compose'
|
23
23
|
require 'orchestration/environment'
|
24
24
|
require 'orchestration/errors'
|
25
|
+
require 'orchestration/docker_healthcheck'
|
25
26
|
require 'orchestration/install_generator'
|
26
27
|
require 'orchestration/railtie' if defined?(Rails)
|
27
28
|
require 'orchestration/service_check'
|
@@ -27,7 +27,7 @@ module Orchestration
|
|
27
27
|
|
28
28
|
def healthcheck
|
29
29
|
{
|
30
|
-
'test' => ['
|
30
|
+
'test' => ['bundle', 'exec', 'rake', 'orchestration:healthcheck'],
|
31
31
|
# Defaults according to
|
32
32
|
# https://docs.docker.com/engine/reference/builder/#healthcheck
|
33
33
|
# Except start_period which cannot be set to 0s
|
@@ -113,7 +113,7 @@ module Orchestration
|
|
113
113
|
end
|
114
114
|
|
115
115
|
def ports
|
116
|
-
['${
|
116
|
+
['${PUBLISH_PORT:?PUBLISH_PORT must be provided}:8080']
|
117
117
|
end
|
118
118
|
end
|
119
119
|
end
|
@@ -10,10 +10,6 @@ module Orchestration
|
|
10
10
|
@terminal = terminal
|
11
11
|
end
|
12
12
|
|
13
|
-
def docker_compose_yml
|
14
|
-
create_compose_file
|
15
|
-
end
|
16
|
-
|
17
13
|
def docker_compose_test_yml
|
18
14
|
create_compose_file(:test)
|
19
15
|
end
|
@@ -22,22 +18,10 @@ module Orchestration
|
|
22
18
|
create_compose_file(:development)
|
23
19
|
end
|
24
20
|
|
25
|
-
def docker_compose_local_yml
|
26
|
-
create_compose_file(:local)
|
27
|
-
end
|
28
|
-
|
29
21
|
def docker_compose_production_yml
|
30
22
|
create_compose_file(:production)
|
31
23
|
end
|
32
24
|
|
33
|
-
def docker_compose_override_yml
|
34
|
-
simple_copy(
|
35
|
-
'docker-compose.override.yml',
|
36
|
-
@env.docker_compose_path(:override),
|
37
|
-
overwrite: false
|
38
|
-
)
|
39
|
-
end
|
40
|
-
|
41
25
|
def enabled_services(environment)
|
42
26
|
service_names(environment).select { |name| service_enabled?(name) }
|
43
27
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
module Orchestration
|
5
|
+
class DockerHealthcheck
|
6
|
+
def self.execute
|
7
|
+
new.execute
|
8
|
+
end
|
9
|
+
|
10
|
+
def execute
|
11
|
+
return_code = 1
|
12
|
+
|
13
|
+
# rubocop:disable Lint/RescueException
|
14
|
+
begin
|
15
|
+
response = run
|
16
|
+
return_code = 0 if success?(response.code)
|
17
|
+
puts message(response.code)
|
18
|
+
rescue Exception => e
|
19
|
+
puts "[#{__FILE__}] ERROR: #{e.inspect}"
|
20
|
+
ensure
|
21
|
+
exit return_code
|
22
|
+
end
|
23
|
+
# rubocop:enable Lint/RescueException
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def run
|
29
|
+
client = Net::HTTP.new(
|
30
|
+
ENV.fetch('WEB_HOST', 'localhost'),
|
31
|
+
ENV.fetch('WEB_PORT', '8080').to_i
|
32
|
+
)
|
33
|
+
|
34
|
+
client.read_timeout = ENV.fetch('WEB_HEALTHCHECK_READ_TIMEOUT', '10').to_i
|
35
|
+
client.open_timeout = ENV.fetch('WEB_HEALTHCHECK_OPEN_TIMEOUT', '10').to_i
|
36
|
+
|
37
|
+
client.start do |request|
|
38
|
+
request.get(ENV.fetch('WEB_HEALTHCHECK_PATH') { '/' })
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def success_codes
|
43
|
+
ENV.fetch('WEB_HEALTHCHECK_SUCCESS_CODES', '200,201,202,204').split(',')
|
44
|
+
end
|
45
|
+
|
46
|
+
def success?(code)
|
47
|
+
success_codes.include?(code.to_s)
|
48
|
+
end
|
49
|
+
|
50
|
+
def message(code)
|
51
|
+
if success?(code)
|
52
|
+
outcome = 'SUCCESS ✓ '
|
53
|
+
in_or_not = 'IN'
|
54
|
+
else
|
55
|
+
outcome = 'FAILURE ✘ '
|
56
|
+
in_or_not = 'NOT IN'
|
57
|
+
end
|
58
|
+
|
59
|
+
accepted = success_codes.join(', ')
|
60
|
+
message = "#{in_or_not} [#{accepted}] : #{outcome} [#{__FILE__}]"
|
61
|
+
|
62
|
+
"# HTTP_STATUS(#{code}) #{message}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -53,7 +53,7 @@ module Orchestration
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def docker_compose_path(env = nil)
|
56
|
-
|
56
|
+
env ||= 'development'
|
57
57
|
|
58
58
|
orchestration_root.join("docker-compose.#{env}.yml")
|
59
59
|
end
|
@@ -82,7 +82,7 @@ module Orchestration
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def app_port
|
85
|
-
ENV.fetch('
|
85
|
+
ENV.fetch('PUBLISH_PORT', ENV.fetch('WEB_PORT', '3000')).to_i
|
86
86
|
end
|
87
87
|
|
88
88
|
def app_name
|
@@ -66,9 +66,8 @@ module Orchestration
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def skip?(present, content, previous_content, options)
|
69
|
-
overwrite = options.fetch(:overwrite, true)
|
70
69
|
return false unless present
|
71
|
-
return true unless overwrite || force?
|
70
|
+
return true unless options.fetch(:overwrite, true) || force?
|
72
71
|
|
73
72
|
previous_content == content
|
74
73
|
end
|
@@ -27,10 +27,18 @@ module Orchestration
|
|
27
27
|
@terminal.write(:skip, relpath)
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
30
|
+
def verify_makefile(skip = true)
|
31
|
+
# Only run when called explicitly [from Rake tasks].
|
32
|
+
# (I know this is hacky).
|
33
|
+
return if skip
|
34
|
+
|
31
35
|
content = template('orchestration.mk', makefile_environment)
|
32
36
|
path = @env.orchestration_root.join('Makefile')
|
33
|
-
path.exist?
|
37
|
+
return if path.exist? && content == File.read(path)
|
38
|
+
|
39
|
+
write_file(path, content)
|
40
|
+
@terminal.write(:update, 'Makefile')
|
41
|
+
@terminal.write(:status, t(:auto_update))
|
34
42
|
end
|
35
43
|
|
36
44
|
def application_makefile
|
@@ -39,6 +47,12 @@ module Orchestration
|
|
39
47
|
inject_if_missing(path, 'include orchestration/Makefile')
|
40
48
|
end
|
41
49
|
|
50
|
+
def orchestration_makefile
|
51
|
+
content = template('orchestration.mk', makefile_environment)
|
52
|
+
path = @env.orchestration_root.join('Makefile')
|
53
|
+
path.exist? ? update_file(path, content) : create_file(path, content)
|
54
|
+
end
|
55
|
+
|
42
56
|
def dockerfile
|
43
57
|
create_file(
|
44
58
|
orchestration_dir.join('Dockerfile'),
|
@@ -54,23 +68,10 @@ module Orchestration
|
|
54
68
|
FileUtils.chmod('a+x', path)
|
55
69
|
end
|
56
70
|
|
57
|
-
def gitignore
|
58
|
-
path = @env.root.join('.gitignore')
|
59
|
-
globs = %w[.build/ .deploy/ Gemfile Gemfile.lock docker-compose.local.yml]
|
60
|
-
lines = %w[orchestration/.sidecar .env deploy.tar] + globs.map do |line|
|
61
|
-
"#{@env.orchestration_dir_name}/#{line}"
|
62
|
-
end
|
63
|
-
|
64
|
-
ensure_lines_in_file(path, lines)
|
65
|
-
end
|
66
|
-
|
67
71
|
def docker_compose
|
68
|
-
@docker_compose.docker_compose_yml
|
69
72
|
@docker_compose.docker_compose_test_yml
|
70
73
|
@docker_compose.docker_compose_development_yml
|
71
|
-
@docker_compose.docker_compose_local_yml
|
72
74
|
@docker_compose.docker_compose_production_yml
|
73
|
-
@docker_compose.docker_compose_override_yml
|
74
75
|
end
|
75
76
|
|
76
77
|
def puma
|
@@ -112,16 +113,18 @@ module Orchestration
|
|
112
113
|
service_config('rabbitmq.yml', Services::RabbitMQ::Configuration)
|
113
114
|
end
|
114
115
|
|
115
|
-
def
|
116
|
-
simple_copy('
|
116
|
+
def env
|
117
|
+
simple_copy('env', @env.root.join('.env'), overwrite: false)
|
117
118
|
end
|
118
119
|
|
119
|
-
def
|
120
|
-
|
121
|
-
|
120
|
+
def gitignore
|
121
|
+
path = @env.root.join('.gitignore')
|
122
|
+
globs = %w[.build/ .deploy/ Gemfile Gemfile.lock docker-compose.local.yml]
|
123
|
+
lines = %w[orchestration/.sidecar .env deploy.tar] + globs.map do |line|
|
124
|
+
"#{@env.orchestration_dir_name}/#{line}"
|
125
|
+
end
|
122
126
|
|
123
|
-
|
124
|
-
simple_copy('env', @env.root.join('.env'), overwrite: false)
|
127
|
+
ensure_lines_in_file(path, lines)
|
125
128
|
end
|
126
129
|
|
127
130
|
def deploy_mk
|
@@ -16,11 +16,13 @@ module Orchestration
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def run
|
19
|
-
return
|
19
|
+
return unless @service.configuration.configured?
|
20
20
|
|
21
|
+
@service.modify_environment
|
21
22
|
echo_start
|
22
23
|
success = attempt_connection
|
23
24
|
echo_ready if success
|
25
|
+
@service.unmodify_environment
|
24
26
|
success
|
25
27
|
end
|
26
28
|
|
@@ -39,14 +41,6 @@ module Orchestration
|
|
39
41
|
false
|
40
42
|
end
|
41
43
|
|
42
|
-
def echo_missing
|
43
|
-
@terminal.write(
|
44
|
-
@service_name.to_sym,
|
45
|
-
"#{@service.configuration.error} (skipping)",
|
46
|
-
:error
|
47
|
-
)
|
48
|
-
end
|
49
|
-
|
50
44
|
def echo_start
|
51
45
|
@terminal.write(@service_name.to_sym, '', :status)
|
52
46
|
end
|
@@ -18,14 +18,14 @@ module Orchestration
|
|
18
18
|
"[#{adapter.name}] #{host}:#{port}"
|
19
19
|
end
|
20
20
|
|
21
|
-
def settings
|
21
|
+
def settings(healthcheck: false)
|
22
22
|
{
|
23
23
|
adapter: adapter.name,
|
24
24
|
host: host,
|
25
25
|
port: port,
|
26
26
|
username: username,
|
27
27
|
password: password,
|
28
|
-
database: database
|
28
|
+
database: healthcheck ? adapter.credentials['database'] : database
|
29
29
|
}.transform_keys(&:to_s)
|
30
30
|
end
|
31
31
|
|
@@ -19,6 +19,18 @@ module Orchestration
|
|
19
19
|
[ActiveRecord::ConnectionNotEstablished].concat(adapter_errors)
|
20
20
|
end
|
21
21
|
|
22
|
+
def modify_environment
|
23
|
+
@database_url = ENV.delete('DATABASE_URL')
|
24
|
+
@development_database_url = ENV.delete('DEVELOPMENT_DATABASE_URL')
|
25
|
+
@test_database_url = ENV.delete('TEST_DATABASE_URL')
|
26
|
+
end
|
27
|
+
|
28
|
+
def unmodify_environment
|
29
|
+
ENV['DATABASE_URL'] = @database_url
|
30
|
+
ENV['DEVELOPMENT_DATABASE_URL'] = @development_database_url
|
31
|
+
ENV['TEST_DATABASE_URL'] = @test_database_url
|
32
|
+
end
|
33
|
+
|
22
34
|
private
|
23
35
|
|
24
36
|
def adapter_errors
|
@@ -26,7 +38,7 @@ module Orchestration
|
|
26
38
|
end
|
27
39
|
|
28
40
|
def settings
|
29
|
-
@configuration.settings
|
41
|
+
@configuration.settings(healthcheck: true)
|
30
42
|
end
|
31
43
|
end
|
32
44
|
end
|
@@ -20,10 +20,10 @@ COPY .build/Gemfile .build/Gemfile.lock ./
|
|
20
20
|
RUN bundle install --without development test --deployment
|
21
21
|
<% if defined?(Webpacker) %>
|
22
22
|
COPY .build/package.json .build/yarn.lock ./
|
23
|
-
RUN . /root/.bashrc
|
23
|
+
RUN . /root/.bashrc ; yarn install
|
24
24
|
<% end %>
|
25
25
|
ADD .build/context.tar .
|
26
|
-
<% if defined?(Webpacker) %>RUN . /root/.bashrc
|
26
|
+
<% if defined?(Webpacker) %>RUN . /root/.bashrc ; NODE_ENV=production RAILS_ENV=production yarn install && NODE_ENV=production RAILS_ENV=production SECRET_KEY_BASE=abc123 bundle exec rake assets:precompile<% elsif Rake::Task.tasks.map(&:name).include?('assets:precompile') %>RUN NODE_ENV=production RAILS_ENV=production SECRET_KEY_BASE=abc123 bundle exec rake assets:precompile<% end %>
|
27
27
|
RUN echo "${GIT_COMMIT}" > /app/GIT_COMMIT
|
28
28
|
HEALTHCHECK --interval=<%= healthcheck['interval'] %> \
|
29
29
|
--timeout=<%= healthcheck['timeout'] %> \
|
@@ -12,3 +12,13 @@
|
|
12
12
|
test: test-setup
|
13
13
|
bundle exec rspec
|
14
14
|
bundle exec rubocop
|
15
|
+
|
16
|
+
# Start development containers and create/migrate/seed database
|
17
|
+
.PHONY: develop
|
18
|
+
develop:
|
19
|
+
bundle install
|
20
|
+
@$(MAKE) start env=test
|
21
|
+
@$(MAKE) start env=development
|
22
|
+
bundle exec rake db:create
|
23
|
+
bundle exec rake db:migrate
|
24
|
+
bundle exec rake db:seed
|
@@ -8,7 +8,7 @@ development:
|
|
8
8
|
port: <%= compose.call('development').local_port('database') %>
|
9
9
|
username: <%= compose.call(nil).database_adapter.credentials['username'] %>
|
10
10
|
password: <%= compose.call(nil).database_adapter.credentials['password'] %>
|
11
|
-
database:
|
11
|
+
database: development
|
12
12
|
<%% if ENV.key?('DEVELOPMENT_DATABASE_URL') %>
|
13
13
|
url: <%%= ENV['DEVELOPMENT_DATABASE_URL'] %>
|
14
14
|
<%% end %>
|
@@ -21,7 +21,7 @@ test:
|
|
21
21
|
port: <%= compose.call('test').local_port('database') %>
|
22
22
|
username: <%= compose.call(nil).database_adapter.credentials['username'] %>
|
23
23
|
password: <%= compose.call(nil).database_adapter.credentials['password'] %>
|
24
|
-
database:
|
24
|
+
database: test
|
25
25
|
# Useful for certain continuous integration environments (e.g. Jenkins in
|
26
26
|
# Docker) where the DB hostname may be a service name rather than `127.0.0.1`:
|
27
27
|
<%% if ENV.key?('TEST_DATABASE_URL') %>
|
@@ -8,8 +8,8 @@ else ifneq (,$(RACK_ENV))
|
|
8
8
|
endif
|
9
9
|
|
10
10
|
verify-environment:
|
11
|
-
ifndef
|
12
|
-
@$(error `
|
11
|
+
ifndef PUBLISH_PORT
|
12
|
+
@$(error `PUBLISH_PORT` must be defined in environment)
|
13
13
|
endif
|
14
14
|
|
15
15
|
ifndef env
|
@@ -22,9 +22,7 @@ compose_base:=env HOST_UID=$(shell id -u) \
|
|
22
22
|
DOCKER_REPOSITORY=%%REPOSITORY%%:%%VERSION%% \
|
23
23
|
docker-compose \
|
24
24
|
-p ${project_name} \
|
25
|
-
-f docker-compose.yml
|
26
|
-
|
27
|
-
compose:=${compose_base} -f docker-compose.production.yml -f docker-compose.override.yml
|
25
|
+
-f docker-compose.production.yml
|
28
26
|
|
29
27
|
.PHONY: deploy
|
30
28
|
deploy:
|
@@ -36,7 +34,7 @@ endif
|
|
36
34
|
|
37
35
|
.PHONY: deploy-stack
|
38
36
|
deploy-stack:
|
39
|
-
|
37
|
+
${compose} config | docker stack deploy --prune --with-registry-auth -c - ${project_name}
|
40
38
|
|
41
39
|
.PHONY: console
|
42
40
|
service := app
|
@@ -1,7 +1,4 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
#
|
5
|
-
# Use this setting to control the number of replicas to create for your
|
6
|
-
# application service:
|
7
|
-
REPLICAS=1
|
1
|
+
# Set any development environment variables here
|
2
|
+
# e.g.:
|
3
|
+
#
|
4
|
+
# DISABLE_SPRING=1
|
@@ -87,17 +87,19 @@ restore_env:=( \
|
|
87
87
|
|
88
88
|
key_chars:=[a-zA-Z0-9_]
|
89
89
|
censored:=**********
|
90
|
-
censor=
|
91
|
-
censor_urls:=
|
92
|
-
format_env
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
90
|
+
censor=s/\(^${key_chars}*$(1)${key_chars}*\)=\(.*\)$$/\1=${censored}/
|
91
|
+
censor_urls:=s|\([a-zA-Z0-9_+]\+://.*:\).*\(@.*\)$$|\1${censored}\2|
|
92
|
+
format_env:=sed '$(call censor,SECRET); \
|
93
|
+
$(call censor,TOKEN); \
|
94
|
+
$(call censor,PRIVATE); \
|
95
|
+
$(call censor,KEY); \
|
96
|
+
$(censor_urls); \
|
97
|
+
/^\s*$$/d; \
|
98
|
+
/^\s*\#/d; \
|
99
|
+
s/\(^[a-zA-Z0-9_]\+\)=/${blue}\1${reset}=/; \
|
100
|
+
s/^/ /; \
|
101
|
+
s/=\(.*\)$$/=${yellow}\1${reset}/' | \
|
102
|
+
sort
|
101
103
|
|
102
104
|
fail=( \
|
103
105
|
$(call printraw,' ${cross}') ; \
|
@@ -38,8 +38,15 @@ ifneq (,$(wildcard ${env_file}))
|
|
38
38
|
rake=. ${env_file} && ${rake_cmd}
|
39
39
|
endif
|
40
40
|
|
41
|
-
|
42
|
-
|
41
|
+
ifeq (,$(findstring serve,$(MAKECMDGOALS)))
|
42
|
+
ifeq (,$(findstring console,$(MAKECMDGOALS)))
|
43
|
+
ifeq (,$(findstring test,$(MAKECMDGOALS)))
|
44
|
+
docker_config:=$(shell ${rake} orchestration:config)
|
45
|
+
docker_organization=$(word 1,$(docker_config))
|
46
|
+
docker_repository=$(word 2,$(docker_config))
|
47
|
+
endif
|
48
|
+
endif
|
49
|
+
endif
|
43
50
|
|
44
51
|
ifeq (,$(project_name))
|
45
52
|
project_base = ${docker_repository}_${env}
|
@@ -73,19 +80,26 @@ else
|
|
73
80
|
compose_project_name = ${project_base}
|
74
81
|
endif
|
75
82
|
|
76
|
-
compose_base=env
|
83
|
+
compose_base=env -i \
|
84
|
+
PATH=$(PATH) \
|
85
|
+
HOST_UID=$(shell id -u) \
|
77
86
|
DOCKER_ORGANIZATION="${docker_organization}" \
|
78
87
|
DOCKER_REPOSITORY="${docker_repository}" \
|
79
88
|
COMPOSE_PROJECT_NAME="${compose_project_name}" \
|
80
89
|
${sidecar_compose} \
|
81
90
|
docker-compose \
|
82
|
-
-f
|
91
|
+
-f ${orchestration_dir}/docker-compose.${env}.yml
|
83
92
|
|
84
93
|
git_branch ?= $(if $(branch),$(branch),$(shell git rev-parse --abbrev-ref HEAD))
|
85
|
-
|
94
|
+
ifndef dev
|
95
|
+
git_version ?= $(shell git rev-parse --short --verify ${git_branch})
|
96
|
+
else
|
97
|
+
git_version = dev
|
98
|
+
endif
|
99
|
+
|
86
100
|
docker_image=${docker_organization}/${docker_repository}:${git_version}
|
87
101
|
|
88
|
-
compose=${compose_base}
|
102
|
+
compose=${compose_base}
|
89
103
|
random_str=cat /dev/urandom | LC_ALL=C tr -dc 'a-z' | head -c $1
|
90
104
|
|
91
105
|
ifneq (,$(wildcard ${orchestration_dir}/docker-compose.local.yml))
|
@@ -100,10 +114,10 @@ all: build
|
|
100
114
|
ifndef network
|
101
115
|
start: network := ${compose_project_name}_default
|
102
116
|
endif
|
103
|
-
start: _clean-logs
|
104
|
-
@$(call print,'${yellow}Starting containers${reset} ...')
|
117
|
+
start: _create-log-directory _clean-logs
|
118
|
+
@$(call print,'${yellow}Starting ${cyan}${env}${yellow} containers${reset} ...')
|
105
119
|
ifeq (${env},$(filter ${env},test development))
|
106
|
-
@${compose} up --detach --force-recreate --renew-anon-volumes ${services} ${log} || ${fail}
|
120
|
+
@${compose} up --detach --force-recreate --renew-anon-volumes --remove-orphans ${services} ${log} || ${fail}
|
107
121
|
@[ -n '${sidecar}' ] && \
|
108
122
|
( \
|
109
123
|
$(call printraw,' ${yellow}(joining dependency network ${green}${network}${yellow})${reset} ... ') ; \
|
@@ -132,7 +146,7 @@ start-<%= service %>:
|
|
132
146
|
.PHONY: stop
|
133
147
|
stop: network := ${compose_project_name}_default
|
134
148
|
stop:
|
135
|
-
@$(call print,'${yellow}Stopping containers${reset} ...')
|
149
|
+
@$(call print,'${yellow}Stopping ${cyan}${env}${yellow} containers${reset} ...')
|
136
150
|
@if docker ps --format "{{.ID}}" | grep -q $(shell hostname) ; \
|
137
151
|
then \
|
138
152
|
( docker network disconnect ${network} $(shell hostname) ${log} || : ) \
|
@@ -165,7 +179,7 @@ serve:
|
|
165
179
|
then ( \
|
166
180
|
$(call println,'${yellow}Environment${reset}: ${green}${env_file}${reset}') && \
|
167
181
|
cat '${env_file}' | ${format_env} && \
|
168
|
-
$(call
|
182
|
+
$(call printrawln,'') \
|
169
183
|
) ; \
|
170
184
|
fi
|
171
185
|
${rails}
|
@@ -178,7 +192,7 @@ console:
|
|
178
192
|
then ( \
|
179
193
|
$(call println,'${yellow}Environment${reset}: ${green}${env_file}${reset}') && \
|
180
194
|
cat '${env_file}' | ${format_env} && \
|
181
|
-
$(call
|
195
|
+
$(call printrawln,'') \
|
182
196
|
) ; \
|
183
197
|
fi
|
184
198
|
${rails} console
|
@@ -186,23 +200,25 @@ console:
|
|
186
200
|
.PHONY: test-setup
|
187
201
|
test-setup: env := test
|
188
202
|
test-setup:
|
203
|
+
ifndef light
|
189
204
|
@$(call make,start env=test)
|
190
|
-
ifneq (,$(wildcard config/database.yml))
|
205
|
+
ifneq (,$(wildcard config/database.yml))
|
191
206
|
${rake} db:create || :
|
192
|
-
|
207
|
+
ifneq (,$(wildcard db/structure.sql))
|
193
208
|
${rake} db:structure:load
|
194
|
-
|
209
|
+
else ifneq (,$(wildcard db/schema.rb))
|
195
210
|
${rake} db:schema:load
|
196
|
-
|
211
|
+
endif
|
197
212
|
|
198
213
|
${rake} db:migrate
|
214
|
+
endif
|
199
215
|
endif
|
200
216
|
|
201
217
|
.PHONY: dump
|
202
218
|
dump:
|
203
219
|
ifndef verbose
|
204
220
|
@$(call println)
|
205
|
-
@$(call println,'${yellow}Captured${reset} ${green}stdout${reset} ${yellow}and${reset} ${red}stderr${reset} ${yellow}log data${reset}:')
|
221
|
+
@$(call println,'${yellow}Captured${reset} ${green}stdout${reset} ${yellow}and${reset} ${red}stderr${reset} ${yellow}log data [${cyan}${env}${yellow}]${reset}:')
|
206
222
|
@$(call println)
|
207
223
|
@echo
|
208
224
|
@test -f '${stdout}' && ( \
|
@@ -249,10 +265,6 @@ endif
|
|
249
265
|
-e "s/%%ORGANIZATION%%/${docker_organization}/g" \
|
250
266
|
${orchestration_dir}/deploy.mk > \
|
251
267
|
${orchestration_dir}/.deploy/${docker_repository}/Makefile
|
252
|
-
@cp ${orchestration_dir}/docker-compose.yml \
|
253
|
-
${orchestration_dir}/docker-compose.production.yml \
|
254
|
-
${orchestration_dir}/docker-compose.override.yml \
|
255
|
-
${orchestration_dir}/.deploy/${docker_repository}/
|
256
268
|
@bundle_path="${path}" ; tar -C '${orchestration_dir}/.deploy' -cf "$${bundle_path:-./bundle.tar}" ./${docker_repository}
|
257
269
|
|
258
270
|
.PHONY: deploy
|
@@ -264,7 +276,7 @@ deploy:
|
|
264
276
|
ifndef manager
|
265
277
|
@$(call println_error,'Missing `manager` parameter: `make deploy manager=swarm-manager.example.com`') ; exit 1
|
266
278
|
endif
|
267
|
-
@$(call println,'${yellow}Deploying stack via${reset} ${green}${manager}${reset} ...') && \
|
279
|
+
@$(call println,'${yellow}Deploying ${green}${env}${reset} stack via${reset} ${green}${manager}${reset} ...') && \
|
268
280
|
( \
|
269
281
|
$(call make,bundle path='${path}/bundle.tar') ${log} && \
|
270
282
|
cd '${path}' ${log} && \
|
@@ -312,17 +324,31 @@ wait-listener:
|
|
312
324
|
### Docker build commands ###
|
313
325
|
|
314
326
|
.PHONY: build
|
315
|
-
build:
|
316
|
-
build:
|
327
|
+
build: build_dir = ${orchestration_dir}/.build
|
328
|
+
build: context = ${build_dir}/context.tar
|
329
|
+
build: _create-log-directory check-local-changes
|
317
330
|
@$(call print,'${yellow}Preparing build context from${reset} ${cyan}${git_branch}:${git_version}${reset} ... ')
|
318
331
|
@mkdir -p ${orchestration_dir}/.build ${log} || ${fail}
|
332
|
+
ifndef dev
|
319
333
|
@git show ${git_branch}:./Gemfile > ${orchestration_dir}/.build/Gemfile 2>${stderr} || ${fail}
|
320
334
|
@git show ${git_branch}:./Gemfile.lock > ${orchestration_dir}/.build/Gemfile.lock 2>${stderr} || ${fail}
|
321
335
|
<% if defined?(Webpacker) %> @git show ${git_branch}:./package.json > ${orchestration_dir}/.build/package.json 2>${stderr} || ${fail}<% end %>
|
322
336
|
<% if defined?(Webpacker) %> @git show ${git_branch}:./yarn.lock > ${orchestration_dir}/.build/yarn.lock 2>${stderr} || ${fail}<% end %>
|
323
337
|
@git archive --format 'tar' -o '${context}' '${git_branch}' ${log} || ${fail}
|
324
|
-
|
338
|
+
else
|
339
|
+
@tar -cvf '${context}' . ${log} || ${fail}
|
340
|
+
endif
|
325
341
|
@$(call printrawln,'${green}complete.${reset} ${tick}')
|
342
|
+
ifdef include
|
343
|
+
@$(call print,'${yellow}Including files from:${reset} ${cyan}${include}${reset} ...')
|
344
|
+
@(while read line; do \
|
345
|
+
export line; \
|
346
|
+
include_dir="${build_dir}/$$(dirname "$${line}")/" && \
|
347
|
+
mkdir -p "$${include_dir}" && cp "$${line}" "$${include_dir}" \
|
348
|
+
&& (cd '${orchestration_dir}/.build/' && tar rf 'context.tar' "$${line}"); \
|
349
|
+
done < '${include}') ${log} || ${fail}
|
350
|
+
@$(call printrawln,' ${green}complete.${reset} ${tick}')
|
351
|
+
endif
|
326
352
|
ifdef sidecar
|
327
353
|
# Assume we are in a line-buffered environment (e.g. Jenkins)
|
328
354
|
@$(call println,'${yellow}Building image${reset} ...')
|
@@ -341,14 +367,29 @@ endif
|
|
341
367
|
@$(call println,'[${green}tag${reset}] ${cyan}${docker_organization}/${docker_repository}:${git_version}${reset}')
|
342
368
|
|
343
369
|
.PHONY: push
|
344
|
-
push:
|
370
|
+
push: _create-log-directory
|
345
371
|
@$(call print,'${yellow}Pushing${reset} ${cyan}${docker_image}${reset} ...')
|
346
372
|
@docker push ${docker_image} ${log_progress} || ${fail}
|
347
373
|
@$(call printrawln,' ${green}complete${reset}. ${tick}')
|
348
374
|
|
375
|
+
.PHONY: check-local-changes
|
376
|
+
check-local-changes:
|
377
|
+
ifndef dev
|
378
|
+
@if [[ ! -z "$$(git status --porcelain)" ]] ; \
|
379
|
+
then \
|
380
|
+
$(call println,'${red}You have uncommitted changes which will not be included in your build:${reset}') ; \
|
381
|
+
git status --porcelain ; \
|
382
|
+
$(call println,'${yellow}Use ${cyan}make build dev=1${reset} ${yellow}to include these files.${reset}\n') ; \
|
383
|
+
fi
|
384
|
+
endif
|
385
|
+
|
349
386
|
### Internal Commands ###
|
350
387
|
#
|
351
388
|
.PHONY: _clean-logs
|
352
389
|
_clean-logs:
|
353
390
|
@rm -f '${stdout}' '${stderr}'
|
354
391
|
@touch '${stdout}' '${stderr}'
|
392
|
+
|
393
|
+
.PHONY: _create-log-directory
|
394
|
+
_create-log-directory:
|
395
|
+
@mkdir -p log
|
@@ -15,10 +15,23 @@ namespace :orchestration do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
desc I18n.t('orchestration.rake.config')
|
19
|
+
task :config do
|
20
|
+
config = YAML.safe_load(File.read('.orchestration.yml'))
|
21
|
+
puts "#{config['docker']['organization']} #{config['docker']['repository']}"
|
22
|
+
end
|
23
|
+
|
24
|
+
desc I18n.t('orchestration.rake.healthcheck')
|
25
|
+
task :healthcheck do
|
26
|
+
Orchestration::DockerHealthcheck.execute
|
27
|
+
end
|
28
|
+
|
29
|
+
desc I18n.t('orchestration.rake.wait')
|
18
30
|
task :wait do
|
31
|
+
Orchestration::InstallGenerator.new.verify_makefile(false)
|
19
32
|
env = Orchestration::Environment.new
|
20
33
|
services = Orchestration::Services
|
21
|
-
env.docker_compose_config['services'].each do |name,
|
34
|
+
env.docker_compose_config['services'].each do |name, _service|
|
22
35
|
path = nil
|
23
36
|
|
24
37
|
adapter = if name == 'database'
|
@@ -39,50 +52,4 @@ namespace :orchestration do
|
|
39
52
|
)
|
40
53
|
end
|
41
54
|
end
|
42
|
-
|
43
|
-
namespace :app do
|
44
|
-
desc I18n.t('orchestration.rake.app.wait')
|
45
|
-
task :wait do
|
46
|
-
Orchestration::Services::App::Healthcheck.start(
|
47
|
-
nil, nil, config_path: ENV['config'], service_name: ENV['service']
|
48
|
-
)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
namespace :database do
|
53
|
-
desc I18n.t('orchestration.rake.database.wait')
|
54
|
-
task :wait do
|
55
|
-
Orchestration::Services::Database::Healthcheck.start(
|
56
|
-
nil, nil, config_path: ENV['config'], service_name: ENV['service']
|
57
|
-
)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
namespace :mongo do
|
62
|
-
desc I18n.t('orchestration.rake.mongo.wait')
|
63
|
-
task :wait do
|
64
|
-
Orchestration::Services::Mongo::Healthcheck.start(
|
65
|
-
nil, nil, config_path: ENV['config'], service_name: ENV['service']
|
66
|
-
)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
namespace :rabbitmq do
|
71
|
-
desc I18n.t('orchestration.rake.rabbitmq.wait')
|
72
|
-
task :wait do
|
73
|
-
Orchestration::Services::RabbitMQ::Healthcheck.start(
|
74
|
-
nil, nil, config_path: ENV['config'], service_name: ENV['service']
|
75
|
-
)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
namespace :listener do
|
80
|
-
desc I18n.t('orchestration.rake.listener.wait')
|
81
|
-
task :wait do
|
82
|
-
Orchestration::Services::Listener::Healthcheck.start(
|
83
|
-
nil, nil, service_name: ENV.fetch('service'),
|
84
|
-
sidecar: ENV['sidecar']
|
85
|
-
)
|
86
|
-
end
|
87
|
-
end
|
88
55
|
end
|
data/orchestration.gemspec
CHANGED
@@ -16,8 +16,11 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.homepage = url
|
17
17
|
|
18
18
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
19
|
-
|
19
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
21
|
+
end
|
20
22
|
end
|
23
|
+
|
21
24
|
spec.bindir = 'bin'
|
22
25
|
spec.executables = []
|
23
26
|
spec.require_paths = ['lib']
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: orchestration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Farrell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: database_url
|
@@ -318,15 +318,11 @@ files:
|
|
318
318
|
- ".travis.yml"
|
319
319
|
- Gemfile
|
320
320
|
- LICENSE
|
321
|
-
- MANIFEST
|
322
321
|
- Makefile
|
323
322
|
- README.md
|
324
323
|
- Rakefile
|
325
324
|
- bin/console
|
326
|
-
- bin/rspec
|
327
|
-
- bin/rubocop
|
328
325
|
- bin/setup
|
329
|
-
- bin/strong_versions
|
330
326
|
- config/locales/en.yml
|
331
327
|
- doc/images/example.png
|
332
328
|
- lib/Rakefile
|
@@ -340,6 +336,7 @@ files:
|
|
340
336
|
- lib/orchestration/docker_compose/install_generator.rb
|
341
337
|
- lib/orchestration/docker_compose/mongo_service.rb
|
342
338
|
- lib/orchestration/docker_compose/rabbitmq_service.rb
|
339
|
+
- lib/orchestration/docker_healthcheck.rb
|
343
340
|
- lib/orchestration/environment.rb
|
344
341
|
- lib/orchestration/errors.rb
|
345
342
|
- lib/orchestration/file_helpers.rb
|
@@ -374,17 +371,14 @@ files:
|
|
374
371
|
- lib/orchestration/templates/application.mk.erb
|
375
372
|
- lib/orchestration/templates/database.yml.erb
|
376
373
|
- lib/orchestration/templates/deploy.mk.erb
|
377
|
-
- lib/orchestration/templates/docker-compose.override.yml.erb
|
378
374
|
- lib/orchestration/templates/entrypoint.sh.erb
|
379
375
|
- lib/orchestration/templates/env.erb
|
380
|
-
- lib/orchestration/templates/healthcheck.rb.erb
|
381
376
|
- lib/orchestration/templates/makefile_macros.mk.erb
|
382
377
|
- lib/orchestration/templates/mongoid.yml.erb
|
383
378
|
- lib/orchestration/templates/orchestration.mk.erb
|
384
379
|
- lib/orchestration/templates/puma.rb.erb
|
385
380
|
- lib/orchestration/templates/rabbitmq.yml.erb
|
386
381
|
- lib/orchestration/templates/unicorn.rb.erb
|
387
|
-
- lib/orchestration/templates/yaml.bash.erb
|
388
382
|
- lib/orchestration/terminal.rb
|
389
383
|
- lib/orchestration/version.rb
|
390
384
|
- lib/tasks/orchestration.rake
|
data/MANIFEST
DELETED
@@ -1,78 +0,0 @@
|
|
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
|
-
doc/images/example.png
|
19
|
-
lib/Rakefile
|
20
|
-
lib/orchestration.rb
|
21
|
-
lib/orchestration/docker_compose.rb
|
22
|
-
lib/orchestration/docker_compose/app_service.rb
|
23
|
-
lib/orchestration/docker_compose/compose_configuration.rb
|
24
|
-
lib/orchestration/docker_compose/compose_helpers.rb
|
25
|
-
lib/orchestration/docker_compose/configuration.rb
|
26
|
-
lib/orchestration/docker_compose/database_service.rb
|
27
|
-
lib/orchestration/docker_compose/install_generator.rb
|
28
|
-
lib/orchestration/docker_compose/mongo_service.rb
|
29
|
-
lib/orchestration/docker_compose/rabbitmq_service.rb
|
30
|
-
lib/orchestration/environment.rb
|
31
|
-
lib/orchestration/errors.rb
|
32
|
-
lib/orchestration/file_helpers.rb
|
33
|
-
lib/orchestration/install_generator.rb
|
34
|
-
lib/orchestration/railtie.rb
|
35
|
-
lib/orchestration/service_check.rb
|
36
|
-
lib/orchestration/services.rb
|
37
|
-
lib/orchestration/services/app.rb
|
38
|
-
lib/orchestration/services/app/configuration.rb
|
39
|
-
lib/orchestration/services/app/healthcheck.rb
|
40
|
-
lib/orchestration/services/database.rb
|
41
|
-
lib/orchestration/services/database/adapters.rb
|
42
|
-
lib/orchestration/services/database/adapters/mysql2.rb
|
43
|
-
lib/orchestration/services/database/adapters/postgresql.rb
|
44
|
-
lib/orchestration/services/database/adapters/sqlite3.rb
|
45
|
-
lib/orchestration/services/database/configuration.rb
|
46
|
-
lib/orchestration/services/database/healthcheck.rb
|
47
|
-
lib/orchestration/services/listener.rb
|
48
|
-
lib/orchestration/services/listener/configuration.rb
|
49
|
-
lib/orchestration/services/listener/healthcheck.rb
|
50
|
-
lib/orchestration/services/mixins/configuration_base.rb
|
51
|
-
lib/orchestration/services/mixins/healthcheck_base.rb
|
52
|
-
lib/orchestration/services/mixins/http_healthcheck.rb
|
53
|
-
lib/orchestration/services/mongo.rb
|
54
|
-
lib/orchestration/services/mongo/configuration.rb
|
55
|
-
lib/orchestration/services/mongo/healthcheck.rb
|
56
|
-
lib/orchestration/services/rabbitmq.rb
|
57
|
-
lib/orchestration/services/rabbitmq/configuration.rb
|
58
|
-
lib/orchestration/services/rabbitmq/healthcheck.rb
|
59
|
-
lib/orchestration/settings.rb
|
60
|
-
lib/orchestration/templates/Dockerfile.erb
|
61
|
-
lib/orchestration/templates/application.mk.erb
|
62
|
-
lib/orchestration/templates/database.yml.erb
|
63
|
-
lib/orchestration/templates/deploy.mk.erb
|
64
|
-
lib/orchestration/templates/docker-compose.override.yml.erb
|
65
|
-
lib/orchestration/templates/entrypoint.sh.erb
|
66
|
-
lib/orchestration/templates/env.erb
|
67
|
-
lib/orchestration/templates/healthcheck.rb.erb
|
68
|
-
lib/orchestration/templates/makefile_macros.mk.erb
|
69
|
-
lib/orchestration/templates/mongoid.yml.erb
|
70
|
-
lib/orchestration/templates/orchestration.mk.erb
|
71
|
-
lib/orchestration/templates/puma.rb.erb
|
72
|
-
lib/orchestration/templates/rabbitmq.yml.erb
|
73
|
-
lib/orchestration/templates/unicorn.rb.erb
|
74
|
-
lib/orchestration/templates/yaml.bash.erb
|
75
|
-
lib/orchestration/terminal.rb
|
76
|
-
lib/orchestration/version.rb
|
77
|
-
lib/tasks/orchestration.rake
|
78
|
-
orchestration.gemspec
|
data/bin/rspec
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
#
|
5
|
-
# This file was generated by Bundler.
|
6
|
-
#
|
7
|
-
# The application 'rspec' is installed as part of a gem, and
|
8
|
-
# this file is here to facilitate running it.
|
9
|
-
#
|
10
|
-
|
11
|
-
require "pathname"
|
12
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
-
Pathname.new(__FILE__).realpath)
|
14
|
-
|
15
|
-
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
-
|
17
|
-
if File.file?(bundle_binstub)
|
18
|
-
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
-
load(bundle_binstub)
|
20
|
-
else
|
21
|
-
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
-
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
require "rubygems"
|
27
|
-
require "bundler/setup"
|
28
|
-
|
29
|
-
load Gem.bin_path("rspec-core", "rspec")
|
data/bin/rubocop
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
#
|
5
|
-
# This file was generated by Bundler.
|
6
|
-
#
|
7
|
-
# The application 'rubocop' is installed as part of a gem, and
|
8
|
-
# this file is here to facilitate running it.
|
9
|
-
#
|
10
|
-
|
11
|
-
require "pathname"
|
12
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
-
Pathname.new(__FILE__).realpath)
|
14
|
-
|
15
|
-
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
-
|
17
|
-
if File.file?(bundle_binstub)
|
18
|
-
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
-
load(bundle_binstub)
|
20
|
-
else
|
21
|
-
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
-
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
require "rubygems"
|
27
|
-
require "bundler/setup"
|
28
|
-
|
29
|
-
load Gem.bin_path("rubocop", "rubocop")
|
data/bin/strong_versions
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
#
|
5
|
-
# This file was generated by Bundler.
|
6
|
-
#
|
7
|
-
# The application 'strong_versions' is installed as part of a gem, and
|
8
|
-
# this file is here to facilitate running it.
|
9
|
-
#
|
10
|
-
|
11
|
-
require "pathname"
|
12
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
-
Pathname.new(__FILE__).realpath)
|
14
|
-
|
15
|
-
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
-
|
17
|
-
if File.file?(bundle_binstub)
|
18
|
-
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
-
load(bundle_binstub)
|
20
|
-
else
|
21
|
-
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
-
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
require "rubygems"
|
27
|
-
require "bundler/setup"
|
28
|
-
|
29
|
-
load Gem.bin_path("strong_versions", "strong_versions")
|
@@ -1 +0,0 @@
|
|
1
|
-
version: <%= env.docker_api_version.to_json %>
|
@@ -1,56 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Orchestration Healthcheck Utility
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# https://github.com/bobf/orchestration
|
6
|
-
#
|
7
|
-
|
8
|
-
require 'net/http'
|
9
|
-
|
10
|
-
def run
|
11
|
-
client = Net::HTTP.new(
|
12
|
-
ENV.fetch('WEB_HOST', 'localhost'),
|
13
|
-
ENV.fetch('WEB_PORT', '8080').to_i
|
14
|
-
)
|
15
|
-
|
16
|
-
client.read_timeout = ENV.fetch('WEB_HEALTHCHECK_READ_TIMEOUT', '10').to_i
|
17
|
-
client.open_timeout = ENV.fetch('WEB_HEALTHCHECK_OPEN_TIMEOUT', '10').to_i
|
18
|
-
|
19
|
-
client.start do |request|
|
20
|
-
request.get(ENV.fetch('WEB_HEALTHCHECK_PATH') { '/' })
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def success_codes
|
25
|
-
ENV.fetch('WEB_HEALTHCHECK_SUCCESS_CODES', '200,202,204').split(',')
|
26
|
-
end
|
27
|
-
|
28
|
-
def success?(code)
|
29
|
-
success_codes.include?(code.to_s)
|
30
|
-
end
|
31
|
-
|
32
|
-
def message(code)
|
33
|
-
if success?(code)
|
34
|
-
outcome = 'SUCCESS ✓ '
|
35
|
-
in_or_not = 'IN'
|
36
|
-
else
|
37
|
-
outcome = 'FAILURE ✘ '
|
38
|
-
in_or_not = 'NOT IN'
|
39
|
-
end
|
40
|
-
|
41
|
-
accepted = success_codes.join(', ')
|
42
|
-
|
43
|
-
"# HTTP_STATUS(#{code}) #{in_or_not} [#{accepted}] : #{outcome} [#{__FILE__}]"
|
44
|
-
end
|
45
|
-
|
46
|
-
return_code = 1
|
47
|
-
|
48
|
-
begin
|
49
|
-
response = run
|
50
|
-
return_code = 0 if success?(response.code)
|
51
|
-
puts message(response.code)
|
52
|
-
rescue Exception => e
|
53
|
-
puts "[#{__FILE__}] ERROR: #{e.inspect}"
|
54
|
-
ensure
|
55
|
-
exit return_code
|
56
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# https://stackoverflow.com/a/21189044 - thanks.
|
2
|
-
function parse_yaml {
|
3
|
-
local prefix=$2
|
4
|
-
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
|
5
|
-
sed -ne "s|^\($s\):|\1|" \
|
6
|
-
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
|
7
|
-
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
|
8
|
-
awk -F$fs '{
|
9
|
-
indent = length($1)/2;
|
10
|
-
vname[indent] = $2;
|
11
|
-
for (i in vname) {if (i > indent) {delete vname[i]}}
|
12
|
-
if (length($3) > 0) {
|
13
|
-
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
|
14
|
-
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
|
15
|
-
}
|
16
|
-
}'
|
17
|
-
}
|
18
|
-
|
19
|
-
eval $(parse_yaml ./.orchestration.yml)
|
20
|
-
|
21
|
-
set -u
|
22
|
-
echo -n "$(eval echo \$$1)"
|