From 961f7f18d67ae121b9b01069b0004b2233cee64a Mon Sep 17 00:00:00 2001 From: Niels Abildgaard Date: Tue, 12 Mar 2024 21:50:05 +0100 Subject: [PATCH] Ensure first deploy is run for all relevant branches when running sites:sync task --- docs/runbooks/add-library-site-to-platform.md | 11 --------- docs/runbooks/deploy-a-release.md | 5 ++++ infrastructure/Taskfile.yml | 24 +++++++++++++++---- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/docs/runbooks/add-library-site-to-platform.md b/docs/runbooks/add-library-site-to-platform.md index b33dda64..62cbe619 100644 --- a/docs/runbooks/add-library-site-to-platform.md +++ b/docs/runbooks/add-library-site-to-platform.md @@ -118,17 +118,6 @@ $ task sites:sync # You may be prompted to confirm Terraform plan execution and approve other critical steps. # Read and consider these messages carefully and ensure you are not needlessly changing # other sites. - - -#TODO: move first deploys to Taskfile -# 3.a Trigger a deployment manually, this will fail as the repository is empty -# but will serve to prepare Lagoon for future deployments. -# lagoon deploy branch -p -b -$ lagoon deploy branch -p core-test1 -b main - -# 3.b If you are setting up a site with `plan: webmaster`, you also need to -# deploy the moduletest branch -$ lagoon deploy branch -p core-test1 -b moduletest ``` If you want to deploy a release to the site, continue to diff --git a/docs/runbooks/deploy-a-release.md b/docs/runbooks/deploy-a-release.md index 4c1c957d..d93802cf 100644 --- a/docs/runbooks/deploy-a-release.md +++ b/docs/runbooks/deploy-a-release.md @@ -23,6 +23,11 @@ environment for custom Drupal modules will also be synced appropriately. ## Procedure ```sh +# 0. The easiest way to sync all sites is to run this single command: +task sites:sync + +# Alternatively you can go through more granular sync'ing of individual sites... + # 1. Make any changes to the sites entry sites.yml you need. # 2. (optional) diff the deployment DIFF=1 SITE= task site:sync diff --git a/infrastructure/Taskfile.yml b/infrastructure/Taskfile.yml index e23cee9a..eb6d0d47 100644 --- a/infrastructure/Taskfile.yml +++ b/infrastructure/Taskfile.yml @@ -773,13 +773,10 @@ tasks: SITE="$site" task site:lagoon:project:capture-deploy-key done - task: env_repos:provision - - | - echo "TODO: figure out which sites are newly created and require a first deploy\ - and run lagoon deploy for them - and for plan:webmaster run deploy of\ - moduletest, too" - | set -e cat sites.yaml | yq '.sites | keys | .[]' | while read -r site; do + SITE="$site" task site:lagoon:ensure-first-deployment SITE="$site" task site:sync done @@ -822,6 +819,25 @@ tasks: - sh: "[ ! -z {{.SITE}} ]" msg: "Env variable SITE is not set or empty." + site:lagoon:ensure-first-deployment: + desc: Ensures that a site has at least one deployment on required branches, so they are tracked by Lagoon + deps: [lagoon:cli:config] + dir: "{{.dir_env}}" + env: + SITE: "{{.SITE}}" + cmds: + - | + if [ "$(lagoon list deployments --project "{{.SITE}}" --environment main --output-json | jq '.data | length')" = "0" ]; then + lagoon deploy branch --project "{{.SITE}}" --branch "main"; + fi + - | + if [ "$(yq '.sites[env(SITE)].plan' sites.yaml)" = "webmaster" -a "$(lagoon list deployments --project "{{.SITE}}" --environment moduletest --output-json | jq '.data | length')" = "0" ]; then + lagoon deploy branch --project "{{.SITE}}" --branch "moduletest"; + fi + preconditions: + - sh: "[ ! -z {{.SITE}} ]" + msg: "Env variable SITE is not set or empty." + ui-password: desc: Get the password to access a given user interface cmds: