diff --git a/.platform/schema b/.platform/schema index e440e5c8..bf0d87ab 100644 --- a/.platform/schema +++ b/.platform/schema @@ -1 +1 @@ -3 \ No newline at end of file +4 \ No newline at end of file diff --git a/composer.lock b/composer.lock index 01b82ebb..a2aa0480 100644 --- a/composer.lock +++ b/composer.lock @@ -3747,16 +3747,16 @@ }, { "name": "drupal/hdbt", - "version": "6.0.7", + "version": "6.1.0", "source": { "type": "git", "url": "https://github.com/City-of-Helsinki/drupal-hdbt.git", - "reference": "870d15251457e0b01c0a71a73197d93f20e65fc1" + "reference": "23f88b1560240d61ca7c2a644d0856679a778ebf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/City-of-Helsinki/drupal-hdbt/zipball/870d15251457e0b01c0a71a73197d93f20e65fc1", - "reference": "870d15251457e0b01c0a71a73197d93f20e65fc1", + "url": "https://api.github.com/repos/City-of-Helsinki/drupal-hdbt/zipball/23f88b1560240d61ca7c2a644d0856679a778ebf", + "reference": "23f88b1560240d61ca7c2a644d0856679a778ebf", "shasum": "" }, "require": { @@ -3774,10 +3774,10 @@ "Drupal" ], "support": { - "source": "https://github.com/City-of-Helsinki/drupal-hdbt/tree/6.0.7", + "source": "https://github.com/City-of-Helsinki/drupal-hdbt/tree/6.1.0", "issues": "https://github.com/City-of-Helsinki/drupal-hdbt/issues" }, - "time": "2023-11-30T11:36:34+00:00" + "time": "2023-12-01T12:38:54+00:00" }, { "name": "drupal/hdbt_admin", @@ -4040,16 +4040,16 @@ }, { "name": "drupal/helfi_platform_config", - "version": "4.1.3", + "version": "4.1.4", "source": { "type": "git", "url": "https://github.com/City-of-Helsinki/drupal-helfi-platform-config.git", - "reference": "d0379a5a1b82e8bb1e6312a0540d982bacf565cb" + "reference": "9adcf9998ab020196f6803538d8192d245560866" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/City-of-Helsinki/drupal-helfi-platform-config/zipball/d0379a5a1b82e8bb1e6312a0540d982bacf565cb", - "reference": "d0379a5a1b82e8bb1e6312a0540d982bacf565cb", + "url": "https://api.github.com/repos/City-of-Helsinki/drupal-helfi-platform-config/zipball/9adcf9998ab020196f6803538d8192d245560866", + "reference": "9adcf9998ab020196f6803538d8192d245560866", "shasum": "" }, "require": { @@ -4161,10 +4161,10 @@ ], "description": "HELfi platform config", "support": { - "source": "https://github.com/City-of-Helsinki/drupal-helfi-platform-config/tree/4.1.3", + "source": "https://github.com/City-of-Helsinki/drupal-helfi-platform-config/tree/4.1.4", "issues": "https://github.com/City-of-Helsinki/drupal-helfi-platform-config/issues" }, - "time": "2023-12-01T06:58:54+00:00" + "time": "2023-12-01T11:23:19+00:00" }, { "name": "drupal/helfi_proxy", @@ -7478,16 +7478,16 @@ }, { "name": "firebase/php-jwt", - "version": "v6.9.0", + "version": "v6.10.0", "source": { "type": "git", "url": "https://github.com/firebase/php-jwt.git", - "reference": "f03270e63eaccf3019ef0f32849c497385774e11" + "reference": "a49db6f0a5033aef5143295342f1c95521b075ff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/firebase/php-jwt/zipball/f03270e63eaccf3019ef0f32849c497385774e11", - "reference": "f03270e63eaccf3019ef0f32849c497385774e11", + "url": "https://api.github.com/repos/firebase/php-jwt/zipball/a49db6f0a5033aef5143295342f1c95521b075ff", + "reference": "a49db6f0a5033aef5143295342f1c95521b075ff", "shasum": "" }, "require": { @@ -7535,9 +7535,9 @@ ], "support": { "issues": "https://github.com/firebase/php-jwt/issues", - "source": "https://github.com/firebase/php-jwt/tree/v6.9.0" + "source": "https://github.com/firebase/php-jwt/tree/v6.10.0" }, - "time": "2023-10-05T00:24:42+00:00" + "time": "2023-12-01T16:26:39+00:00" }, { "name": "galbar/jsonpath", @@ -7700,16 +7700,16 @@ }, { "name": "guzzlehttp/guzzle", - "version": "7.8.0", + "version": "7.8.1", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "1110f66a6530a40fe7aea0378fe608ee2b2248f9" + "reference": "41042bc7ab002487b876a0683fc8dce04ddce104" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/1110f66a6530a40fe7aea0378fe608ee2b2248f9", - "reference": "1110f66a6530a40fe7aea0378fe608ee2b2248f9", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/41042bc7ab002487b876a0683fc8dce04ddce104", + "reference": "41042bc7ab002487b876a0683fc8dce04ddce104", "shasum": "" }, "require": { @@ -7724,11 +7724,11 @@ "psr/http-client-implementation": "1.0" }, "require-dev": { - "bamarni/composer-bin-plugin": "^1.8.1", + "bamarni/composer-bin-plugin": "^1.8.2", "ext-curl": "*", "php-http/client-integration-tests": "dev-master#2c025848417c1135031fdf9c728ee53d0a7ceaee as 3.0.999", "php-http/message-factory": "^1.1", - "phpunit/phpunit": "^8.5.29 || ^9.5.23", + "phpunit/phpunit": "^8.5.36 || ^9.6.15", "psr/log": "^1.1 || ^2.0 || ^3.0" }, "suggest": { @@ -7806,7 +7806,7 @@ ], "support": { "issues": "https://github.com/guzzle/guzzle/issues", - "source": "https://github.com/guzzle/guzzle/tree/7.8.0" + "source": "https://github.com/guzzle/guzzle/tree/7.8.1" }, "funding": [ { @@ -7822,28 +7822,28 @@ "type": "tidelift" } ], - "time": "2023-08-27T10:20:53+00:00" + "time": "2023-12-03T20:35:24+00:00" }, { "name": "guzzlehttp/promises", - "version": "2.0.1", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/guzzle/promises.git", - "reference": "111166291a0f8130081195ac4556a5587d7f1b5d" + "reference": "bbff78d96034045e58e13dedd6ad91b5d1253223" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/111166291a0f8130081195ac4556a5587d7f1b5d", - "reference": "111166291a0f8130081195ac4556a5587d7f1b5d", + "url": "https://api.github.com/repos/guzzle/promises/zipball/bbff78d96034045e58e13dedd6ad91b5d1253223", + "reference": "bbff78d96034045e58e13dedd6ad91b5d1253223", "shasum": "" }, "require": { "php": "^7.2.5 || ^8.0" }, "require-dev": { - "bamarni/composer-bin-plugin": "^1.8.1", - "phpunit/phpunit": "^8.5.29 || ^9.5.23" + "bamarni/composer-bin-plugin": "^1.8.2", + "phpunit/phpunit": "^8.5.36 || ^9.6.15" }, "type": "library", "extra": { @@ -7889,7 +7889,7 @@ ], "support": { "issues": "https://github.com/guzzle/promises/issues", - "source": "https://github.com/guzzle/promises/tree/2.0.1" + "source": "https://github.com/guzzle/promises/tree/2.0.2" }, "funding": [ { @@ -7905,20 +7905,20 @@ "type": "tidelift" } ], - "time": "2023-08-03T15:11:55+00:00" + "time": "2023-12-03T20:19:20+00:00" }, { "name": "guzzlehttp/psr7", - "version": "2.6.1", + "version": "2.6.2", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "be45764272e8873c72dbe3d2edcfdfcc3bc9f727" + "reference": "45b30f99ac27b5ca93cb4831afe16285f57b8221" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/be45764272e8873c72dbe3d2edcfdfcc3bc9f727", - "reference": "be45764272e8873c72dbe3d2edcfdfcc3bc9f727", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/45b30f99ac27b5ca93cb4831afe16285f57b8221", + "reference": "45b30f99ac27b5ca93cb4831afe16285f57b8221", "shasum": "" }, "require": { @@ -7932,9 +7932,9 @@ "psr/http-message-implementation": "1.0" }, "require-dev": { - "bamarni/composer-bin-plugin": "^1.8.1", + "bamarni/composer-bin-plugin": "^1.8.2", "http-interop/http-factory-tests": "^0.9", - "phpunit/phpunit": "^8.5.29 || ^9.5.23" + "phpunit/phpunit": "^8.5.36 || ^9.6.15" }, "suggest": { "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" @@ -8005,7 +8005,7 @@ ], "support": { "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/2.6.1" + "source": "https://github.com/guzzle/psr7/tree/2.6.2" }, "funding": [ { @@ -8021,7 +8021,7 @@ "type": "tidelift" } ], - "time": "2023-08-27T10:13:57+00:00" + "time": "2023-12-03T20:05:35+00:00" }, { "name": "http-interop/http-factory-guzzle", @@ -10922,16 +10922,16 @@ }, { "name": "symfony/console", - "version": "v6.4.0", + "version": "v6.4.1", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "cd9864b47c367450e14ab32f78fdbf98c44c26b6" + "reference": "a550a7c99daeedef3f9d23fb82e3531525ff11fd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/cd9864b47c367450e14ab32f78fdbf98c44c26b6", - "reference": "cd9864b47c367450e14ab32f78fdbf98c44c26b6", + "url": "https://api.github.com/repos/symfony/console/zipball/a550a7c99daeedef3f9d23fb82e3531525ff11fd", + "reference": "a550a7c99daeedef3f9d23fb82e3531525ff11fd", "shasum": "" }, "require": { @@ -10996,7 +10996,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v6.4.0" + "source": "https://github.com/symfony/console/tree/v6.4.1" }, "funding": [ { @@ -11012,20 +11012,20 @@ "type": "tidelift" } ], - "time": "2023-11-20T16:41:16+00:00" + "time": "2023-11-30T10:54:28+00:00" }, { "name": "symfony/dependency-injection", - "version": "v6.4.0", + "version": "v6.4.1", "source": { "type": "git", "url": "https://github.com/symfony/dependency-injection.git", - "reference": "5dc8ad5f2bbba7046f5947682bf7d868ce80d4e8" + "reference": "f88ff6428afbeb17cc648c8003bd608534750baf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/5dc8ad5f2bbba7046f5947682bf7d868ce80d4e8", - "reference": "5dc8ad5f2bbba7046f5947682bf7d868ce80d4e8", + "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/f88ff6428afbeb17cc648c8003bd608534750baf", + "reference": "f88ff6428afbeb17cc648c8003bd608534750baf", "shasum": "" }, "require": { @@ -11077,7 +11077,7 @@ "description": "Allows you to standardize and centralize the way objects are constructed in your application", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/dependency-injection/tree/v6.4.0" + "source": "https://github.com/symfony/dependency-injection/tree/v6.4.1" }, "funding": [ { @@ -11093,7 +11093,7 @@ "type": "tidelift" } ], - "time": "2023-10-31T08:40:20+00:00" + "time": "2023-12-01T14:56:37+00:00" }, { "name": "symfony/deprecation-contracts", @@ -11770,16 +11770,16 @@ }, { "name": "symfony/http-kernel", - "version": "v6.4.0", + "version": "v6.4.1", "source": { "type": "git", "url": "https://github.com/symfony/http-kernel.git", - "reference": "16a29c453966f29466ad34444ce97970a336f3c8" + "reference": "2953274c16a229b3933ef73a6898e18388e12e1b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-kernel/zipball/16a29c453966f29466ad34444ce97970a336f3c8", - "reference": "16a29c453966f29466ad34444ce97970a336f3c8", + "url": "https://api.github.com/repos/symfony/http-kernel/zipball/2953274c16a229b3933ef73a6898e18388e12e1b", + "reference": "2953274c16a229b3933ef73a6898e18388e12e1b", "shasum": "" }, "require": { @@ -11863,7 +11863,7 @@ "description": "Provides a structured process for converting a Request into a Response", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/http-kernel/tree/v6.4.0" + "source": "https://github.com/symfony/http-kernel/tree/v6.4.1" }, "funding": [ { @@ -11879,7 +11879,7 @@ "type": "tidelift" } ], - "time": "2023-11-29T10:40:15+00:00" + "time": "2023-12-01T17:02:02+00:00" }, { "name": "symfony/mime", @@ -13081,16 +13081,16 @@ }, { "name": "symfony/routing", - "version": "v6.4.0", + "version": "v6.4.1", "source": { "type": "git", "url": "https://github.com/symfony/routing.git", - "reference": "ae014d60d7c8e80be5c3b644a286e91249a3e8f4" + "reference": "0c95c164fdba18b12523b75e64199ca3503e6d40" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/routing/zipball/ae014d60d7c8e80be5c3b644a286e91249a3e8f4", - "reference": "ae014d60d7c8e80be5c3b644a286e91249a3e8f4", + "url": "https://api.github.com/repos/symfony/routing/zipball/0c95c164fdba18b12523b75e64199ca3503e6d40", + "reference": "0c95c164fdba18b12523b75e64199ca3503e6d40", "shasum": "" }, "require": { @@ -13144,7 +13144,7 @@ "url" ], "support": { - "source": "https://github.com/symfony/routing/tree/v6.4.0" + "source": "https://github.com/symfony/routing/tree/v6.4.1" }, "funding": [ { @@ -13160,20 +13160,20 @@ "type": "tidelift" } ], - "time": "2023-11-29T08:04:54+00:00" + "time": "2023-12-01T14:54:37+00:00" }, { "name": "symfony/serializer", - "version": "v6.4.0", + "version": "v6.4.1", "source": { "type": "git", "url": "https://github.com/symfony/serializer.git", - "reference": "39471236913df0c3cfcc90bec28c50f355d3c7ef" + "reference": "7ead272e62c9567df619ef3c49809bf934ddbc1f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/serializer/zipball/39471236913df0c3cfcc90bec28c50f355d3c7ef", - "reference": "39471236913df0c3cfcc90bec28c50f355d3c7ef", + "url": "https://api.github.com/repos/symfony/serializer/zipball/7ead272e62c9567df619ef3c49809bf934ddbc1f", + "reference": "7ead272e62c9567df619ef3c49809bf934ddbc1f", "shasum": "" }, "require": { @@ -13242,7 +13242,7 @@ "description": "Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like XML and JSON.", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/serializer/tree/v6.4.0" + "source": "https://github.com/symfony/serializer/tree/v6.4.1" }, "funding": [ { @@ -13258,7 +13258,7 @@ "type": "tidelift" } ], - "time": "2023-11-29T10:01:06+00:00" + "time": "2023-12-01T14:54:37+00:00" }, { "name": "symfony/service-contracts", @@ -13689,16 +13689,16 @@ }, { "name": "symfony/var-exporter", - "version": "v7.0.0", + "version": "v7.0.1", "source": { "type": "git", "url": "https://github.com/symfony/var-exporter.git", - "reference": "d97726e8d254a2d5512b2b4ba204735d84e7167d" + "reference": "a3d7c877414fcd59ab7075ecdc3b8f9c00f7bcc3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-exporter/zipball/d97726e8d254a2d5512b2b4ba204735d84e7167d", - "reference": "d97726e8d254a2d5512b2b4ba204735d84e7167d", + "url": "https://api.github.com/repos/symfony/var-exporter/zipball/a3d7c877414fcd59ab7075ecdc3b8f9c00f7bcc3", + "reference": "a3d7c877414fcd59ab7075ecdc3b8f9c00f7bcc3", "shasum": "" }, "require": { @@ -13743,7 +13743,7 @@ "serialize" ], "support": { - "source": "https://github.com/symfony/var-exporter/tree/v7.0.0" + "source": "https://github.com/symfony/var-exporter/tree/v7.0.1" }, "funding": [ { @@ -13759,7 +13759,7 @@ "type": "tidelift" } ], - "time": "2023-11-29T08:40:23+00:00" + "time": "2023-11-30T11:38:21+00:00" }, { "name": "symfony/yaml", diff --git a/conf/cmi/core.entity_form_display.node.landing_page.default.yml b/conf/cmi/core.entity_form_display.node.landing_page.default.yml index 416a968a..7948b74e 100644 --- a/conf/cmi/core.entity_form_display.node.landing_page.default.yml +++ b/conf/cmi/core.entity_form_display.node.landing_page.default.yml @@ -128,9 +128,9 @@ content: third_party_settings: { } simple_sitemap: weight: 10 + region: content settings: { } third_party_settings: { } - region: content status: type: boolean_checkbox weight: 12 diff --git a/docker/openshift/Dockerfile b/docker/openshift/Dockerfile index 25b26fa5..6f82194d 100644 --- a/docker/openshift/Dockerfile +++ b/docker/openshift/Dockerfile @@ -9,6 +9,7 @@ RUN composer install --no-progress --profile --prefer-dist --no-interaction --no COPY docker/openshift/entrypoints/ /entrypoints RUN chmod +x /entrypoints/* +COPY docker/openshift/init.sh / # Copy cron scripts RUN mkdir /crons diff --git a/docker/openshift/crons/migrate-status.php b/docker/openshift/crons/migrate-status.php deleted file mode 100644 index 8cb5aaa2..00000000 --- a/docker/openshift/crons/migrate-status.php +++ /dev/null @@ -1,82 +0,0 @@ -format('U'); - } - catch (\Exception $e) { - } - return 0; -} - -if (php_sapi_name() !== 'cli') { - throw new RuntimeException(); -} - -if (!isset($argv[2], $argv[1])) { - throw new RuntimeException('Missing argument.'); -} - -$migrations = explode(',', $argv[1]); -$data = $argv[2]; -// Default to 6 hours. -$time = $argv[3] ?? 21600; - -if (is_file($data)) { - $data = file_get_contents($data); -} - -if (!($json = json_decode($data)) || !is_array($json)) { - throw new RuntimeException('Given argument is not a valid json'); -} - -$reset_status = []; -$skip_migrate = []; - -foreach ($json as $migration) { - if (!in_array($migration->id, $migrations)) { - continue; - } - // Reset migration status. - if ($migration->status !== 'Idle') { - $reset_status[] = $migration->id; - } - - $last_imported = unix_time($migration->last_imported) + $time; - - // Skip migration. - if ($last_imported && $last_imported > time()) { - $skip_migrate[] = $migration->id; - } -} - -output_variable('RESET_STATUS', implode(' ', $reset_status)); -output_variable('SKIP_MIGRATE', implode(' ', $skip_migrate)); diff --git a/docker/openshift/crons/migrate-tpr.sh b/docker/openshift/crons/migrate-tpr.sh index 08006f13..780bcbbf 100644 --- a/docker/openshift/crons/migrate-tpr.sh +++ b/docker/openshift/crons/migrate-tpr.sh @@ -1,68 +1,12 @@ #!/bin/bash -function populate_variables { - # Generate variables used to control which migrates needs - # to be reset and which ones needs to be skipped based on - # migrate status - MIGRATE_STATUS=$(drush migrate:status --format=json) - php ./docker/openshift/crons/migrate-status.php \ - tpr_unit,tpr_service,tpr_errand_service,tpr_service_channel \ - "$MIGRATE_STATUS" > /tmp/migrate-tpr-source.sh \ - $1 - - # Contains variables: - # - $RESET_STATUS - # - $SKIP_MIGRATE - # Both contains a space separated list of migrates - source /tmp/migrate-tpr-source.sh -} - -function reset_status { - # Reset status of stuck migrations. - for ID in $RESET_STATUS; do - drush migrate:reset-status $ID - done -} - -function run_migrate { - for ID in $SKIP_MIGRATE; do - if [ "$ID" == "$1" ]; then - return 1 - fi - done - return 0 -} - -# Populate variables for the first run after deploy and -# default migrate interval to 6 hours. -populate_variables 21600 - while true do - # Reset stuck migrates. - reset_status - - if run_migrate "tpr_unit"; then - echo "Running TPR Unit migrate: $(date)" - PARTIAL_MIGRATE=1 drush migrate:import tpr_unit --no-progress - fi - if run_migrate "tpr_service"; then - echo "Running TPR Service migrate: $(date)" - PARTIAL_MIGRATE=1 drush migrate:import tpr_service --no-progress - fi - if run_migrate "tpr_errand_service"; then - echo "Running TPR Errand Service migrate: $(date)" - PARTIAL_MIGRATE=1 drush migrate:import tpr_errand_service --no-progress - fi - if run_migrate "tpr_service_channel"; then - echo "Running TPR Service Channel migrate: $(date)" - PARTIAL_MIGRATE=1 drush migrate:import tpr_service_channel --no-progress - fi - # Reset migrate status if migrate has been running for more - # than 12 hours. - populate_variables 43200 - # Never skip migrate after first time. - SKIP_MIGRATE= + # Allow migrations to be run every 3 hours and reset stuck migrations every 12 hours. + drush migrate:import tpr_unit --no-progress --reset-threshold 43200 --interval 10800 + drush migrate:import tpr_service --no-progress --reset-threshold 43200 --interval 10800 + drush migrate:import tpr_errand_service --no-progress --reset-threshold 43200 --interval 10800 + drush migrate:import tpr_service_channel --no-progress --reset-threshold 43200 --interval 10800 # Sleep for 6 hours. sleep 21600 done diff --git a/docker/openshift/entrypoints/10-preflight.sh b/docker/openshift/entrypoints/10-preflight.sh new file mode 100644 index 00000000..5cd45c01 --- /dev/null +++ b/docker/openshift/entrypoints/10-preflight.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +source /init.sh + +if [ -f "../docker/openshift/preflight/preflight.php" ]; then + echo "Running preflight checks ..." + php ../docker/openshift/preflight/preflight.php +fi + diff --git a/docker/openshift/entrypoints/20-deploy.sh b/docker/openshift/entrypoints/20-deploy.sh index c4051265..6a098241 100644 --- a/docker/openshift/entrypoints/20-deploy.sh +++ b/docker/openshift/entrypoints/20-deploy.sh @@ -1,25 +1,11 @@ #!/bin/bash -cd /var/www/html/public +source /init.sh -function output_error_message { - echo ${1} - php ../docker/openshift/notify.php "${1}" || true -} - -# Make sure we have active Drupal configuration. -if [ ! -f "../conf/cmi/system.site.yml" ]; then - output_error_message "Container start error: Codebase is not deployed properly. Exiting early." +function rollback_deployment { + output_error_message "Deployment failed: ${1}" + set_deploy_id ${2} exit 1 -fi - -if [ ! -n "$OPENSHIFT_BUILD_NAME" ]; then - output_error_message "Container start error: OPENSHIFT_BUILD_NAME is not defined. Exiting early." - exit 1 -fi - -function get_deploy_id { - echo $(drush state:get deploy_id) } # Populate twig caches. @@ -27,54 +13,42 @@ if [ ! -d "/tmp/twig" ]; then drush twig:compile || true fi -# Attempt to set deploy ID in case this is the first deploy. -if [[ -z "$(get_deploy_id)" ]]; then - drush state:set deploy_id $OPENSHIFT_BUILD_NAME -fi - -# Exit early if deploy ID is still not set. This usually means either Redis or -# something else is down. -if [[ -z "$(get_deploy_id)" ]]; then - output_error_message "Container start error: Could not fetch deploy ID. Exiting early." - exit 1 -fi +# Capture the current deploy ID so we can roll back to previous version in case +# deployment fails. +CURRENT_DEPLOY_ID=$(get_deploy_id) # This script is run every time a container is spawned and certain environments might # start more than one Drupal container. This is used to make sure we run deploy # tasks only once per deploy. -if [ "$(get_deploy_id)" != "$OPENSHIFT_BUILD_NAME" ]; then - drush state:set deploy_id $OPENSHIFT_BUILD_NAME +if [ "$CURRENT_DEPLOY_ID" != "$OPENSHIFT_BUILD_NAME" ]; then + set_deploy_id $OPENSHIFT_BUILD_NAME if [ $? -ne 0 ]; then - output_error_message "Deployment failed: Failed set deploy_id" - exit 1 + rollback_deployment "Failed to set deploy_id" $CURRENT_DEPLOY_ID fi # Put site in maintenance mode drush state:set system.maintenance_mode 1 --input-format=integer if [ $? -ne 0 ]; then - output_error_message "Deployment failed: Failed to enable maintenance_mode" - exit 1 + rollback_deployment "Failed to enable maintenance_mode" $CURRENT_DEPLOY_ID fi - # Run helfi specific pre-deploy tasks. Allow this to fail in case - # the environment is not using the 'helfi_api_base' module. - # @see https://github.com/City-of-Helsinki/drupal-module-helfi-api-base + # Run pre-deploy tasks. + # @see https://github.com/City-of-Helsinki/drupal-module-helfi-api-base/blob/main/documentation/deploy-hooks.md drush helfi:pre-deploy || true # Run maintenance tasks (config import, database updates etc) drush deploy if [ $? -ne 0 ]; then - output_error_message "Deployment failed: drush deploy failed with {$?} exit code. See logs for more information." + rollback_deployment "drush deploy failed with {$?} exit code. See logs for more information." $CURRENT_DEPLOY_ID exit 1 fi - # Run helfi specific post deploy tasks. Allow this to fail in case - # the environment is not using the 'helfi_api_base' module. - # @see https://github.com/City-of-Helsinki/drupal-module-helfi-api-base + # Run post-deploy tasks. + # @see https://github.com/City-of-Helsinki/drupal-module-helfi-api-base/blob/main/documentation/deploy-hooks.md drush helfi:post-deploy || true # Disable maintenance mode drush state:set system.maintenance_mode 0 --input-format=integer if [ $? -ne 0 ]; then - output_error_message "Deployment failure: Failed to disable maintenance_mode" + rollback_deployment "Failed to disable maintenance_mode" $CURRENT_DEPLOY_ID fi fi diff --git a/docker/openshift/init.sh b/docker/openshift/init.sh new file mode 100644 index 00000000..8bef1380 --- /dev/null +++ b/docker/openshift/init.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +cd /var/www/html/public + +function get_deploy_id { + if [ ! -f "sites/default/files/deploy.id" ]; then + touch sites/default/files/deploy.id + fi + echo $(cat sites/default/files/deploy.id) +} + +function set_deploy_id { + echo ${1} > sites/default/files/deploy.id +} + +function output_error_message { + echo ${1} + php ../docker/openshift/notify.php "${1}" || true +} + +function deployment_in_progress { + if [ "$(get_deploy_id)" != "$OPENSHIFT_BUILD_NAME" ]; then + return 0 + fi + + if [ "$(drush state:get system.maintenance_mode)" = "1" ]; then + return 0 + fi + + return 1 +} + +if [ ! -d "sites/default/files" ]; then + output_error_message "Container start error: Public file folder does not exist. Exiting early." + exit 1 +fi + +# Make sure we have active Drupal configuration. +if [ ! -f "../conf/cmi/system.site.yml" ]; then + output_error_message "Container start error: Codebase is not deployed properly. Exiting early." + exit 1 +fi + +if [ ! -n "$OPENSHIFT_BUILD_NAME" ]; then + output_error_message "Container start error: OPENSHIFT_BUILD_NAME is not defined. Exiting early." + exit 1 +fi + diff --git a/docker/openshift/preflight/preflight.php b/docker/openshift/preflight/preflight.php new file mode 100644 index 00000000..35219bb8 --- /dev/null +++ b/docker/openshift/preflight/preflight.php @@ -0,0 +1,100 @@ +#!/usr/bin/env php + [ + 'DRUPAL_ROUTES', + 'DRUPAL_DB_NAME', + 'DRUPAL_DB_PASS', + 'DRUPAL_DB_HOST', + ], + 'additionalFiles' => [], +]; + // Environment specific overrides. if (file_exists(__DIR__ . '/all.settings.php')) { // phpcs:ignore @@ -349,3 +364,4 @@ function drupal_get_env(string|array $variables) : mixed { if (empty($settings['deployment_identifier'])) { $settings['deployment_identifier'] = filemtime(__DIR__ . '/../../../composer.lock'); } +