From 83e8339e958ba55e74ae54dcb3268d331ac751a4 Mon Sep 17 00:00:00 2001 From: actions-bot Date: Fri, 1 Dec 2023 12:42:59 +0000 Subject: [PATCH] Update configuration --- .platform/schema | 2 +- composer.lock | 12 +- ...form_display.node.announcement.default.yml | 16 +-- ...ty_form_display.node.news_item.default.yml | 43 +------- ...ty_view_display.node.news_item.default.yml | 39 +------ ...ity_view_display.node.news_item.teaser.yml | 2 +- ...raphs.paragraphs_type.popular_services.yml | 2 +- ...raphs.paragraphs_type.popular_services.yml | 2 +- ...raphs.paragraphs_type.popular_services.yml | 2 +- docker/openshift/Dockerfile | 1 + docker/openshift/crons/migrate-status.php | 82 -------------- docker/openshift/crons/migrate-tpr.sh | 66 +---------- docker/openshift/entrypoints/10-preflight.sh | 9 ++ docker/openshift/entrypoints/20-deploy.sh | 60 +++------- docker/openshift/init.sh | 48 ++++++++ docker/openshift/preflight/preflight.php | 103 ++++++++++++++++++ public/sites/default/settings.php | 16 +++ 17 files changed, 225 insertions(+), 280 deletions(-) delete mode 100644 docker/openshift/crons/migrate-status.php create mode 100644 docker/openshift/entrypoints/10-preflight.sh create mode 100644 docker/openshift/init.sh create mode 100644 docker/openshift/preflight/preflight.php diff --git a/.platform/schema b/.platform/schema index e440e5c84..bf0d87ab1 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 a57385142..37bacaf05 100644 --- a/composer.lock +++ b/composer.lock @@ -3927,16 +3927,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": { @@ -3954,10 +3954,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", diff --git a/conf/cmi/core.entity_form_display.node.announcement.default.yml b/conf/cmi/core.entity_form_display.node.announcement.default.yml index 0cc1059bd..67510a4b6 100644 --- a/conf/cmi/core.entity_form_display.node.announcement.default.yml +++ b/conf/cmi/core.entity_form_display.node.announcement.default.yml @@ -28,7 +28,7 @@ mode: default content: body: type: text_textarea_with_summary - weight: 17 + weight: 18 region: content settings: rows: 9 @@ -51,7 +51,7 @@ content: third_party_settings: { } field_announcement_content_pages: type: select2_entity_reference - weight: 15 + weight: 14 region: content settings: width: 100% @@ -61,7 +61,7 @@ content: third_party_settings: { } field_announcement_link: type: link_default - weight: 18 + weight: 19 region: content settings: placeholder_url: '' @@ -79,7 +79,7 @@ content: third_party_settings: { } field_announcement_title: type: string_textfield - weight: 16 + weight: 17 region: content settings: size: 60 @@ -102,13 +102,6 @@ content: match_operator: CONTAINS match_limit: 20 third_party_settings: { } - field_publish_externally: - type: boolean_checkbox - weight: 14 - region: content - settings: - display_label: true - third_party_settings: { } langcode: type: language_select weight: 1 @@ -181,6 +174,7 @@ content: settings: { } third_party_settings: { } hidden: + field_publish_externally: true hide_sidebar_navigation: true promote: true sticky: true diff --git a/conf/cmi/core.entity_form_display.node.news_item.default.yml b/conf/cmi/core.entity_form_display.node.news_item.default.yml index c374ffd56..74e96e26e 100644 --- a/conf/cmi/core.entity_form_display.node.news_item.default.yml +++ b/conf/cmi/core.entity_form_display.node.news_item.default.yml @@ -23,7 +23,6 @@ dependencies: - paragraphs - path - publication_date - - radioactivity - scheduler - select2 third_party_settings: @@ -69,18 +68,11 @@ third_party_settings: format_type: details format_settings: classes: '' - show_empty_fields: true + show_empty_fields: false id: '' open: false description: '' - required_fields: false - element: div - show_label: '0' - label_element: h3 - label_element_classes: '' - attributes: '' - effect: none - speed: fast + required_fields: true _core: default_config_hash: RHDFf9pvwgV2FvoelXlH7dXXBoWkziCZI1FWuQS94k8 id: node.news_item.default @@ -136,16 +128,6 @@ content: rows: 5 placeholder: '' third_party_settings: { } - field_news_groups: - type: select2_entity_reference - weight: 26 - region: content - settings: - width: 100% - autocomplete: false - match_operator: CONTAINS - match_limit: 10 - third_party_settings: { } field_news_item_links_link: type: linkit weight: 20 @@ -153,7 +135,7 @@ content: settings: placeholder_url: '' placeholder_title: '' - linkit_profile: tpr_content + linkit_profile: helfi linkit_auto_link_text: true third_party_settings: { } field_news_item_links_title: @@ -174,22 +156,6 @@ content: match_operator: CONTAINS match_limit: 10 third_party_settings: { } - field_news_neighbourhoods: - type: select2_entity_reference - weight: 27 - region: content - settings: - width: 100% - autocomplete: false - match_operator: CONTAINS - match_limit: 10 - third_party_settings: { } - field_radioactivity: - type: radioactivity_reference - weight: 28 - region: content - settings: { } - third_party_settings: { } field_short_title: type: string_textfield weight: 2 @@ -289,4 +255,7 @@ content: settings: { } third_party_settings: { } hidden: + field_news_groups: true + field_news_neighbourhoods: true + field_radioactivity: true hide_sidebar_navigation: true diff --git a/conf/cmi/core.entity_view_display.node.news_item.default.yml b/conf/cmi/core.entity_view_display.node.news_item.default.yml index 9cb118539..e05334d3e 100644 --- a/conf/cmi/core.entity_view_display.node.news_item.default.yml +++ b/conf/cmi/core.entity_view_display.node.news_item.default.yml @@ -19,7 +19,6 @@ dependencies: - entity_reference_revisions - helfi_platform_config - link - - radioactivity - user _core: default_config_hash: fHNnwg186A981K7d578If1MCkuYBmQqaxabpDSAZwIc @@ -60,14 +59,6 @@ content: third_party_settings: { } weight: 8 region: content - field_news_groups: - type: entity_reference_label - label: above - settings: - link: false - third_party_settings: { } - weight: 10 - region: content field_news_item_links_link: type: link label: hidden @@ -88,32 +79,6 @@ content: third_party_settings: { } weight: 6 region: content - field_news_item_tags: - type: entity_reference_label - label: above - settings: - link: false - third_party_settings: { } - weight: 11 - region: content - field_news_neighbourhoods: - type: entity_reference_label - label: above - settings: - link: false - third_party_settings: { } - weight: 12 - region: content - field_radioactivity: - type: radioactivity_reference_emitter - label: above - settings: - energy: 10.0 - display: false - decimals: 0.0 - third_party_settings: { } - weight: 9 - region: content field_short_title: type: string label: hidden @@ -147,6 +112,10 @@ content: weight: 3 region: content hidden: + field_news_groups: true + field_news_item_tags: true + field_news_neighbourhoods: true + field_radioactivity: true langcode: true search_api_excerpt: true toc_enabled: true diff --git a/conf/cmi/core.entity_view_display.node.news_item.teaser.yml b/conf/cmi/core.entity_view_display.node.news_item.teaser.yml index 640bf4326..38c929cb5 100644 --- a/conf/cmi/core.entity_view_display.node.news_item.teaser.yml +++ b/conf/cmi/core.entity_view_display.node.news_item.teaser.yml @@ -29,7 +29,7 @@ content: type: entity_reference_entity_view label: hidden settings: - view_mode: image + view_mode: media_library link: false third_party_settings: { } weight: 1 diff --git a/conf/cmi/language/fi/paragraphs.paragraphs_type.popular_services.yml b/conf/cmi/language/fi/paragraphs.paragraphs_type.popular_services.yml index e19e47b26..3f05477bd 100644 --- a/conf/cmi/language/fi/paragraphs.paragraphs_type.popular_services.yml +++ b/conf/cmi/language/fi/paragraphs.paragraphs_type.popular_services.yml @@ -1,2 +1,2 @@ -label: 'Suositut palvelut (tuettu muilla kielillä)' +label: 'Suositut palvelut' description: 'Esittele suosittuja palveluita.' diff --git a/conf/cmi/language/sv/paragraphs.paragraphs_type.popular_services.yml b/conf/cmi/language/sv/paragraphs.paragraphs_type.popular_services.yml index f377f18c1..4a2f7cd5f 100644 --- a/conf/cmi/language/sv/paragraphs.paragraphs_type.popular_services.yml +++ b/conf/cmi/language/sv/paragraphs.paragraphs_type.popular_services.yml @@ -1,2 +1,2 @@ -label: 'Popular services (stöds på andra språk)' +label: 'Populära tjänster' description: 'Introducera populära tjänster.' diff --git a/conf/cmi/paragraphs.paragraphs_type.popular_services.yml b/conf/cmi/paragraphs.paragraphs_type.popular_services.yml index 3425c985a..560c41dde 100644 --- a/conf/cmi/paragraphs.paragraphs_type.popular_services.yml +++ b/conf/cmi/paragraphs.paragraphs_type.popular_services.yml @@ -5,7 +5,7 @@ dependencies: { } _core: default_config_hash: GHPwCLPig7XSKliVrahWkQsE6i0gVcqJnKnYIa4OGq4 id: popular_services -label: 'Popular services (supported in other languages)' +label: 'Popular services' icon_uuid: null icon_default: null description: 'Showcase popular services' diff --git a/docker/openshift/Dockerfile b/docker/openshift/Dockerfile index 25b26fa5f..6f82194d4 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 8cb5aaa23..000000000 --- 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 08006f135..780bcbbf5 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 000000000..5cd45c010 --- /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 c40512651..6a0982412 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 000000000..8bef13803 --- /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 000000000..b3eb762e7 --- /dev/null +++ b/docker/openshift/preflight/preflight.php @@ -0,0 +1,103 @@ +#!/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'); } +