interactive_record 0.0.1alpha

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.
Files changed (103) hide show
  1. checksums.yaml +7 -0
  2. data/.browserslistrc +1 -0
  3. data/.gitattributes +10 -0
  4. data/.gitignore +31 -0
  5. data/.orchestration.yml +4 -0
  6. data/.rspec +3 -0
  7. data/.rubocop.yml +6 -0
  8. data/.ruby-version +1 -0
  9. data/Gemfile +40 -0
  10. data/Gemfile.lock +287 -0
  11. data/LICENSE.txt +21 -0
  12. data/Makefile +27 -0
  13. data/README.md +39 -0
  14. data/Rakefile +8 -0
  15. data/app/assets/config/manifest.js +2 -0
  16. data/app/assets/images/.keep +0 -0
  17. data/app/assets/stylesheets/application.css +15 -0
  18. data/app/channels/application_cable/channel.rb +6 -0
  19. data/app/channels/application_cable/connection.rb +6 -0
  20. data/app/controllers/application_controller.rb +4 -0
  21. data/app/controllers/concerns/.keep +0 -0
  22. data/app/helpers/application_helper.rb +5 -0
  23. data/app/javascript/channels/consumer.js +6 -0
  24. data/app/javascript/channels/index.js +5 -0
  25. data/app/javascript/packs/application.js +13 -0
  26. data/app/javascript/packs/hello_react.jsx +26 -0
  27. data/app/jobs/application_job.rb +9 -0
  28. data/app/mailers/application_mailer.rb +6 -0
  29. data/app/models/application_record.rb +6 -0
  30. data/app/models/concerns/.keep +0 -0
  31. data/app/views/layouts/application.html.erb +16 -0
  32. data/app/views/layouts/mailer.html.erb +13 -0
  33. data/app/views/layouts/mailer.text.erb +1 -0
  34. data/babel.config.js +87 -0
  35. data/bin/bundle +118 -0
  36. data/bin/console +15 -0
  37. data/bin/rails +7 -0
  38. data/bin/rake +7 -0
  39. data/bin/setup +38 -0
  40. data/bin/spring +16 -0
  41. data/bin/webpack +19 -0
  42. data/bin/webpack-dev-server +19 -0
  43. data/bin/yarn +19 -0
  44. data/config.ru +8 -0
  45. data/config/application.rb +24 -0
  46. data/config/boot.rb +6 -0
  47. data/config/cable.yml +10 -0
  48. data/config/credentials.yml.enc +1 -0
  49. data/config/database.yml +25 -0
  50. data/config/environment.rb +7 -0
  51. data/config/environments/development.rb +70 -0
  52. data/config/environments/production.rb +116 -0
  53. data/config/environments/test.rb +62 -0
  54. data/config/initializers/application_controller_renderer.rb +9 -0
  55. data/config/initializers/backtrace_silencers.rb +10 -0
  56. data/config/initializers/content_security_policy.rb +31 -0
  57. data/config/initializers/cookies_serializer.rb +7 -0
  58. data/config/initializers/filter_parameter_logging.rb +8 -0
  59. data/config/initializers/inflections.rb +17 -0
  60. data/config/initializers/mime_types.rb +5 -0
  61. data/config/initializers/permissions_policy.rb +12 -0
  62. data/config/initializers/wrap_parameters.rb +16 -0
  63. data/config/locales/en.yml +33 -0
  64. data/config/puma.rb +45 -0
  65. data/config/routes.rb +5 -0
  66. data/config/spring.rb +8 -0
  67. data/config/storage.yml +34 -0
  68. data/config/unicorn.rb +19 -0
  69. data/config/webpack/development.js +5 -0
  70. data/config/webpack/environment.js +3 -0
  71. data/config/webpack/production.js +5 -0
  72. data/config/webpack/test.js +5 -0
  73. data/config/webpacker.yml +93 -0
  74. data/db/schema.rb +15 -0
  75. data/db/seeds.rb +8 -0
  76. data/interactive_record.gemspec +31 -0
  77. data/lib/assets/.keep +0 -0
  78. data/lib/interactive_record.rb +8 -0
  79. data/lib/interactive_record/version.rb +5 -0
  80. data/lib/tasks/.keep +0 -0
  81. data/log/.keep +0 -0
  82. data/orchestration/Dockerfile +32 -0
  83. data/orchestration/Makefile +508 -0
  84. data/orchestration/deploy.mk +69 -0
  85. data/orchestration/docker-compose.development.yml +4 -0
  86. data/orchestration/docker-compose.production.yml +28 -0
  87. data/orchestration/docker-compose.test.yml +4 -0
  88. data/orchestration/entrypoint.sh +17 -0
  89. data/package.json +20 -0
  90. data/postcss.config.js +12 -0
  91. data/public/404.html +67 -0
  92. data/public/422.html +67 -0
  93. data/public/500.html +66 -0
  94. data/public/apple-touch-icon-precomposed.png +0 -0
  95. data/public/apple-touch-icon.png +0 -0
  96. data/public/favicon.ico +0 -0
  97. data/public/robots.txt +1 -0
  98. data/storage/.keep +0 -0
  99. data/tmp/.keep +0 -0
  100. data/tmp/pids/.keep +0 -0
  101. data/vendor/.keep +0 -0
  102. data/yarn.lock +7785 -0
  103. metadata +147 -0
data/lib/assets/.keep ADDED
File without changes
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'interactive_record/version'
4
+
5
+ module InteractiveRecord
6
+ class Error < StandardError; end
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InteractiveRecord
4
+ VERSION = '0.0.1alpha'
5
+ end
data/lib/tasks/.keep ADDED
File without changes
data/log/.keep ADDED
File without changes
@@ -0,0 +1,32 @@
1
+ FROM ruby:3.0.0
2
+ ARG BUNDLE_BITBUCKET__ORG
3
+ ARG BUNDLE_GITHUB__COM
4
+ ARG GIT_COMMIT
5
+ RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \
6
+ && apt-get update \
7
+ && DEBIAN_FRONTEND=noninteractive apt-get install -y \
8
+ nodejs \
9
+ gosu \
10
+ sendmail \
11
+ && rm -rf /var/lib/apt/lists/* \
12
+ && gem install bundler \
13
+ && mkdir /app \
14
+ && curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash \
15
+ && . /root/.bashrc \
16
+ && nvm install 10.11.0 \
17
+ && npm install -g yarn
18
+ WORKDIR /app
19
+ COPY .build/Gemfile .build/Gemfile.lock ./
20
+ RUN bundle install --without development test --deployment
21
+ COPY .build/package.json .build/yarn.lock ./
22
+ RUN . /root/.bashrc ; yarn install
23
+ ADD .build/context.tar .
24
+ 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
25
+ RUN echo "${GIT_COMMIT}" > /app/GIT_COMMIT
26
+ HEALTHCHECK --interval=30s \
27
+ --timeout=30s \
28
+ --start-period=5s \
29
+ --retries=3 \
30
+ CMD ["bundle","exec","rake","orchestration:healthcheck"]
31
+ ENTRYPOINT ["/app/orchestration/entrypoint.sh"]
32
+ CMD ["bundle","exec","unicorn","-c","config/unicorn.rb"]
@@ -0,0 +1,508 @@
1
+ ### Environment setup ###
2
+ SHELL:=/bin/bash
3
+
4
+ TERM ?= 'dumb'
5
+ pwd:=$(shell pwd)
6
+ ifdef mounted_orchestration
7
+ orchestration_dir=$(mounted_orchestration)
8
+ else
9
+ orchestration_dir=${pwd}/orchestration
10
+ endif
11
+
12
+ ifdef env_file
13
+ custom_env_file ?= 1
14
+ else
15
+ custom_env_file ?= 0
16
+ endif
17
+
18
+ ifneq (,$(wildcard ${pwd}/config/database.yml))
19
+ database_enabled = 1
20
+ else
21
+ database_enabled = 0
22
+ endif
23
+
24
+ make=$(MAKE) $1
25
+ orchestration_config_filename:=.orchestration.yml
26
+ orchestration_config:=${pwd}/${orchestration_config_filename}
27
+ print_error=printf '${red}\#${reset} '$1 | tee '${stderr}'
28
+ println_error=$(call print_error,$1'\n')
29
+ print=printf '${blue}\#${reset} '$1
30
+ println=$(call print,$1'\n')
31
+ printraw=printf $1
32
+ printrawln=$(call printraw,$1'\n')
33
+ stdout=${pwd}/log/orchestration.stdout.log
34
+ stderr=${pwd}/log/orchestration.stderr.log
35
+ log_path_length=$(shell echo "${stdout}" | wc -c)
36
+ ifndef verbose
37
+ log:= >>${stdout} 2>>${stderr}
38
+ progress_point:=perl -e 'while( my $$line = <STDIN> ) { printf("."); select()->flush(); }'
39
+ log_progress:= > >(tee -ai ${stdout} >&1 | ${progress_point}) 2> >(tee -ai ${stderr} 2>&1 | ${progress_point})
40
+ endif
41
+ red:=$(shell tput setaf 1)
42
+ green:=$(shell tput setaf 2)
43
+ yellow:=$(shell tput setaf 3)
44
+ blue:=$(shell tput setaf 4)
45
+ magenta:=$(shell tput setaf 5)
46
+ cyan:=$(shell tput setaf 6)
47
+ gray:=$(shell tput setaf 7)
48
+ reset:=$(shell tput sgr0)
49
+ tick=[${green}✓${reset}]
50
+ cross=[${red}✘${reset}]
51
+ warn=[${yellow}!${reset}]
52
+ hr=$(call println,"$1$(shell head -c ${log_path_length} < /dev/zero | tr '\0' '=')${reset}")
53
+ managed_env_tag:=\# -|- ORCHESTRATION
54
+ standard_env_path:=${pwd}/.env
55
+ backup_env_path:=${pwd}/.env.orchestration.backup
56
+ is_managed_env:=$$(test -f '${standard_env_path}' && tail -n 1 '${standard_env_path}') == "${managed_env_tag}"*
57
+ token:=$(shell cat /dev/urandom | LC_CTYPE=C tr -dc 'a-z0-9' | fold -w8 | head -n1)
58
+ back_up_env:=( \
59
+ [ ! -f '${standard_env_path}' ] \
60
+ || \
61
+ ( \
62
+ [ -f '${standard_env_path}' ] \
63
+ && cp '${standard_env_path}' '${backup_env_path}' \
64
+ ) \
65
+ )
66
+
67
+ replace_env:=( \
68
+ ( [ "${custom_env_file}" == "0" ] ) \
69
+ || \
70
+ ( \
71
+ [ "${custom_env_file}" == "1" ] \
72
+ && ${back_up_env} \
73
+ && cp ${env_file} '${standard_env_path}' \
74
+ && $(call printraw,'\n${managed_env_tag}') >> '${standard_env_path}' \
75
+ ) \
76
+ )
77
+
78
+ restore_env:=( \
79
+ ( \
80
+ [[ ! ${is_managed_env} ]] \
81
+ || [ ! -f '${backup_env_path}' ] \
82
+ ) \
83
+ || \
84
+ ( \
85
+ [ -f '${backup_env_path}' ] \
86
+ && [[ ${is_managed_env} ]] \
87
+ && mv '${backup_env_path}' '${standard_env_path}' \
88
+ ) \
89
+ )
90
+
91
+ key_chars:=[a-zA-Z0-9_]
92
+ censored:=**********
93
+ censor=s/\(^${key_chars}*$(1)${key_chars}*\)=\(.*\)$$/\1=${censored}/
94
+ censor_urls:=s|\([a-zA-Z0-9_+]\+://.*:\).*\(@.*\)$$|\1${censored}\2|
95
+ format_env:=sed '$(call censor,SECRET); \
96
+ $(call censor,TOKEN); \
97
+ $(call censor,PRIVATE); \
98
+ $(call censor,KEY); \
99
+ $(censor_urls); \
100
+ /^\s*$$/d; \
101
+ /^\s*\#/d; \
102
+ s/\(^[a-zA-Z0-9_]\+\)=/${blue}\1${reset}=/; \
103
+ s/^/ /; \
104
+ s/=\(.*\)$$/=${yellow}\1${reset}/' | \
105
+ sort
106
+
107
+ fail=( \
108
+ $(call printraw,' ${cross}') ; \
109
+ ${restore_env} ; \
110
+ $(call make,dump) ; \
111
+ echo ; \
112
+ $(call println,'Failed. ${cross}') ; \
113
+ exit 1 \
114
+ )
115
+
116
+
117
+ ifdef env_file
118
+ -include ${env_file}
119
+ else
120
+ ifneq (${env},test)
121
+ ifeq (,$(findstring test,$(MAKECMDGOALS)))
122
+ -include .env
123
+ endif
124
+ endif
125
+ endif
126
+
127
+ export
128
+
129
+ ifneq (,$(env))
130
+ # `env` set by current shell.
131
+ else ifneq (,$(RAILS_ENV))
132
+ env=$(RAILS_ENV)
133
+ else ifneq (,$(RACK_ENV))
134
+ env=$(RACK_ENV)
135
+ else
136
+ env=development
137
+ endif
138
+
139
+ DOCKER_TAG ?= latest
140
+
141
+ ifneq (,$(wildcard ./Gemfile))
142
+ rake=RACK_ENV=${env} RAILS_ENV=${env} bundle exec rake
143
+ else
144
+ rake=RACK_ENV=${env} RAILS_ENV=${env} rake
145
+ endif
146
+
147
+ ifneq (,$(wildcard ${env_file}))
148
+ rake_cmd:=${rake}
149
+ rake=. ${env_file} && ${rake_cmd}
150
+ endif
151
+
152
+ ifeq (,$(findstring serve,$(MAKECMDGOALS)))
153
+ ifeq (,$(findstring console,$(MAKECMDGOALS)))
154
+ ifeq (,$(findstring test,$(MAKECMDGOALS)))
155
+ docker_config:=$(shell ${rake} orchestration:config)
156
+ docker_organization=$(word 1,$(docker_config))
157
+ docker_repository=$(word 2,$(docker_config))
158
+ endif
159
+ endif
160
+ endif
161
+
162
+ ifeq (,$(project_name))
163
+ project_base = ${docker_repository}_${env}
164
+ else
165
+ project_base := $(project_name)
166
+ endif
167
+
168
+ ifeq (,$(findstring deploy,$(MAKECMDGOALS)))
169
+ sidecar_suffix := $(shell test -f ${orchestration_dir}/.sidecar && cat ${orchestration_dir}/.sidecar)
170
+ ifneq (,${sidecar_suffix})
171
+ sidecar := 1
172
+ endif
173
+
174
+ ifdef sidecar
175
+ # Set the variable to an empty string so that "#{sidecar-1234}" will
176
+ # evaluate to "1234" in port mappings.
177
+ sidecar_compose = sidecar=''
178
+ ifeq (,${sidecar_suffix})
179
+ sidecar_suffix := $(call token)
180
+ _ignore := $(shell echo ${sidecar_suffix} > ${orchestration_dir}/.sidecar)
181
+ endif
182
+
183
+ ifeq (,${sidecar_suffix})
184
+ $(warning Unable to generate project suffix; project name collisions may occur.)
185
+ endif
186
+ compose_project_name = ${project_base}_${sidecar_suffix}
187
+ else
188
+ compose_project_name = ${project_base}
189
+ endif
190
+ else
191
+ compose_project_name = ${project_base}
192
+ endif
193
+
194
+ compose_base=env -i \
195
+ PATH=$(PATH) \
196
+ HOST_UID=$(shell id -u) \
197
+ DOCKER_ORGANIZATION="${docker_organization}" \
198
+ DOCKER_REPOSITORY="${docker_repository}" \
199
+ COMPOSE_PROJECT_NAME="${compose_project_name}" \
200
+ ${sidecar_compose} \
201
+ docker-compose \
202
+ -f ${orchestration_dir}/docker-compose.${env}.yml
203
+
204
+ git_branch ?= $(if $(branch),$(branch),$(shell git rev-parse --abbrev-ref HEAD))
205
+ ifndef dev
206
+ git_version ?= $(shell git rev-parse --short --verify ${git_branch})
207
+ else
208
+ git_version = dev
209
+ endif
210
+
211
+ docker_image=${docker_organization}/${docker_repository}:${git_version}
212
+
213
+ compose=${compose_base}
214
+ random_str=cat /dev/urandom | LC_ALL=C tr -dc 'a-z' | head -c $1
215
+
216
+ ifneq (,$(wildcard ${orchestration_dir}/docker-compose.local.yml))
217
+ compose:=${compose} -f ${orchestration_dir}/docker-compose.local.yml
218
+ endif
219
+
220
+ all: build
221
+
222
+ ### Container management commands ###
223
+
224
+ .PHONY: start
225
+ ifndef network
226
+ start: network := ${compose_project_name}_default
227
+ endif
228
+ start: _create-log-directory _clean-logs
229
+ @$(call print,'${yellow}Starting ${cyan}${env}${yellow} containers${reset} ...')
230
+ ifeq (${env},$(filter ${env},test development))
231
+ @${compose} up --detach --force-recreate --renew-anon-volumes --remove-orphans ${services} ${log} || ${fail}
232
+ @[ -n '${sidecar}' ] && \
233
+ ( \
234
+ $(call printraw,' ${yellow}(joining dependency network ${green}${network}${yellow})${reset} ... ') ; \
235
+ docker network connect '${network}' '$(shell hostname)' ${log} \
236
+ || ( \
237
+ $(call println,'') ; \
238
+ $(call println,'${yellow}Warning${reset}: Unable to join network: "${yellow}${network}${reset}". Container will not be able to connect to dependency services.') ; \
239
+ $(call print,'You may need to delete "${yellow}orchestration/.sidecar${reset}" to disable sidecar mode if this file was added by mistake.\n...') ; \
240
+ ) \
241
+ ) \
242
+ || ( [ -z '${sidecar}' ] || ${fail} )
243
+ else
244
+ @${compose} up --detach --scale app=$${instances:-1} ${log} || ${fail}
245
+ endif
246
+ @$(call printrawln,' ${green}started${reset} ${tick}')
247
+ @$(call println,'${yellow}Waiting for services to become available${reset} ...')
248
+ @$(call make,wait) 2>${stderr} || ${fail}
249
+
250
+ .PHONY: start-database
251
+ start-database:
252
+ @$(call make,start services='database')
253
+
254
+ .PHONY: start-app
255
+ start-app:
256
+ @$(call make,start services='app')
257
+
258
+
259
+ .PHONY: stop
260
+ stop: network := ${compose_project_name}_default
261
+ stop:
262
+ @$(call print,'${yellow}Stopping ${cyan}${env}${yellow} containers${reset} ...')
263
+ @if docker ps --format "{{.ID}}" | grep -q $(shell hostname) ; \
264
+ then \
265
+ ( docker network disconnect ${network} $(shell hostname) ${log} || : ) \
266
+ && \
267
+ ( ${compose} down ${log} || ${fail} ) ; \
268
+ else \
269
+ ${compose} down ${log} || ${fail} ; \
270
+ fi
271
+ @$(call printrawln,' ${green}stopped${reset}. ${tick}')
272
+
273
+ .PHONY: logs
274
+ logs:
275
+ @${compose} logs -f
276
+
277
+ .PHONY: config
278
+ config:
279
+ @${compose} config
280
+
281
+ .PHONY: compose
282
+ compose:
283
+ @echo ${compose}
284
+
285
+ ### Development/Test Utility Commands
286
+
287
+ .PHONY: serve
288
+ serve: env_file ?= ./.env
289
+ serve: rails = RAILS_ENV='${env}' bundle exec rails server ${server}
290
+ serve:
291
+ @if [ -f "${env_file}" ] ; \
292
+ then ( \
293
+ $(call println,'${yellow}Environment${reset}: ${green}${env_file}${reset}') && \
294
+ cat '${env_file}' | ${format_env} && \
295
+ $(call printrawln,'') \
296
+ ) ; \
297
+ fi
298
+ ${rails}
299
+
300
+ .PHONY: console
301
+ console: env_file ?= ./.env
302
+ console: rails = RAILS_ENV='${env}' bundle exec rails
303
+ console:
304
+ @if [ -f "${env_file}" ] ; \
305
+ then ( \
306
+ $(call println,'${yellow}Environment${reset}: ${green}${env_file}${reset}') && \
307
+ cat '${env_file}' | ${format_env} && \
308
+ $(call printrawln,'') \
309
+ ) ; \
310
+ fi
311
+ ${rails} console
312
+
313
+ .PHONY: test-setup
314
+ test-setup: env := test
315
+ test-setup:
316
+ ifndef light
317
+ @$(call make,start env=test)
318
+ ifneq (,$(wildcard config/database.yml))
319
+ ${rake} db:create || :
320
+ ifneq (,$(wildcard db/structure.sql))
321
+ ${rake} db:structure:load
322
+ else ifneq (,$(wildcard db/schema.rb))
323
+ ${rake} db:schema:load
324
+ endif
325
+
326
+ ${rake} db:migrate
327
+ endif
328
+ endif
329
+
330
+ .PHONY: dump
331
+ dump:
332
+ ifndef verbose
333
+ @$(call println)
334
+ @$(call println,'${yellow}Captured${reset} ${green}stdout${reset} ${yellow}and${reset} ${red}stderr${reset} ${yellow}log data [${cyan}${env}${yellow}]${reset}:')
335
+ @$(call println)
336
+ @echo
337
+ @test -f '${stdout}' && ( \
338
+ $(call hr,${green}) ; \
339
+ $(call println,'${gray}${stdout}${reset}') ; \
340
+ $(call hr,${green}) ; \
341
+ echo ; cat '${stdout}' ; echo ; \
342
+ $(call hr,${green}) ; \
343
+ )
344
+
345
+ @test -f '${stdout}' && ( \
346
+ echo ; \
347
+ $(call hr,${red}) ; \
348
+ $(call println,'${gray}${stderr}${reset}') ; \
349
+ $(call hr,${red}) ; \
350
+ echo ; cat '${stderr}' ; echo ; \
351
+ $(call hr,${red}) ; \
352
+ )
353
+ endif
354
+ @echo ; \
355
+ $(call hr,${yellow}) ; \
356
+ $(call println,'${gray}docker-compose logs${reset}') ; \
357
+ $(call hr,${yellow}) ; \
358
+ echo
359
+ @${compose} logs
360
+ @echo ; \
361
+ $(call hr,${yellow})
362
+
363
+ .PHONY: image
364
+ image:
365
+ @echo ${docker_image}
366
+
367
+ ### Deployment utility commands ###
368
+
369
+ .PHONY: bundle
370
+ bundle:
371
+ ifndef path
372
+ @$(warning Missing `path` parameter; using `./bundle.tar`. Set a custom path with `make bundle path=/tmp/bundle.tar`)
373
+ endif
374
+ @rm -rf ${orchestration_dir}/.deploy/
375
+ @mkdir -p ${orchestration_dir}/.deploy/${docker_repository}/
376
+ @sed -e "s/%%VERSION%%/${git_version}/g" \
377
+ -e "s/%%REPOSITORY%%/${docker_repository}/g" \
378
+ -e "s/%%ORGANIZATION%%/${docker_organization}/g" \
379
+ ${orchestration_dir}/deploy.mk > \
380
+ ${orchestration_dir}/.deploy/${docker_repository}/Makefile
381
+ @bundle_path="${path}" ; tar -C '${orchestration_dir}/.deploy' -cf "$${bundle_path:-./bundle.tar}" ./${docker_repository}
382
+
383
+ .PHONY: deploy
384
+ deploy: path := $(shell mktemp -d)
385
+ deploy: RAILS_ENV := ${env}
386
+ deploy: RACK_ENV := ${env}
387
+ deploy: DOCKER_TAG = ${git_version}
388
+ deploy:
389
+ ifndef manager
390
+ @$(call println_error,'Missing `manager` parameter: `make deploy manager=swarm-manager.example.com`') ; exit 1
391
+ endif
392
+ @$(call println,'${yellow}Deploying ${green}${env}${reset} stack via${reset} ${green}${manager}${reset} ...') && \
393
+ ( \
394
+ $(call make,bundle path='${path}/bundle.tar') ${log} && \
395
+ cd '${path}' ${log} && \
396
+ tar xf 'bundle.tar' ${log} && \
397
+ cd '${docker_repository}' ${log} && \
398
+ ( [ -z '${env_file}' ] || cp '${env_file}' './.env' ${log} ) && \
399
+ $(call println,'${yellow}Deployment environment${reset}:') && \
400
+ ( test -f '.env' && cat '.env' | ${format_env} || : ) && \
401
+ echo 'DOCKER_ORGANIZATION=${docker_organization}' >> './.env' && \
402
+ echo 'DOCKER_REPOSITORY=${docker_repository}' >> './.env' && \
403
+ echo 'DOCKER_TAG=${git_version}' >> ./.env && \
404
+ $(call println,'') && \
405
+ $(call println,'${yellow}Application image${reset}: ${cyan}${docker_image}${reset}') && \
406
+ ${compose} config 2>${stderr} | ssh "${manager}" 'docker stack deploy --prune --with-registry-auth -c - "${project_base}"' ${log} && \
407
+ ( [ -z "${path}" ] || rm -rf "${path}" ${log} ) \
408
+ ) \
409
+ || ${fail}
410
+
411
+ @$(call println,'${yellow}Deployment${reset} ${green}complete${reset}. ${tick}')
412
+
413
+ .PHONY: rollback
414
+ ifndef service
415
+ rollback: service = app
416
+ endif
417
+ rollback:
418
+ ifndef manager
419
+ @$(call println_error,'Missing `manager` parameter: `make deploy manager=swarm-manager.example.com`') ; exit 1
420
+ endif
421
+ @$(call println,'${yellow}Rolling back${reset} ${green}${compose_project_name}_${service}${reset} ${yellow}via${reset} ${green}${manager}${reset} ...')
422
+ @ssh "${manager}" 'docker service rollback --detach "${compose_project_name}_${service}"' ${log} || ${fail}
423
+ @$(call println,'${yellow}Rollback request${reset} ${green}complete${reset}. ${tick}')
424
+
425
+ ### Service healthcheck commands ###
426
+
427
+ .PHONY: wait
428
+ wait:
429
+ @${rake} orchestration:wait
430
+ @$(call println,'${yellow}All services${reset} ${green}ready${reset}. ${tick}')
431
+
432
+ ## Generic Listener healthcheck for TCP services ##
433
+
434
+ wait-listener:
435
+ @${rake} orchestration:listener:wait service=${service} sidecar=${sidecar}
436
+
437
+ ### Docker build commands ###
438
+
439
+ .PHONY: build
440
+ build: build_dir = ${orchestration_dir}/.build
441
+ build: context = ${build_dir}/context.tar
442
+ build: _create-log-directory check-local-changes
443
+ @$(call print,'${yellow}Preparing build context from${reset} ${cyan}${git_branch}:${git_version}${reset} ... ')
444
+ @mkdir -p ${orchestration_dir}/.build ${log} || ${fail}
445
+ ifndef dev
446
+ @git show ${git_branch}:./Gemfile > ${orchestration_dir}/.build/Gemfile 2>${stderr} || ${fail}
447
+ @git show ${git_branch}:./Gemfile.lock > ${orchestration_dir}/.build/Gemfile.lock 2>${stderr} || ${fail}
448
+ @git show ${git_branch}:./package.json > ${orchestration_dir}/.build/package.json 2>${stderr} || ${fail}
449
+ @git show ${git_branch}:./yarn.lock > ${orchestration_dir}/.build/yarn.lock 2>${stderr} || ${fail}
450
+ @git archive --format 'tar' -o '${context}' '${git_branch}' ${log} || ${fail}
451
+ else
452
+ @tar -cvf '${context}' . ${log} || ${fail}
453
+ endif
454
+ @$(call printrawln,'${green}complete.${reset} ${tick}')
455
+ ifdef include
456
+ @$(call print,'${yellow}Including files from:${reset} ${cyan}${include}${reset} ...')
457
+ @(while read line; do \
458
+ export line; \
459
+ include_dir="${build_dir}/$$(dirname "$${line}")/" && \
460
+ mkdir -p "$${include_dir}" && cp "$${line}" "$${include_dir}" \
461
+ && (cd '${orchestration_dir}/.build/' && tar rf 'context.tar' "$${line}"); \
462
+ done < '${include}') ${log} || ${fail}
463
+ @$(call printrawln,' ${green}complete.${reset} ${tick}')
464
+ endif
465
+ ifdef sidecar
466
+ # Assume we are in a line-buffered environment (e.g. Jenkins)
467
+ @$(call println,'${yellow}Building image${reset} ...')
468
+ else
469
+ @$(call print,'${yellow}Building image${reset} ...')
470
+ endif
471
+ @docker build \
472
+ --build-arg BUNDLE_GITHUB__COM \
473
+ --build-arg BUNDLE_BITBUCKET__ORG \
474
+ --build-arg GIT_COMMIT='${git_version}' \
475
+ -t ${docker_organization}/${docker_repository} \
476
+ -t ${docker_organization}/${docker_repository}:${git_version} \
477
+ ${orchestration_dir}/ ${log_progress} || ${fail}
478
+ @$(call printrawln,' ${green}complete${reset}. ${tick}')
479
+ @$(call println,'[${green}tag${reset}] ${cyan}${docker_organization}/${docker_repository}${reset}')
480
+ @$(call println,'[${green}tag${reset}] ${cyan}${docker_organization}/${docker_repository}:${git_version}${reset}')
481
+
482
+ .PHONY: push
483
+ push: _create-log-directory
484
+ @$(call print,'${yellow}Pushing${reset} ${cyan}${docker_image}${reset} ...')
485
+ @docker push ${docker_image} ${log_progress} || ${fail}
486
+ @$(call printrawln,' ${green}complete${reset}. ${tick}')
487
+
488
+ .PHONY: check-local-changes
489
+ check-local-changes:
490
+ ifndef dev
491
+ @if [[ ! -z "$$(git status --porcelain)" ]] ; \
492
+ then \
493
+ $(call println,'${red}You have uncommitted changes which will not be included in your build:${reset}') ; \
494
+ git status --porcelain ; \
495
+ $(call println,'${yellow}Use ${cyan}make build dev=1${reset} ${yellow}to include these files.${reset}\n') ; \
496
+ fi
497
+ endif
498
+
499
+ ### Internal Commands ###
500
+ #
501
+ .PHONY: _clean-logs
502
+ _clean-logs:
503
+ @rm -f '${stdout}' '${stderr}'
504
+ @touch '${stdout}' '${stderr}'
505
+
506
+ .PHONY: _create-log-directory
507
+ _create-log-directory:
508
+ @mkdir -p log