diff --git a/src/_base/CHANGELOG.md b/src/_base/CHANGELOG.md new file mode 100644 index 000000000..b9fde5c09 --- /dev/null +++ b/src/_base/CHANGELOG.md @@ -0,0 +1,13 @@ +# CHANGELOG + +## 1.5.0 - 20230126 + +### Added attributes + +* `attribute('console.state.steps')` - Steps necessary to test the health of the console container +* `attribute('console.healthcheck.enabled')` - Defaults to `true` only for local builds +* `attribute('console.healthcheck.test')` - The command in array format that will run the healthcheck - Defaults to ['CMD', 'app', 'state'] +* `attribute('console.healthcheck.test.start_period')` - Defaults to 5s +* `attribute('console.healthcheck.test.interval')` - Defaults to 5s +* `attribute('console.healthcheck.test.timeout')` - Defaults to 3s +* `attribute('console.healthcheck.test.retries')` - Defaults to 10 diff --git a/src/_base/_twig/docker-compose.yml/service/console.yml.twig b/src/_base/_twig/docker-compose.yml/service/console.yml.twig index 6a1325832..17f5ae228 100644 --- a/src/_base/_twig/docker-compose.yml/service/console.yml.twig +++ b/src/_base/_twig/docker-compose.yml/service/console.yml.twig @@ -7,6 +7,14 @@ build: context: ./ dockerfile: .my127ws/docker/image/console/Dockerfile +{% if @('console.healthcheck.enabled') %} + healthcheck: + test: {{ to_nice_yaml( @('console.healthcheck.test'), 2, 8) | raw }} + start_period: {{ @('console.healthcheck.start_period') }} + interval: {{ @('console.healthcheck.interval') }} + timeout: {{ @('console.healthcheck.timeout') }} + retries: {{ @('console.healthcheck.retries') }} +{% endif %} {% if @('app.build') == 'dynamic' %} entrypoint: [/entrypoint.dynamic.sh] command: [sleep, infinity] diff --git a/src/_base/docker/image/console/root/entrypoint.dynamic.sh b/src/_base/docker/image/console/root/entrypoint.dynamic.sh old mode 100755 new mode 100644 diff --git a/src/_base/docker/image/console/root/entrypoint.sh.twig b/src/_base/docker/image/console/root/entrypoint.sh.twig index 8c8b35af9..063813c09 100755 --- a/src/_base/docker/image/console/root/entrypoint.sh.twig +++ b/src/_base/docker/image/console/root/entrypoint.sh.twig @@ -36,10 +36,16 @@ run_steps() fi } +healthcheck_checkpoint() +{ + echo 'Entrypoint tasks completed: console has started' > /run/started +} + bootstrap() { setup_app_networking run_steps + healthcheck_checkpoint } bootstrap diff --git a/src/_base/docker/image/console/root/lib/task/state.sh b/src/_base/docker/image/console/root/lib/task/state.sh deleted file mode 100644 index c0e00419c..000000000 --- a/src/_base/docker/image/console/root/lib/task/state.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -function task_state() -{ - task database:available - - echo "Ready!" -} diff --git a/src/_base/docker/image/console/root/lib/task/state.sh.twig b/src/_base/docker/image/console/root/lib/task/state.sh.twig new file mode 100644 index 000000000..38d5fb26d --- /dev/null +++ b/src/_base/docker/image/console/root/lib/task/state.sh.twig @@ -0,0 +1,20 @@ +#!/bin/bash + +function test_ok() +{ + # run any command required which result can be monitored by Docker's HEALTHCHECK + {% for step in @('console.state.steps') -%} + {{ step|raw }} + {% else -%} + : + {% endfor %} + +} + +function task_state() +{ + if ! test_ok; then + echo "Console is not ready: test steps failed!" + return 1 + fi +} diff --git a/src/_base/harness/attributes/common.yml b/src/_base/harness/attributes/common.yml index b8a8b4779..de77af227 100644 --- a/src/_base/harness/attributes/common.yml +++ b/src/_base/harness/attributes/common.yml @@ -297,6 +297,17 @@ attributes.default: steps: [] console: + state: + steps: + - if [[ -f /run/started ]]; then cat /run/started; else return 1; fi + healthcheck: + # we want that enabled only for local builds + enabled: false + test: ['CMD', 'app', 'state'] + start_period: 5s + interval: 5s + timeout: 3s + retries: 10 entrypoint: steps: [] diff --git a/src/_base/harness/attributes/environment/local.yml b/src/_base/harness/attributes/environment/local.yml index 41505a544..32df8174a 100644 --- a/src/_base/harness/attributes/environment/local.yml +++ b/src/_base/harness/attributes/environment/local.yml @@ -3,4 +3,7 @@ attributes: app: build: dynamic mode: development - version: develop \ No newline at end of file + version: develop + console: + healthcheck: + enabled: true diff --git a/src/_base/harness/config/confd.yml b/src/_base/harness/config/confd.yml index 550aacec2..be9df75f4 100644 --- a/src/_base/harness/config/confd.yml +++ b/src/_base/harness/config/confd.yml @@ -12,6 +12,7 @@ confd('harness:/'): - { src: docker/image/console/root/lib/task/install.sh } - { src: docker/image/console/root/lib/task/migrate.sh } - { src: docker/image/console/root/lib/task/rabbitmq/vhosts.sh } + - { src: docker/image/console/root/lib/task/state.sh } - { src: docker/image/console/root/lib/task/welcome.sh } - { src: docker/image/console/root/usr/local/etc/php/php.ini } - { src: docker/image/console/root/usr/local/etc/php/conf.d/docker-php-ext-blackfire.ini } diff --git a/src/_base/harness/scripts/enable.sh.twig b/src/_base/harness/scripts/enable.sh.twig index b047664d6..ad7559e66 100755 --- a/src/_base/harness/scripts/enable.sh.twig +++ b/src/_base/harness/scripts/enable.sh.twig @@ -85,7 +85,8 @@ dynamic_console() find .my127ws/docker/image/ -type d ! -perm u+rwx,go+rx,o-w -exec chmod u+rwx,go+rx,o-w {} + - passthru docker-compose up --build -d console + # docker-compose will wait for `console` to be in healty status if healthcheck is enabled + passthru docker-compose up --build -d console --wait passthru docker-compose exec -T -u build console app build if [ "$USE_MUTAGEN" = yes ]; then diff --git a/src/akeneo/harness/config/confd.yml b/src/akeneo/harness/config/confd.yml index d342e4697..bb587321e 100644 --- a/src/akeneo/harness/config/confd.yml +++ b/src/akeneo/harness/config/confd.yml @@ -12,6 +12,7 @@ confd('harness:/'): - { src: docker/image/console/root/lib/task/install.sh } - { src: docker/image/console/root/lib/task/migrate.sh } - { src: docker/image/console/root/lib/task/rabbitmq/vhosts.sh } + - { src: docker/image/console/root/lib/task/state.sh } - { src: docker/image/console/root/lib/task/welcome.sh } - { src: docker/image/console/root/usr/local/etc/php/php.ini } - { src: docker/image/console/root/usr/local/etc/php/conf.d/docker-php-ext-blackfire.ini } diff --git a/src/magento1/harness/config/confd.yml b/src/magento1/harness/config/confd.yml index 8ee0040c0..5db5dfdea 100644 --- a/src/magento1/harness/config/confd.yml +++ b/src/magento1/harness/config/confd.yml @@ -12,6 +12,7 @@ confd('harness:/'): - { src: docker/image/console/root/lib/task/install.sh } - { src: docker/image/console/root/lib/task/migrate.sh } - { src: docker/image/console/root/lib/task/rabbitmq/vhosts.sh } + - { src: docker/image/console/root/lib/task/state.sh } - { src: docker/image/console/root/lib/task/welcome.sh } - { src: docker/image/console/root/usr/local/etc/php/php.ini } - { src: docker/image/console/root/usr/local/etc/php/conf.d/docker-php-ext-blackfire.ini } diff --git a/src/magento2/harness/config/confd.yml b/src/magento2/harness/config/confd.yml index 87a09309c..15dfca49f 100644 --- a/src/magento2/harness/config/confd.yml +++ b/src/magento2/harness/config/confd.yml @@ -12,6 +12,7 @@ confd('harness:/'): - { src: docker/image/console/root/lib/task/install.sh } - { src: docker/image/console/root/lib/task/migrate.sh } - { src: docker/image/console/root/lib/task/rabbitmq/vhosts.sh } + - { src: docker/image/console/root/lib/task/state.sh } - { src: docker/image/console/root/lib/task/welcome.sh } - { src: docker/image/console/root/usr/local/etc/php/php.ini } - { src: docker/image/console/root/usr/local/etc/php/conf.d/docker-php-ext-blackfire.ini } diff --git a/src/spryker/_twig/docker-compose.yml/service/console.yml.twig b/src/spryker/_twig/docker-compose.yml/service/console.yml.twig index 154fc6bda..744be95e3 100644 --- a/src/spryker/_twig/docker-compose.yml/service/console.yml.twig +++ b/src/spryker/_twig/docker-compose.yml/service/console.yml.twig @@ -7,6 +7,14 @@ build: context: ./ dockerfile: .my127ws/docker/image/console/Dockerfile +{% if @('console.healthcheck.enabled') %} + healthcheck: + test: {{ to_nice_yaml( @('console.healthcheck.test'), 2, 8) | raw }} + start_period: {{ @('console.healthcheck.start_period') }} + interval: {{ @('console.healthcheck.interval') }} + timeout: {{ @('console.healthcheck.timeout') }} + retries: {{ @('console.healthcheck.retries') }} +{% endif %} {% if @('app.build') == 'dynamic' %} image: {{ @('workspace.name') ~ '-console:dev' }} entrypoint: [/entrypoint.dynamic.sh] diff --git a/src/spryker/harness/attributes/environment/local.yml b/src/spryker/harness/attributes/environment/local.yml index 340d633ec..e5baa56d9 100644 --- a/src/spryker/harness/attributes/environment/local.yml +++ b/src/spryker/harness/attributes/environment/local.yml @@ -5,3 +5,6 @@ attributes: build: dynamic mode: development version: develop + console: + healthcheck: + enabled: true diff --git a/src/spryker/harness/config/confd.yml b/src/spryker/harness/config/confd.yml index 953071f62..0e864f2b3 100644 --- a/src/spryker/harness/config/confd.yml +++ b/src/spryker/harness/config/confd.yml @@ -12,6 +12,7 @@ confd('harness:/'): - { src: docker/image/console/root/lib/task/install.sh } - { src: docker/image/console/root/lib/task/migrate.sh } - { src: docker/image/console/root/lib/task/rabbitmq/vhosts.sh } + - { src: docker/image/console/root/lib/task/state.sh } - { src: docker/image/console/root/lib/task/welcome.sh } - { src: docker/image/console/root/usr/local/etc/php/php.ini } - { src: docker/image/console/root/usr/local/etc/php/conf.d/docker-php-ext-blackfire.ini } diff --git a/src/symfony/harness/config/confd.yml b/src/symfony/harness/config/confd.yml index d34379088..b9ed7a720 100644 --- a/src/symfony/harness/config/confd.yml +++ b/src/symfony/harness/config/confd.yml @@ -12,6 +12,7 @@ confd('harness:/'): - { src: docker/image/console/root/lib/task/install.sh } - { src: docker/image/console/root/lib/task/migrate.sh } - { src: docker/image/console/root/lib/task/rabbitmq/vhosts.sh } + - { src: docker/image/console/root/lib/task/state.sh } - { src: docker/image/console/root/lib/task/welcome.sh } - { src: docker/image/console/root/usr/local/etc/php/php.ini } - { src: docker/image/console/root/usr/local/etc/php/conf.d/docker-php-ext-blackfire.ini } diff --git a/src/wordpress/harness/config/confd.yml b/src/wordpress/harness/config/confd.yml index e29928424..b3e4a74f3 100644 --- a/src/wordpress/harness/config/confd.yml +++ b/src/wordpress/harness/config/confd.yml @@ -12,6 +12,7 @@ confd('harness:/'): - { src: docker/image/console/root/lib/task/install.sh } - { src: docker/image/console/root/lib/task/migrate.sh } - { src: docker/image/console/root/lib/task/rabbitmq/vhosts.sh } + - { src: docker/image/console/root/lib/task/state.sh } - { src: docker/image/console/root/lib/task/welcome.sh } - { src: docker/image/console/root/usr/local/etc/php/php.ini } - { src: docker/image/console/root/usr/local/etc/php/conf.d/docker-php-ext-blackfire.ini }