orchestration 0.5.10 → 0.6.0
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/README.md +34 -30
- data/config/locales/en.yml +11 -15
- data/lib/orchestration.rb +4 -0
- data/lib/orchestration/docker_compose/app_service.rb +7 -1
- data/lib/orchestration/docker_compose/configuration.rb +1 -1
- data/lib/orchestration/docker_compose/database_service.rb +1 -1
- data/lib/orchestration/docker_compose/install_generator.rb +4 -4
- data/lib/orchestration/docker_compose/rabbitmq_service.rb +4 -2
- data/lib/orchestration/environment.rb +1 -1
- data/lib/orchestration/errors.rb +2 -0
- data/lib/orchestration/install_generator.rb +2 -28
- data/lib/orchestration/make.rb +4 -0
- data/lib/orchestration/make/orchestration.mk +503 -0
- data/lib/orchestration/service_check.rb +24 -38
- data/lib/orchestration/services/database/adapters.rb +1 -0
- data/lib/orchestration/services/database/adapters/adapter_base.rb +21 -0
- data/lib/orchestration/services/database/adapters/mysql2.rb +4 -2
- data/lib/orchestration/services/database/adapters/postgresql.rb +2 -0
- data/lib/orchestration/services/database/adapters/sqlite3.rb +2 -0
- data/lib/orchestration/services/database/configuration.rb +17 -19
- data/lib/orchestration/services/mixins/configuration_base.rb +1 -1
- data/lib/orchestration/services/rabbitmq.rb +1 -0
- data/lib/orchestration/templates/Dockerfile.erb +2 -6
- data/lib/orchestration/templates/application.mk.erb +23 -7
- data/lib/orchestration/templates/puma.rb.erb +1 -1
- data/lib/orchestration/templates/rabbitmq.yml.erb +5 -2
- data/lib/orchestration/terminal.rb +4 -3
- data/lib/orchestration/version.rb +1 -1
- data/lib/tasks/orchestration.rake +17 -6
- data/orchestration.gemspec +6 -3
- metadata +64 -21
- data/lib/orchestration/templates/makefile_macros.mk.erb +0 -112
- data/lib/orchestration/templates/orchestration.mk.erb +0 -393
data/orchestration.gemspec
CHANGED
@@ -30,12 +30,12 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_runtime_dependency 'erubis', '~> 2.7'
|
31
31
|
spec.add_runtime_dependency 'i18n', '>= 0.5'
|
32
32
|
spec.add_runtime_dependency 'paint', '~> 2.0'
|
33
|
+
spec.add_runtime_dependency 'rails', '~> 6.0'
|
33
34
|
spec.add_runtime_dependency 'thor', '~> 1.0'
|
34
35
|
|
35
36
|
spec.add_development_dependency 'activerecord', '~> 6.0'
|
36
|
-
spec.add_development_dependency 'bundler', '~> 1.16'
|
37
37
|
spec.add_development_dependency 'bunny', '~> 2.12'
|
38
|
-
spec.add_development_dependency 'devpack', '~> 0.3.
|
38
|
+
spec.add_development_dependency 'devpack', '~> 0.3.2'
|
39
39
|
spec.add_development_dependency 'mongoid', '~> 7.0'
|
40
40
|
spec.add_development_dependency 'mysql2', '~> 0.5.2'
|
41
41
|
spec.add_development_dependency 'pg', '~> 1.1'
|
@@ -43,7 +43,10 @@ Gem::Specification.new do |spec|
|
|
43
43
|
spec.add_development_dependency 'rake', '~> 10.0'
|
44
44
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
45
45
|
spec.add_development_dependency 'rspec-its', '~> 1.2'
|
46
|
-
spec.add_development_dependency 'rubocop', '~>
|
46
|
+
spec.add_development_dependency 'rubocop', '~> 1.12'
|
47
|
+
spec.add_development_dependency 'rubocop-rails', '~> 2.9'
|
48
|
+
spec.add_development_dependency 'rubocop-rake', '~> 0.5.1'
|
49
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 2.2'
|
47
50
|
spec.add_development_dependency 'sqlite3', '~> 1.3'
|
48
51
|
spec.add_development_dependency 'strong_versions', '~> 0.4.5'
|
49
52
|
spec.add_development_dependency 'webmock', '~> 3.4'
|
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.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Farrell
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: database_url
|
@@ -67,47 +67,47 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '2.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rails
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '6.0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '6.0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: thor
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
90
|
-
type: :
|
89
|
+
version: '1.0'
|
90
|
+
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '1.0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: activerecord
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '6.0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '6.0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: bunny
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,14 +128,14 @@ dependencies:
|
|
128
128
|
requirements:
|
129
129
|
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: 0.3.
|
131
|
+
version: 0.3.2
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: 0.3.
|
138
|
+
version: 0.3.2
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: mongoid
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -240,14 +240,56 @@ dependencies:
|
|
240
240
|
requirements:
|
241
241
|
- - "~>"
|
242
242
|
- !ruby/object:Gem::Version
|
243
|
-
version:
|
243
|
+
version: '1.12'
|
244
|
+
type: :development
|
245
|
+
prerelease: false
|
246
|
+
version_requirements: !ruby/object:Gem::Requirement
|
247
|
+
requirements:
|
248
|
+
- - "~>"
|
249
|
+
- !ruby/object:Gem::Version
|
250
|
+
version: '1.12'
|
251
|
+
- !ruby/object:Gem::Dependency
|
252
|
+
name: rubocop-rails
|
253
|
+
requirement: !ruby/object:Gem::Requirement
|
254
|
+
requirements:
|
255
|
+
- - "~>"
|
256
|
+
- !ruby/object:Gem::Version
|
257
|
+
version: '2.9'
|
258
|
+
type: :development
|
259
|
+
prerelease: false
|
260
|
+
version_requirements: !ruby/object:Gem::Requirement
|
261
|
+
requirements:
|
262
|
+
- - "~>"
|
263
|
+
- !ruby/object:Gem::Version
|
264
|
+
version: '2.9'
|
265
|
+
- !ruby/object:Gem::Dependency
|
266
|
+
name: rubocop-rake
|
267
|
+
requirement: !ruby/object:Gem::Requirement
|
268
|
+
requirements:
|
269
|
+
- - "~>"
|
270
|
+
- !ruby/object:Gem::Version
|
271
|
+
version: 0.5.1
|
272
|
+
type: :development
|
273
|
+
prerelease: false
|
274
|
+
version_requirements: !ruby/object:Gem::Requirement
|
275
|
+
requirements:
|
276
|
+
- - "~>"
|
277
|
+
- !ruby/object:Gem::Version
|
278
|
+
version: 0.5.1
|
279
|
+
- !ruby/object:Gem::Dependency
|
280
|
+
name: rubocop-rspec
|
281
|
+
requirement: !ruby/object:Gem::Requirement
|
282
|
+
requirements:
|
283
|
+
- - "~>"
|
284
|
+
- !ruby/object:Gem::Version
|
285
|
+
version: '2.2'
|
244
286
|
type: :development
|
245
287
|
prerelease: false
|
246
288
|
version_requirements: !ruby/object:Gem::Requirement
|
247
289
|
requirements:
|
248
290
|
- - "~>"
|
249
291
|
- !ruby/object:Gem::Version
|
250
|
-
version:
|
292
|
+
version: '2.2'
|
251
293
|
- !ruby/object:Gem::Dependency
|
252
294
|
name: sqlite3
|
253
295
|
requirement: !ruby/object:Gem::Requirement
|
@@ -327,6 +369,8 @@ files:
|
|
327
369
|
- lib/orchestration/errors.rb
|
328
370
|
- lib/orchestration/file_helpers.rb
|
329
371
|
- lib/orchestration/install_generator.rb
|
372
|
+
- lib/orchestration/make.rb
|
373
|
+
- lib/orchestration/make/orchestration.mk
|
330
374
|
- lib/orchestration/railtie.rb
|
331
375
|
- lib/orchestration/service_check.rb
|
332
376
|
- lib/orchestration/services.rb
|
@@ -335,6 +379,7 @@ files:
|
|
335
379
|
- lib/orchestration/services/app/healthcheck.rb
|
336
380
|
- lib/orchestration/services/database.rb
|
337
381
|
- lib/orchestration/services/database/adapters.rb
|
382
|
+
- lib/orchestration/services/database/adapters/adapter_base.rb
|
338
383
|
- lib/orchestration/services/database/adapters/mysql2.rb
|
339
384
|
- lib/orchestration/services/database/adapters/postgresql.rb
|
340
385
|
- lib/orchestration/services/database/adapters/sqlite3.rb
|
@@ -358,9 +403,7 @@ files:
|
|
358
403
|
- lib/orchestration/templates/database.yml.erb
|
359
404
|
- lib/orchestration/templates/entrypoint.sh.erb
|
360
405
|
- lib/orchestration/templates/env.erb
|
361
|
-
- lib/orchestration/templates/makefile_macros.mk.erb
|
362
406
|
- lib/orchestration/templates/mongoid.yml.erb
|
363
|
-
- lib/orchestration/templates/orchestration.mk.erb
|
364
407
|
- lib/orchestration/templates/puma.rb.erb
|
365
408
|
- lib/orchestration/templates/rabbitmq.yml.erb
|
366
409
|
- lib/orchestration/templates/unicorn.rb.erb
|
@@ -371,7 +414,7 @@ files:
|
|
371
414
|
homepage: https://github.com/bobf/orchestration
|
372
415
|
licenses: []
|
373
416
|
metadata: {}
|
374
|
-
post_install_message:
|
417
|
+
post_install_message:
|
375
418
|
rdoc_options: []
|
376
419
|
require_paths:
|
377
420
|
- lib
|
@@ -387,7 +430,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
387
430
|
version: '0'
|
388
431
|
requirements: []
|
389
432
|
rubygems_version: 3.0.3
|
390
|
-
signing_key:
|
433
|
+
signing_key:
|
391
434
|
specification_version: 4
|
392
435
|
summary: Docker orchestration toolkit
|
393
436
|
test_files: []
|
@@ -1,112 +0,0 @@
|
|
1
|
-
TERM ?= 'dumb'
|
2
|
-
pwd:=$(shell pwd)
|
3
|
-
ifdef mounted_orchestration
|
4
|
-
orchestration_dir=$(mounted_orchestration)
|
5
|
-
else
|
6
|
-
orchestration_dir=${pwd}/<%= env.orchestration_dir_name %>
|
7
|
-
endif
|
8
|
-
|
9
|
-
ifdef env_file
|
10
|
-
custom_env_file ?= 1
|
11
|
-
else
|
12
|
-
custom_env_file ?= 0
|
13
|
-
endif
|
14
|
-
|
15
|
-
ifneq (,$(wildcard ${pwd}/config/database.yml))
|
16
|
-
database_enabled = 1
|
17
|
-
else
|
18
|
-
database_enabled = 0
|
19
|
-
endif
|
20
|
-
|
21
|
-
make=$(MAKE) $1
|
22
|
-
orchestration_config_filename:=.orchestration.yml
|
23
|
-
orchestration_config:=${pwd}/${orchestration_config_filename}
|
24
|
-
print_error=printf '${red}\#${reset} '$1 | tee '${stderr}'
|
25
|
-
println_error=$(call print_error,$1'\n')
|
26
|
-
print=printf '${blue}\#${reset} '$1
|
27
|
-
println=$(call print,$1'\n')
|
28
|
-
printraw=printf $1
|
29
|
-
printrawln=$(call printraw,$1'\n')
|
30
|
-
stdout=${pwd}/log/orchestration.stdout.log
|
31
|
-
stderr=${pwd}/log/orchestration.stderr.log
|
32
|
-
log_path_length=$(shell echo "${stdout}" | wc -c)
|
33
|
-
ifndef verbose
|
34
|
-
log_tee:= 2>&1 | tee -a ${stdout}
|
35
|
-
log:= >>${stdout} 2>>${stderr}
|
36
|
-
progress_point:=perl -e 'while( my $$line = <STDIN> ) { printf("."); select()->flush(); }'
|
37
|
-
log_progress:= > >(tee -ai ${stdout} >&1 | ${progress_point}) 2> >(tee -ai ${stderr} 2>&1 | ${progress_point})
|
38
|
-
endif
|
39
|
-
red:=$(shell tput setaf 1)
|
40
|
-
green:=$(shell tput setaf 2)
|
41
|
-
yellow:=$(shell tput setaf 3)
|
42
|
-
blue:=$(shell tput setaf 4)
|
43
|
-
magenta:=$(shell tput setaf 5)
|
44
|
-
cyan:=$(shell tput setaf 6)
|
45
|
-
gray:=$(shell tput setaf 7)
|
46
|
-
reset:=$(shell tput sgr0)
|
47
|
-
tick=[${green}✓${reset}]
|
48
|
-
cross=[${red}✘${reset}]
|
49
|
-
warn=[${yellow}!${reset}]
|
50
|
-
hr=$(call println,"$1$(shell head -c ${log_path_length} < /dev/zero | tr '\0' '=')${reset}")
|
51
|
-
managed_env_tag:=\# -|- ORCHESTRATION
|
52
|
-
standard_env_path:=${pwd}/.env
|
53
|
-
backup_env_path:=${pwd}/.env.orchestration.backup
|
54
|
-
is_managed_env:=$$(test -f '${standard_env_path}' && tail -n 1 '${standard_env_path}') == "${managed_env_tag}"*
|
55
|
-
token:=$(shell cat /dev/urandom | LC_CTYPE=C tr -dc 'a-z0-9' | fold -w8 | head -n1)
|
56
|
-
back_up_env:=( \
|
57
|
-
[ ! -f '${standard_env_path}' ] \
|
58
|
-
|| \
|
59
|
-
( \
|
60
|
-
[ -f '${standard_env_path}' ] \
|
61
|
-
&& cp '${standard_env_path}' '${backup_env_path}' \
|
62
|
-
) \
|
63
|
-
)
|
64
|
-
|
65
|
-
replace_env:=( \
|
66
|
-
( [ "${custom_env_file}" == "0" ] ) \
|
67
|
-
|| \
|
68
|
-
( \
|
69
|
-
[ "${custom_env_file}" == "1" ] \
|
70
|
-
&& ${back_up_env} \
|
71
|
-
&& cp ${env_file} '${standard_env_path}' \
|
72
|
-
&& $(call printraw,'\n${managed_env_tag}') >> '${standard_env_path}' \
|
73
|
-
) \
|
74
|
-
)
|
75
|
-
|
76
|
-
restore_env:=( \
|
77
|
-
( \
|
78
|
-
[[ ! ${is_managed_env} ]] \
|
79
|
-
|| [ ! -f '${backup_env_path}' ] \
|
80
|
-
) \
|
81
|
-
|| \
|
82
|
-
( \
|
83
|
-
[ -f '${backup_env_path}' ] \
|
84
|
-
&& [[ ${is_managed_env} ]] \
|
85
|
-
&& mv '${backup_env_path}' '${standard_env_path}' \
|
86
|
-
) \
|
87
|
-
)
|
88
|
-
|
89
|
-
key_chars:=[a-zA-Z0-9_]
|
90
|
-
censored:=**********
|
91
|
-
censor=s/\(^${key_chars}*$(1)${key_chars}*\)=\(.*\)$$/\1=${censored}/
|
92
|
-
censor_urls:=s|\([a-zA-Z0-9_+]\+://.*:\).*\(@.*\)$$|\1${censored}\2|
|
93
|
-
format_env:=sed '$(call censor,SECRET); \
|
94
|
-
$(call censor,TOKEN); \
|
95
|
-
$(call censor,PRIVATE); \
|
96
|
-
$(call censor,KEY); \
|
97
|
-
$(censor_urls); \
|
98
|
-
/^\s*$$/d; \
|
99
|
-
/^\s*\#/d; \
|
100
|
-
s/\(^[a-zA-Z0-9_]\+\)=/${blue}\1${reset}=/; \
|
101
|
-
s/^/ /; \
|
102
|
-
s/=\(.*\)$$/=${yellow}\1${reset}/' | \
|
103
|
-
sort
|
104
|
-
|
105
|
-
fail=( \
|
106
|
-
$(call printraw,' ${cross}') ; \
|
107
|
-
${restore_env} ; \
|
108
|
-
$(call make,dump) ; \
|
109
|
-
echo ; \
|
110
|
-
$(call println,'Failed. ${cross}') ; \
|
111
|
-
exit 1 \
|
112
|
-
)
|
@@ -1,393 +0,0 @@
|
|
1
|
-
### Environment setup ###
|
2
|
-
SHELL:=/bin/bash
|
3
|
-
|
4
|
-
<%= macros %>
|
5
|
-
|
6
|
-
ifdef env_file
|
7
|
-
-include ${env_file}
|
8
|
-
else
|
9
|
-
ifneq (${env},test)
|
10
|
-
ifeq (,$(findstring test,$(MAKECMDGOALS)))
|
11
|
-
-include .env
|
12
|
-
endif
|
13
|
-
endif
|
14
|
-
endif
|
15
|
-
|
16
|
-
export
|
17
|
-
|
18
|
-
ifneq (,$(env))
|
19
|
-
# `env` set by current shell.
|
20
|
-
else ifneq (,$(RAILS_ENV))
|
21
|
-
env=$(RAILS_ENV)
|
22
|
-
else ifneq (,$(RACK_ENV))
|
23
|
-
env=$(RACK_ENV)
|
24
|
-
else
|
25
|
-
env=development
|
26
|
-
endif
|
27
|
-
|
28
|
-
DOCKER_TAG ?= latest
|
29
|
-
|
30
|
-
ifneq (,$(wildcard ./Gemfile))
|
31
|
-
rake=RACK_ENV=${env} RAILS_ENV=${env} bundle exec rake
|
32
|
-
else
|
33
|
-
rake=RACK_ENV=${env} RAILS_ENV=${env} rake
|
34
|
-
endif
|
35
|
-
|
36
|
-
ifneq (,$(wildcard ${env_file}))
|
37
|
-
rake_cmd:=${rake}
|
38
|
-
rake=. ${env_file} && ${rake_cmd}
|
39
|
-
endif
|
40
|
-
|
41
|
-
ifeq (,$(findstring serve,$(MAKECMDGOALS)))
|
42
|
-
ifeq (,$(findstring console,$(MAKECMDGOALS)))
|
43
|
-
ifeq (,$(findstring test,$(MAKECMDGOALS)))
|
44
|
-
docker_config:=$(shell RAILS_ENV=development bundle exec rake orchestration:config)
|
45
|
-
docker_organization=$(word 1,$(docker_config))
|
46
|
-
docker_repository=$(word 2,$(docker_config))
|
47
|
-
endif
|
48
|
-
endif
|
49
|
-
endif
|
50
|
-
|
51
|
-
ifeq (,$(project_name))
|
52
|
-
project_base = ${docker_repository}_${env}
|
53
|
-
else
|
54
|
-
project_base := $(project_name)
|
55
|
-
endif
|
56
|
-
|
57
|
-
ifeq (,$(findstring deploy,$(MAKECMDGOALS)))
|
58
|
-
sidecar_suffix := $(shell test -f ${orchestration_dir}/.sidecar && cat ${orchestration_dir}/.sidecar)
|
59
|
-
ifneq (,${sidecar_suffix})
|
60
|
-
sidecar := 1
|
61
|
-
endif
|
62
|
-
|
63
|
-
ifdef sidecar
|
64
|
-
# Set the variable to an empty string so that "#{sidecar-1234}" will
|
65
|
-
# evaluate to "1234" in port mappings.
|
66
|
-
sidecar_compose = sidecar=''
|
67
|
-
ifeq (,${sidecar_suffix})
|
68
|
-
sidecar_suffix := $(call token)
|
69
|
-
_ignore := $(shell echo ${sidecar_suffix} > ${orchestration_dir}/.sidecar)
|
70
|
-
endif
|
71
|
-
|
72
|
-
ifeq (,${sidecar_suffix})
|
73
|
-
$(warning Unable to generate project suffix; project name collisions may occur.)
|
74
|
-
endif
|
75
|
-
compose_project_name = ${project_base}_${sidecar_suffix}
|
76
|
-
else
|
77
|
-
compose_project_name = ${project_base}
|
78
|
-
endif
|
79
|
-
else
|
80
|
-
compose_project_name = ${project_base}
|
81
|
-
endif
|
82
|
-
|
83
|
-
compose_base=env -i \
|
84
|
-
PATH=$(PATH) \
|
85
|
-
HOST_UID=$(shell id -u) \
|
86
|
-
DOCKER_ORGANIZATION="${docker_organization}" \
|
87
|
-
DOCKER_REPOSITORY="${docker_repository}" \
|
88
|
-
COMPOSE_PROJECT_NAME="${compose_project_name}" \
|
89
|
-
${sidecar_compose} \
|
90
|
-
docker-compose \
|
91
|
-
-f ${orchestration_dir}/docker-compose.${env}.yml
|
92
|
-
|
93
|
-
git_branch ?= $(if $(branch),$(branch),$(shell git rev-parse --abbrev-ref HEAD))
|
94
|
-
ifndef dev
|
95
|
-
git_version ?= $(shell git rev-parse --short --verify ${git_branch})
|
96
|
-
else
|
97
|
-
git_version = dev
|
98
|
-
endif
|
99
|
-
|
100
|
-
docker_image=${docker_organization}/${docker_repository}:${git_version}
|
101
|
-
|
102
|
-
compose=${compose_base}
|
103
|
-
random_str=cat /dev/urandom | LC_ALL=C tr -dc 'a-z' | head -c $1
|
104
|
-
|
105
|
-
ifneq (,$(wildcard ${orchestration_dir}/docker-compose.local.yml))
|
106
|
-
compose:=${compose} -f ${orchestration_dir}/docker-compose.local.yml
|
107
|
-
endif
|
108
|
-
|
109
|
-
all: build
|
110
|
-
|
111
|
-
### Container management commands ###
|
112
|
-
|
113
|
-
.PHONY: start
|
114
|
-
ifndef network
|
115
|
-
start: network := ${compose_project_name}
|
116
|
-
endif
|
117
|
-
start: _create-log-directory _clean-logs
|
118
|
-
@$(call print,'${yellow}Starting ${cyan}${env}${yellow} containers${reset} ...')
|
119
|
-
ifeq (${env},$(filter ${env},test development))
|
120
|
-
@${compose} up --detach --force-recreate --renew-anon-volumes --remove-orphans ${services} ${log} || ${fail}
|
121
|
-
@[ -n '${sidecar}' ] && \
|
122
|
-
( \
|
123
|
-
$(call printraw,' ${yellow}(joining dependency network ${green}${network}${yellow})${reset} ... ') ; \
|
124
|
-
docker network connect '${network}' '$(shell hostname)' ${log} \
|
125
|
-
|| ( \
|
126
|
-
$(call println,'') ; \
|
127
|
-
$(call println,'${yellow}Warning${reset}: Unable to join network: "${yellow}${network}${reset}". Container will not be able to connect to dependency services.') ; \
|
128
|
-
$(call print,'You may need to delete "${yellow}orchestration/.sidecar${reset}" to disable sidecar mode if this file was added by mistake.\n...') ; \
|
129
|
-
) \
|
130
|
-
) \
|
131
|
-
|| ( [ -z '${sidecar}' ] || ${fail} )
|
132
|
-
else
|
133
|
-
@${compose} up --detach --scale app=$${instances:-1} ${log} || ${fail}
|
134
|
-
endif
|
135
|
-
@$(call printrawln,' ${green}started${reset} ${tick}')
|
136
|
-
@$(call println,'${yellow}Waiting for services to become available${reset} ...')
|
137
|
-
@$(call make,wait) 2>${stderr} || ${fail}
|
138
|
-
|
139
|
-
<% services.each do |service| %>
|
140
|
-
.PHONY: start-<%= service %>
|
141
|
-
start-<%= service %>:
|
142
|
-
@$(call make,start services='<%= service %>')
|
143
|
-
|
144
|
-
<% end %>
|
145
|
-
|
146
|
-
.PHONY: stop
|
147
|
-
stop: network := ${compose_project_name}_default
|
148
|
-
stop:
|
149
|
-
@$(call print,'${yellow}Stopping ${cyan}${env}${yellow} containers${reset} ...')
|
150
|
-
@if docker ps --format "{{.ID}}" | grep -q $(shell hostname) ; \
|
151
|
-
then \
|
152
|
-
( docker network disconnect ${network} $(shell hostname) ${log} || : ) \
|
153
|
-
&& \
|
154
|
-
( ${compose} down ${log} || ${fail} ) ; \
|
155
|
-
else \
|
156
|
-
${compose} down ${log} || ${fail} ; \
|
157
|
-
fi
|
158
|
-
@$(call printrawln,' ${green}stopped${reset}. ${tick}')
|
159
|
-
|
160
|
-
.PHONY: logs
|
161
|
-
logs:
|
162
|
-
@${compose} logs -f
|
163
|
-
|
164
|
-
.PHONY: config
|
165
|
-
config:
|
166
|
-
@${compose} config
|
167
|
-
|
168
|
-
.PHONY: compose
|
169
|
-
compose:
|
170
|
-
@echo ${compose}
|
171
|
-
|
172
|
-
### Development/Test Utility Commands
|
173
|
-
|
174
|
-
.PHONY: serve
|
175
|
-
serve: env_file ?= ./.env
|
176
|
-
serve: rails = RAILS_ENV='${env}' bundle exec rails server ${server}
|
177
|
-
serve:
|
178
|
-
@if [ -f "${env_file}" ] ; \
|
179
|
-
then ( \
|
180
|
-
$(call println,'${yellow}Environment${reset}: ${green}${env_file}${reset}') && \
|
181
|
-
cat '${env_file}' | ${format_env} && \
|
182
|
-
$(call printrawln,'') \
|
183
|
-
) ; \
|
184
|
-
fi
|
185
|
-
${rails}
|
186
|
-
|
187
|
-
.PHONY: console
|
188
|
-
console: env_file ?= ./.env
|
189
|
-
console: rails = RAILS_ENV='${env}' bundle exec rails
|
190
|
-
console:
|
191
|
-
@if [ -f "${env_file}" ] ; \
|
192
|
-
then ( \
|
193
|
-
$(call println,'${yellow}Environment${reset}: ${green}${env_file}${reset}') && \
|
194
|
-
cat '${env_file}' | ${format_env} && \
|
195
|
-
$(call printrawln,'') \
|
196
|
-
) ; \
|
197
|
-
fi
|
198
|
-
${rails} console
|
199
|
-
|
200
|
-
.PHONY: test-setup
|
201
|
-
test-setup: env := test
|
202
|
-
test-setup:
|
203
|
-
ifndef light
|
204
|
-
@$(call make,start env=test)
|
205
|
-
ifneq (,$(wildcard config/database.yml))
|
206
|
-
${rake} db:create || :
|
207
|
-
ifneq (,$(wildcard db/structure.sql))
|
208
|
-
${rake} db:structure:load
|
209
|
-
else ifneq (,$(wildcard db/schema.rb))
|
210
|
-
${rake} db:schema:load
|
211
|
-
endif
|
212
|
-
|
213
|
-
${rake} db:migrate
|
214
|
-
endif
|
215
|
-
endif
|
216
|
-
|
217
|
-
.PHONY: dump
|
218
|
-
dump:
|
219
|
-
ifndef verbose
|
220
|
-
@$(call println)
|
221
|
-
@$(call println,'${yellow}Captured${reset} ${green}stdout${reset} ${yellow}and${reset} ${red}stderr${reset} ${yellow}log data [${cyan}${env}${yellow}]${reset}:')
|
222
|
-
@$(call println)
|
223
|
-
@echo
|
224
|
-
@test -f '${stdout}' && ( \
|
225
|
-
$(call hr,${green}) ; \
|
226
|
-
$(call println,'${gray}${stdout}${reset}') ; \
|
227
|
-
$(call hr,${green}) ; \
|
228
|
-
echo ; cat '${stdout}' ; echo ; \
|
229
|
-
$(call hr,${green}) ; \
|
230
|
-
)
|
231
|
-
|
232
|
-
@test -f '${stdout}' && ( \
|
233
|
-
echo ; \
|
234
|
-
$(call hr,${red}) ; \
|
235
|
-
$(call println,'${gray}${stderr}${reset}') ; \
|
236
|
-
$(call hr,${red}) ; \
|
237
|
-
echo ; cat '${stderr}' ; echo ; \
|
238
|
-
$(call hr,${red}) ; \
|
239
|
-
)
|
240
|
-
endif
|
241
|
-
ifneq (,$(findstring deploy,$(MAKECMDGOALS)))
|
242
|
-
@echo ; \
|
243
|
-
$(call hr,${yellow}) ; \
|
244
|
-
$(call println,'${gray}docker-compose logs${reset}') ; \
|
245
|
-
$(call hr,${yellow}) ; \
|
246
|
-
echo
|
247
|
-
@${compose} logs
|
248
|
-
@echo ; \
|
249
|
-
$(call hr,${yellow})
|
250
|
-
endif
|
251
|
-
@$(NOOP)
|
252
|
-
|
253
|
-
.PHONY: image
|
254
|
-
image:
|
255
|
-
@echo ${docker_image}
|
256
|
-
|
257
|
-
### Deployment utility commands ###
|
258
|
-
|
259
|
-
.PHONY: deploy
|
260
|
-
ifdef env_file
|
261
|
-
deploy: env_file_option = --env-file ${env_file}
|
262
|
-
endif
|
263
|
-
deploy: RAILS_ENV := ${env}
|
264
|
-
deploy: RACK_ENV := ${env}
|
265
|
-
deploy: DOCKER_TAG = ${git_version}
|
266
|
-
deploy: base_vars = DOCKER_ORGANIZATION=${docker_organization} DOCKER_REPOSITORY=${docker_repository} DOCKER_TAG=${git_version}
|
267
|
-
deploy: compose_deploy := ${base_vars} COMPOSE_PROJECT_NAME=${project_base} HOST_UID=$(shell id -u) docker-compose ${env_file_option} --project-name ${project_base} -f orchestration/docker-compose.production.yml
|
268
|
-
deploy: compose_config := ${compose_deploy} config
|
269
|
-
deploy: deploy_cmd := echo "$${config}" | ssh "${manager}" "/bin/bash -lc 'cat | docker stack deploy --prune --with-registry-auth -c - ${project_base}'"
|
270
|
-
deploy: out_of_sequence_error := rpc error: code = Unknown desc = update out of sequence
|
271
|
-
deploy: retry_message := ${yellow}Detected Docker RPC error: ${red}${out_of_sequence_error}${yellow}. Retrying in
|
272
|
-
deploy:
|
273
|
-
ifndef manager
|
274
|
-
@$(call println_error,'Missing `manager` parameter: `make deploy manager=swarm-manager.example.com`') ; exit 1
|
275
|
-
endif
|
276
|
-
@$(call println,'${yellow}Deploying ${green}${env} ${yellow}stack via ${green}${manager} ${yellow}as ${green}${project_base}${reset} ...') && \
|
277
|
-
( \
|
278
|
-
$(call println,'${yellow}Deployment environment${reset}:') && \
|
279
|
-
( test -f '${env_file}' && cat '${env_file}' | ${format_env} || : ) && \
|
280
|
-
$(call println,'') && \
|
281
|
-
$(call println,'${yellow}Application image${reset}: ${cyan}${docker_image}${reset}') && \
|
282
|
-
export config="$$(${compose_config} 2>${stderr})" ; \
|
283
|
-
config_exit_code=$$? ; \
|
284
|
-
if [[ "$${config_exit_code}" != "0" ]]; then exit ${config_exit_code}; fi ; \
|
285
|
-
output="$$(${deploy_cmd} | tee)" ; \
|
286
|
-
deploy_exit_code=$$? ; \
|
287
|
-
if [[ "$${deploy_exit_code}" == 0 ]] ; then exit 0 ; fi ; \
|
288
|
-
if ! echo "$${output}" | grep -q '${out_of_sequence_error}' ; then exit ${deploy_exit_code} ; fi ; \
|
289
|
-
retry_in="$$(( 10 + RANDOM % 50 ))" ; \
|
290
|
-
echo "${retry_message} ${green}$${retry_in} ${yellow}seconds.${reset}" ; \
|
291
|
-
sleep "$${retry_in}" ; \
|
292
|
-
${deploy_cmd} \
|
293
|
-
) \
|
294
|
-
|| ${fail}
|
295
|
-
|
296
|
-
@$(call println,'${yellow}Deployment${reset} ${green}complete${reset}. ${tick}')
|
297
|
-
|
298
|
-
.PHONY: rollback
|
299
|
-
ifndef service
|
300
|
-
rollback: service = app
|
301
|
-
endif
|
302
|
-
rollback:
|
303
|
-
ifndef manager
|
304
|
-
@$(call println_error,'Missing `manager` parameter: `make deploy manager=swarm-manager.example.com`') ; exit 1
|
305
|
-
endif
|
306
|
-
@$(call println,'${yellow}Rolling back${reset} ${green}${compose_project_name}_${service}${reset} ${yellow}via${reset} ${green}${manager}${reset} ...')
|
307
|
-
@ssh "${manager}" 'docker service rollback --detach "${compose_project_name}_${service}"' ${log} || ${fail}
|
308
|
-
@$(call println,'${yellow}Rollback request${reset} ${green}complete${reset}. ${tick}')
|
309
|
-
|
310
|
-
### Service healthcheck commands ###
|
311
|
-
|
312
|
-
.PHONY: wait
|
313
|
-
wait:
|
314
|
-
@${rake} orchestration:wait
|
315
|
-
@$(call println,'${yellow}All services${reset} ${green}ready${reset}. ${tick}')
|
316
|
-
|
317
|
-
## Generic Listener healthcheck for TCP services ##
|
318
|
-
|
319
|
-
wait-listener:
|
320
|
-
@${rake} orchestration:listener:wait service=${service} sidecar=${sidecar}
|
321
|
-
|
322
|
-
### Docker build commands ###
|
323
|
-
|
324
|
-
.PHONY: build
|
325
|
-
build: build_dir = ${orchestration_dir}/.build
|
326
|
-
build: context = ${build_dir}/context.tar
|
327
|
-
build: _create-log-directory check-local-changes
|
328
|
-
@$(call print,'${yellow}Preparing build context from${reset} ${cyan}${git_branch}:${git_version}${reset} ... ')
|
329
|
-
@mkdir -p ${orchestration_dir}/.build ${log} || ${fail}
|
330
|
-
ifndef dev
|
331
|
-
@git show ${git_branch}:./Gemfile > ${orchestration_dir}/.build/Gemfile 2>${stderr} || ${fail}
|
332
|
-
@git show ${git_branch}:./Gemfile.lock > ${orchestration_dir}/.build/Gemfile.lock 2>${stderr} || ${fail}
|
333
|
-
<% if defined?(Webpacker) %> @git show ${git_branch}:./package.json > ${orchestration_dir}/.build/package.json 2>${stderr} || ${fail}<% end %>
|
334
|
-
<% if defined?(Webpacker) %> @git show ${git_branch}:./yarn.lock > ${orchestration_dir}/.build/yarn.lock 2>${stderr} || ${fail}<% end %>
|
335
|
-
@git archive --format 'tar' -o '${context}' '${git_branch}' ${log} || ${fail}
|
336
|
-
else
|
337
|
-
@tar -cvf '${context}' . ${log} || ${fail}
|
338
|
-
endif
|
339
|
-
@$(call printrawln,'${green}complete.${reset} ${tick}')
|
340
|
-
ifdef include
|
341
|
-
@$(call print,'${yellow}Including files from:${reset} ${cyan}${include}${reset} ...')
|
342
|
-
@(while read line; do \
|
343
|
-
export line; \
|
344
|
-
include_dir="${build_dir}/$$(dirname "$${line}")/" && \
|
345
|
-
mkdir -p "$${include_dir}" && cp "$${line}" "$${include_dir}" \
|
346
|
-
&& (cd '${orchestration_dir}/.build/' && tar rf 'context.tar' "$${line}"); \
|
347
|
-
done < '${include}') ${log} || ${fail}
|
348
|
-
@$(call printrawln,' ${green}complete.${reset} ${tick}')
|
349
|
-
endif
|
350
|
-
ifdef sidecar
|
351
|
-
# Assume we are in a line-buffered environment (e.g. Jenkins)
|
352
|
-
@$(call println,'${yellow}Building image${reset} ...')
|
353
|
-
else
|
354
|
-
@$(call print,'${yellow}Building image${reset} ...')
|
355
|
-
endif
|
356
|
-
@docker build \
|
357
|
-
--build-arg BUNDLE_GITHUB__COM \
|
358
|
-
--build-arg BUNDLE_BITBUCKET__ORG \
|
359
|
-
--build-arg GIT_COMMIT='${git_version}' \
|
360
|
-
-t ${docker_organization}/${docker_repository} \
|
361
|
-
-t ${docker_organization}/${docker_repository}:${git_version} \
|
362
|
-
${orchestration_dir}/ ${log_progress} || ${fail}
|
363
|
-
@$(call printrawln,' ${green}complete${reset}. ${tick}')
|
364
|
-
@$(call println,'[${green}tag${reset}] ${cyan}${docker_organization}/${docker_repository}${reset}')
|
365
|
-
@$(call println,'[${green}tag${reset}] ${cyan}${docker_organization}/${docker_repository}:${git_version}${reset}')
|
366
|
-
|
367
|
-
.PHONY: push
|
368
|
-
push: _create-log-directory
|
369
|
-
@$(call print,'${yellow}Pushing${reset} ${cyan}${docker_image}${reset} ...')
|
370
|
-
@docker push ${docker_image} ${log_progress} || ${fail}
|
371
|
-
@$(call printrawln,' ${green}complete${reset}. ${tick}')
|
372
|
-
|
373
|
-
.PHONY: check-local-changes
|
374
|
-
check-local-changes:
|
375
|
-
ifndef dev
|
376
|
-
@if [[ ! -z "$$(git status --porcelain)" ]] ; \
|
377
|
-
then \
|
378
|
-
$(call println,'${red}You have uncommitted changes which will not be included in your build:${reset}') ; \
|
379
|
-
git status --porcelain ; \
|
380
|
-
$(call println,'${yellow}Use ${cyan}make build dev=1${reset} ${yellow}to include these files.${reset}\n') ; \
|
381
|
-
fi
|
382
|
-
endif
|
383
|
-
|
384
|
-
### Internal Commands ###
|
385
|
-
#
|
386
|
-
.PHONY: _clean-logs
|
387
|
-
_clean-logs:
|
388
|
-
@rm -f '${stdout}' '${stderr}'
|
389
|
-
@touch '${stdout}' '${stderr}'
|
390
|
-
|
391
|
-
.PHONY: _create-log-directory
|
392
|
-
_create-log-directory:
|
393
|
-
@mkdir -p log
|