orchestration 0.5.0 → 0.5.1
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 +6 -1
- data/config/locales/en.yml +4 -23
- data/lib/orchestration/docker_compose/app_service.rb +1 -1
- data/lib/orchestration/docker_compose/install_generator.rb +0 -16
- data/lib/orchestration/docker_healthcheck.rb +64 -0
- data/lib/orchestration/environment.rb +1 -1
- data/lib/orchestration/file_helpers.rb +1 -2
- data/lib/orchestration/install_generator.rb +25 -22
- data/lib/orchestration/services/database/configuration.rb +2 -2
- data/lib/orchestration/services/database/healthcheck.rb +1 -1
- data/lib/orchestration/templates/application.mk.erb +8 -0
- data/lib/orchestration/templates/database.yml.erb +2 -2
- data/lib/orchestration/templates/deploy.mk.erb +2 -4
- data/lib/orchestration/templates/entrypoint.sh.erb +1 -1
- data/lib/orchestration/templates/orchestration.mk.erb +34 -16
- data/lib/orchestration/version.rb +1 -1
- data/lib/tasks/orchestration.rake +14 -47
- data/orchestration.gemspec +4 -1
- metadata +3 -6
- data/MANIFEST +0 -78
- 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: c3ef93d88b5d6c2c60bf1c558ec2f04c3563194bae32a5374b53b8a2dd53a73f
|
4
|
+
data.tar.gz: 1488c9004ca7857e59e4dafd5f2276d4c0dd2ad70776ad57f6250dc633895e99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93470c6903f7aaa33b3e684712884733b9112080e7b94bd8461feff6c9fe15c9a647710be340fcd4071a143c9d4a31e2dd2c2bd47de31333b8e93bd121072818
|
7
|
+
data.tar.gz: 024df80165322260d9a9df620eedc4b69fe9e4d844b35f5a21b5ce5a7658f380ac85fd37aec169ed2c50f59917dc89a18a75f661062b8cdb12833b29c5c6eb80
|
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
@@ -35,7 +35,7 @@ The below screenshot demonstrates _Orchestration_ being installed in a brand new
|
|
35
35
|
Add _Orchestration_ to your Gemfile:
|
36
36
|
|
37
37
|
```ruby
|
38
|
-
gem 'orchestration', '~> 0.5.
|
38
|
+
gem 'orchestration', '~> 0.5.1'
|
39
39
|
```
|
40
40
|
|
41
41
|
Install:
|
@@ -56,6 +56,11 @@ rake orchestration:install server=unicorn # (or 'puma' [default], etc.)
|
|
56
56
|
|
57
57
|
To rebuild all build-out at any time, pass `force=yes` to the above install command.
|
58
58
|
|
59
|
+
To rebuild just `orchestration/Makefile` (useful after upgrading the _Orchestration_ gem):
|
60
|
+
```bash
|
61
|
+
rake orchestration:install:makefile
|
62
|
+
```
|
63
|
+
|
59
64
|
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
65
|
|
61
66
|
#### Configuration files
|
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"
|
@@ -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
|
@@ -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,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
|
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 request
|
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,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
|
@@ -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
|
@@ -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
|
|
@@ -12,3 +12,11 @@
|
|
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: start
|
19
|
+
bundle install
|
20
|
+
bundle exec rake db:create
|
21
|
+
bundle exec rake db:migrate
|
22
|
+
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') %>
|
@@ -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
|
@@ -38,8 +38,9 @@ ifneq (,$(wildcard ${env_file}))
|
|
38
38
|
rake=. ${env_file} && ${rake_cmd}
|
39
39
|
endif
|
40
40
|
|
41
|
-
|
42
|
-
|
41
|
+
docker_config:=$(shell ${rake} orchestration:config)
|
42
|
+
docker_organization=$(word 1,$(docker_config))
|
43
|
+
docker_repository=$(word 2,$(docker_config))
|
43
44
|
|
44
45
|
ifeq (,$(project_name))
|
45
46
|
project_base = ${docker_repository}_${env}
|
@@ -79,13 +80,18 @@ compose_base=env HOST_UID=$(shell id -u) \
|
|
79
80
|
COMPOSE_PROJECT_NAME="${compose_project_name}" \
|
80
81
|
${sidecar_compose} \
|
81
82
|
docker-compose \
|
82
|
-
-f
|
83
|
+
-f ${orchestration_dir}/docker-compose.${env}.yml
|
83
84
|
|
84
85
|
git_branch ?= $(if $(branch),$(branch),$(shell git rev-parse --abbrev-ref HEAD))
|
85
|
-
|
86
|
+
ifndef dev
|
87
|
+
git_version ?= $(shell git rev-parse --short --verify ${git_branch})
|
88
|
+
else
|
89
|
+
git_version = dev
|
90
|
+
endif
|
91
|
+
|
86
92
|
docker_image=${docker_organization}/${docker_repository}:${git_version}
|
87
93
|
|
88
|
-
compose=${compose_base}
|
94
|
+
compose=${compose_base}
|
89
95
|
random_str=cat /dev/urandom | LC_ALL=C tr -dc 'a-z' | head -c $1
|
90
96
|
|
91
97
|
ifneq (,$(wildcard ${orchestration_dir}/docker-compose.local.yml))
|
@@ -103,7 +109,7 @@ endif
|
|
103
109
|
start: _clean-logs
|
104
110
|
@$(call print,'${yellow}Starting containers${reset} ...')
|
105
111
|
ifeq (${env},$(filter ${env},test development))
|
106
|
-
@${compose} up --detach --force-recreate --renew-anon-volumes ${services} ${log} || ${fail}
|
112
|
+
@${compose} up --detach --force-recreate --renew-anon-volumes --remove-orphans ${services} ${log} || ${fail}
|
107
113
|
@[ -n '${sidecar}' ] && \
|
108
114
|
( \
|
109
115
|
$(call printraw,' ${yellow}(joining dependency network ${green}${network}${yellow})${reset} ... ') ; \
|
@@ -186,16 +192,18 @@ console:
|
|
186
192
|
.PHONY: test-setup
|
187
193
|
test-setup: env := test
|
188
194
|
test-setup:
|
195
|
+
ifndef light
|
189
196
|
@$(call make,start env=test)
|
190
|
-
ifneq (,$(wildcard config/database.yml))
|
197
|
+
ifneq (,$(wildcard config/database.yml))
|
191
198
|
${rake} db:create || :
|
192
|
-
|
199
|
+
ifneq (,$(wildcard db/structure.sql))
|
193
200
|
${rake} db:structure:load
|
194
|
-
|
201
|
+
else ifneq (,$(wildcard db/schema.rb))
|
195
202
|
${rake} db:schema:load
|
196
|
-
|
203
|
+
endif
|
197
204
|
|
198
205
|
${rake} db:migrate
|
206
|
+
endif
|
199
207
|
endif
|
200
208
|
|
201
209
|
.PHONY: dump
|
@@ -249,10 +257,6 @@ endif
|
|
249
257
|
-e "s/%%ORGANIZATION%%/${docker_organization}/g" \
|
250
258
|
${orchestration_dir}/deploy.mk > \
|
251
259
|
${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
260
|
@bundle_path="${path}" ; tar -C '${orchestration_dir}/.deploy' -cf "$${bundle_path:-./bundle.tar}" ./${docker_repository}
|
257
261
|
|
258
262
|
.PHONY: deploy
|
@@ -313,15 +317,18 @@ wait-listener:
|
|
313
317
|
|
314
318
|
.PHONY: build
|
315
319
|
build: context = ${orchestration_dir}/.build/context.tar
|
316
|
-
build:
|
320
|
+
build: check-local-changes
|
317
321
|
@$(call print,'${yellow}Preparing build context from${reset} ${cyan}${git_branch}:${git_version}${reset} ... ')
|
318
322
|
@mkdir -p ${orchestration_dir}/.build ${log} || ${fail}
|
323
|
+
ifndef dev
|
319
324
|
@git show ${git_branch}:./Gemfile > ${orchestration_dir}/.build/Gemfile 2>${stderr} || ${fail}
|
320
325
|
@git show ${git_branch}:./Gemfile.lock > ${orchestration_dir}/.build/Gemfile.lock 2>${stderr} || ${fail}
|
321
326
|
<% if defined?(Webpacker) %> @git show ${git_branch}:./package.json > ${orchestration_dir}/.build/package.json 2>${stderr} || ${fail}<% end %>
|
322
327
|
<% if defined?(Webpacker) %> @git show ${git_branch}:./yarn.lock > ${orchestration_dir}/.build/yarn.lock 2>${stderr} || ${fail}<% end %>
|
323
328
|
@git archive --format 'tar' -o '${context}' '${git_branch}' ${log} || ${fail}
|
324
|
-
|
329
|
+
else
|
330
|
+
@tar -cvf '${context}' . ${log} || ${fail}
|
331
|
+
endif
|
325
332
|
@$(call printrawln,'${green}complete.${reset} ${tick}')
|
326
333
|
ifdef sidecar
|
327
334
|
# Assume we are in a line-buffered environment (e.g. Jenkins)
|
@@ -346,6 +353,17 @@ push:
|
|
346
353
|
@docker push ${docker_image} ${log_progress} || ${fail}
|
347
354
|
@$(call printrawln,' ${green}complete${reset}. ${tick}')
|
348
355
|
|
356
|
+
.PHONY: check-local-changes
|
357
|
+
check-local-changes:
|
358
|
+
ifndef dev
|
359
|
+
@if [[ ! -z "$$(git status --porcelain)" ]] ; \
|
360
|
+
then \
|
361
|
+
$(call println,'${red}You have uncommitted changes which will not be included in your build:${reset}') ; \
|
362
|
+
git status --porcelain ; \
|
363
|
+
$(call println,'${yellow}Use ${cyan}make build dev=1${reset} ${yellow}to include these files.${reset}\n') ; \
|
364
|
+
fi
|
365
|
+
endif
|
366
|
+
|
349
367
|
### Internal Commands ###
|
350
368
|
#
|
351
369
|
.PHONY: _clean-logs
|
@@ -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::Healthcheck.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.1
|
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-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: database_url
|
@@ -318,7 +318,6 @@ files:
|
|
318
318
|
- ".travis.yml"
|
319
319
|
- Gemfile
|
320
320
|
- LICENSE
|
321
|
-
- MANIFEST
|
322
321
|
- Makefile
|
323
322
|
- README.md
|
324
323
|
- Rakefile
|
@@ -340,6 +339,7 @@ files:
|
|
340
339
|
- lib/orchestration/docker_compose/install_generator.rb
|
341
340
|
- lib/orchestration/docker_compose/mongo_service.rb
|
342
341
|
- lib/orchestration/docker_compose/rabbitmq_service.rb
|
342
|
+
- lib/orchestration/docker_healthcheck.rb
|
343
343
|
- lib/orchestration/environment.rb
|
344
344
|
- lib/orchestration/errors.rb
|
345
345
|
- lib/orchestration/file_helpers.rb
|
@@ -374,17 +374,14 @@ files:
|
|
374
374
|
- lib/orchestration/templates/application.mk.erb
|
375
375
|
- lib/orchestration/templates/database.yml.erb
|
376
376
|
- lib/orchestration/templates/deploy.mk.erb
|
377
|
-
- lib/orchestration/templates/docker-compose.override.yml.erb
|
378
377
|
- lib/orchestration/templates/entrypoint.sh.erb
|
379
378
|
- lib/orchestration/templates/env.erb
|
380
|
-
- lib/orchestration/templates/healthcheck.rb.erb
|
381
379
|
- lib/orchestration/templates/makefile_macros.mk.erb
|
382
380
|
- lib/orchestration/templates/mongoid.yml.erb
|
383
381
|
- lib/orchestration/templates/orchestration.mk.erb
|
384
382
|
- lib/orchestration/templates/puma.rb.erb
|
385
383
|
- lib/orchestration/templates/rabbitmq.yml.erb
|
386
384
|
- lib/orchestration/templates/unicorn.rb.erb
|
387
|
-
- lib/orchestration/templates/yaml.bash.erb
|
388
385
|
- lib/orchestration/terminal.rb
|
389
386
|
- lib/orchestration/version.rb
|
390
387
|
- 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
|
@@ -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)"
|