From 7cf0277fc99ff895c0c200023b001f70fdfa42ee Mon Sep 17 00:00:00 2001 From: Niels Abildgaard Date: Fri, 3 May 2024 15:29:21 +0200 Subject: [PATCH] Add support for `importTranslationsCron` in sites.yaml, set for cms-school This allows us to define custom schedules for when translations should be imported. For cms-school we set it to hourly, so we get more frequent data updates here in particular. --- infrastructure/dpladm/bin/dpladm-shared.source | 16 ++++++++++------ infrastructure/dpladm/bin/sync-site.sh | 18 ++++++++++++++++-- .../env-repo-template/standard/.lagoon.yml | 4 ++-- .../environments/dplplat01/sites.yaml | 1 + 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/infrastructure/dpladm/bin/dpladm-shared.source b/infrastructure/dpladm/bin/dpladm-shared.source index e369accc..31848c34 100755 --- a/infrastructure/dpladm/bin/dpladm-shared.source +++ b/infrastructure/dpladm/bin/dpladm-shared.source @@ -66,10 +66,12 @@ function renderProfileTemplate { local releaseImageRepository=$3 # Name of the container-image that contains the built release local releaseImageName=$4 + # Cron schedule for importing translations + local importTranslationsCron=$5 # The primary domain of the site (optional) - local primaryDomain=${5:-} + local primaryDomain=${6:-} # A space-seperated list of secondary domains (optional) - local secondaryDomainsString=${6:-} + local secondaryDomainsString=${7:-} PRIMARY_DOMAIN="" ENABLE_ROUTES="" @@ -112,12 +114,13 @@ EndOfMessage export LAGOON_IMAGES_RELEASE_TAG export PRIMARY_DOMAIN export SECONDARY_DOMAINS + export IMPORT_TRANSLATIONS_CRON=${importTranslationsCron} # TODO this templating could be quite a bit more flexible. # Tell envsubst which variables to replace. This allows other variables to # remain untouched. # shellcheck disable=SC2016 - local variablesToSubst='$RELEASE_IMAGE_REPOSITORY $RELEASE_IMAGE_NAME $RELEASE_TAG $ENABLE_ROUTES $LAGOON_IMAGES_RELEASE_TAG $LAGOON_PROJECT_NAME $PRIMARY_DOMAIN $SECONDARY_DOMAINS' + local variablesToSubst='$RELEASE_IMAGE_REPOSITORY $RELEASE_IMAGE_NAME $RELEASE_TAG $ENABLE_ROUTES $LAGOON_IMAGES_RELEASE_TAG $LAGOON_PROJECT_NAME $PRIMARY_DOMAIN $SECONDARY_DOMAINS $IMPORT_TRANSLATIONS_CRON' # Loop through the files we know to contain variables that needs replacing. local templateFiles=( @@ -142,8 +145,9 @@ function syncEnvRepo { local branchName=$3 local releaseImageRepository=$4 local releaseImageName=$5 - local primaryDomain="${6:-}" - local secondaryDomains="${7:-}" + local importTranslationsCron=$6 + local primaryDomain="${7:-}" + local secondaryDomains="${8:-}" # TODO, preflight checks that verifies this repository looks good to go. # makes most sense to do when we're doing more complicated things inside @@ -176,7 +180,7 @@ function syncEnvRepo { # Enter the template and rendered it cd "${repoName}" - renderProfileTemplate "${siteName}" "${releaseTag}" "${releaseImageRepository}" "${releaseImageName}" "${primaryDomain}" "${secondaryDomains}" + renderProfileTemplate "${siteName}" "${releaseTag}" "${releaseImageRepository}" "${releaseImageName}" "${importTranslationsCron}" "${primaryDomain}" "${secondaryDomains}" # Detect changes local changedFiles diff --git a/infrastructure/dpladm/bin/sync-site.sh b/infrastructure/dpladm/bin/sync-site.sh index 9597d785..5bf39d39 100755 --- a/infrastructure/dpladm/bin/sync-site.sh +++ b/infrastructure/dpladm/bin/sync-site.sh @@ -113,6 +113,19 @@ function getSiteSecondaryDomains { return } +function getSiteImportTranslationsCron { + local importTranslationsCron + importTranslationsCron=$(yq eval ".sites.${1}.importTranslationsCron" "${2}") + + if [[ "${importTranslationsCron}" == "null" ]]; then + echo "M H(2-5) * * *" + return + fi + + echo "${importTranslationsCron}" + return +} + if [[ -z "${SITES_CONFIG:-}" ]]; then print_usage "SITES_CONFIG" fi @@ -148,11 +161,12 @@ failOnErr $? "${siteImageRepository}" siteReleaseImageName=$(getSiteReleaseImageName "${SITE}" "${SITES_CONFIG}") failOnErr $? "${siteReleaseImageName}" plan=$(getSitePlan "${SITE}" "${SITES_CONFIG}") +importTranslationsCron=$(getSiteImportTranslationsCron "${SITE}" "${SITES_CONFIG}") set -o errexit # Synchronise the sites environment repository. -syncEnvRepo "${SITE}" "${releaseTag}" "${BRANCH}" "${siteImageRepository}" "${siteReleaseImageName}" "${primaryDomain}" "${secondaryDomains}" +syncEnvRepo "${SITE}" "${releaseTag}" "${BRANCH}" "${siteImageRepository}" "${siteReleaseImageName}" "${importTranslationsCron}" "${primaryDomain}" "${secondaryDomains}" if [ "${plan}" = "webmaster" ] && [ "${BRANCH}" = "main" ]; then - syncEnvRepo "${SITE}" "${releaseTag}" "moduletest" "${siteImageRepository}" "${siteReleaseImageName}" + syncEnvRepo "${SITE}" "${releaseTag}" "moduletest" "${siteImageRepository}" "${siteReleaseImageName}" "${importTranslationsCron}" fi diff --git a/infrastructure/dpladm/env-repo-template/standard/.lagoon.yml b/infrastructure/dpladm/env-repo-template/standard/.lagoon.yml index a5d24965..11fd2e96 100644 --- a/infrastructure/dpladm/env-repo-template/standard/.lagoon.yml +++ b/infrastructure/dpladm/env-repo-template/standard/.lagoon.yml @@ -64,11 +64,11 @@ $SECONDARY_DOMAINS command: drush cron service: cli - name: import translations - schedule: "M H(2-5) * * *" + schedule: "${IMPORT_TRANSLATIONS_CRON}" command: drush locale-check && drush locale-update service: cli - name: import danish config translations - schedule: "M H(2-5) * * *" + schedule: "${IMPORT_TRANSLATIONS_CRON}" command: drush dpl_po:import-remote-config-po da https://danskernesdigitalebibliotek.github.io/dpl-cms/translations/da.config.po service: cli diff --git a/infrastructure/environments/dplplat01/sites.yaml b/infrastructure/environments/dplplat01/sites.yaml index c3b7edd5..51089883 100644 --- a/infrastructure/environments/dplplat01/sites.yaml +++ b/infrastructure/environments/dplplat01/sites.yaml @@ -24,6 +24,7 @@ sites: releaseImageRepository: ghcr.io/danskernesdigitalebibliotek releaseImageName: dpl-cms-source dpl-cms-release: "2024.18.3" + importTranslationsCron: "0 * * * *" deploy_key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJ6SzfPFf/XeLeqI342kxuJAlATpDMtgAfqlrLTTbW2m" customizable-canary: name: "Customizable bibliotek - eksempel"