Skip to content

Commit

Permalink
Update configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-bot authored Dec 4, 2023
1 parent ee5f8d0 commit ba55eed
Show file tree
Hide file tree
Showing 11 changed files with 276 additions and 266 deletions.
2 changes: 1 addition & 1 deletion .platform/schema
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3
4
156 changes: 78 additions & 78 deletions composer.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docker/openshift/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
82 changes: 0 additions & 82 deletions docker/openshift/crons/migrate-status.php

This file was deleted.

66 changes: 5 additions & 61 deletions docker/openshift/crons/migrate-tpr.sh
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions docker/openshift/entrypoints/10-preflight.sh
Original file line number Diff line number Diff line change
@@ -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

60 changes: 17 additions & 43 deletions docker/openshift/entrypoints/20-deploy.sh
Original file line number Diff line number Diff line change
@@ -1,80 +1,54 @@
#!/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.
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
48 changes: 48 additions & 0 deletions docker/openshift/init.sh
Original file line number Diff line number Diff line change
@@ -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

Loading

0 comments on commit ba55eed

Please sign in to comment.