Skip to content

Commit

Permalink
Add support for importTranslationsCron in sites.yaml, set for cms-s…
Browse files Browse the repository at this point in the history
…chool

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.
  • Loading branch information
hypesystem committed May 3, 2024
1 parent 58f472b commit 7cf0277
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
16 changes: 10 additions & 6 deletions infrastructure/dpladm/bin/dpladm-shared.source
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand Down Expand Up @@ -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=(
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 16 additions & 2 deletions infrastructure/dpladm/bin/sync-site.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions infrastructure/dpladm/env-repo-template/standard/.lagoon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions infrastructure/environments/dplplat01/sites.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 7cf0277

Please sign in to comment.