From e265e5e710ce1e2de8d1b19b1a2e3fc65532e785 Mon Sep 17 00:00:00 2001 From: Alex Skrypnyk Date: Tue, 27 Aug 2024 13:34:33 +1000 Subject: [PATCH] Updated Lagoon deployment script to use long-form options. --- .scaffold/tests/bats/deployment1.bats | 18 +++++++++--------- scripts/drevops/deploy-lagoon.sh | 26 +++++++++++++------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/.scaffold/tests/bats/deployment1.bats b/.scaffold/tests/bats/deployment1.bats index dbdce4d58..d4ba38146 100644 --- a/.scaffold/tests/bats/deployment1.bats +++ b/.scaffold/tests/bats/deployment1.bats @@ -186,11 +186,11 @@ load _helper.deployment.bash assert_equal 3 "$(mock_get_call_num "${mock_lagoon}")" # Configure. - assert_contains "config add --force -l testlagoon -g https://api.lagoon.amazeeio.cloud/graphql -H ssh.lagoon.amazeeio.cloud -P 32222" "$(mock_get_call_args "${mock_lagoon}" 1)" + assert_contains "config add --force --lagoon testlagoon --graphql https://api.lagoon.amazeeio.cloud/graphql --hostname ssh.lagoon.amazeeio.cloud --port 32222" "$(mock_get_call_args "${mock_lagoon}" 1)" # Get a list of environments. - assert_contains "-l testlagoon -p testproject list environments --output-json --pretty" "$(mock_get_call_args "${mock_lagoon}" 2)" + assert_contains "--lagoon testlagoon --project testproject list environments --output-json --pretty" "$(mock_get_call_args "${mock_lagoon}" 2)" # Trigger a deployment. - assert_contains "-l testlagoon -p testproject deploy branch -b testbranch" "$(mock_get_call_args "${mock_lagoon}" 3)" + assert_contains "--lagoon testlagoon --project testproject deploy branch --branch testbranch" "$(mock_get_call_args "${mock_lagoon}" 3)" # Assert that no other deployments ran. assert_output_not_contains "Started ARTIFACT deployment." @@ -307,17 +307,17 @@ load _helper.deployment.bash assert_equal 6 "$(mock_get_call_num "${mock_lagoon}")" # Configure. - assert_contains "config add --force -l testlagoon -g https://api.lagoon.amazeeio.cloud/graphql -H ssh.lagoon.amazeeio.cloud -P 32222" "$(mock_get_call_args "${mock_lagoon}" 1)" + assert_contains "config add --force --lagoon testlagoon --graphql https://api.lagoon.amazeeio.cloud/graphql --hostname ssh.lagoon.amazeeio.cloud --port 32222" "$(mock_get_call_args "${mock_lagoon}" 1)" # Get a list of environments. - assert_contains "-l testlagoon -p testproject list environments --output-json --pretty" "$(mock_get_call_args "${mock_lagoon}" 2)" + assert_contains "--lagoon testlagoon --project testproject list environments --output-json --pretty" "$(mock_get_call_args "${mock_lagoon}" 2)" # Explicitly set DB overwrite flag to 0 due to a bug in Lagoon. - assert_contains "-l testlagoon -p testproject update variable -e testbranch -N DREVOPS_PROVISION_OVERRIDE_DB -V 0 -S global" "$(mock_get_call_args "${mock_lagoon}" 3)" + assert_contains "--lagoon testlagoon --project testproject update variable --environment testbranch --name DREVOPS_PROVISION_OVERRIDE_DB --value 0 --scope global" "$(mock_get_call_args "${mock_lagoon}" 3)" # Override DB during re-deployment. - assert_contains "-l testlagoon -p testproject update variable -e testbranch -N DREVOPS_PROVISION_OVERRIDE_DB -V 1 -S global" "$(mock_get_call_args "${mock_lagoon}" 4)" + assert_contains "--lagoon testlagoon --project testproject update variable --environment testbranch --name DREVOPS_PROVISION_OVERRIDE_DB --value 1 --scope global" "$(mock_get_call_args "${mock_lagoon}" 4)" # Redeploy. - assert_contains "-l testlagoon -p testproject deploy latest -e testbranch" "$(mock_get_call_args "${mock_lagoon}" 5)" + assert_contains "--lagoon testlagoon --project testproject deploy latest --environment testbranch" "$(mock_get_call_args "${mock_lagoon}" 5)" # Remove a DB import override flag for the current deployment. - assert_contains "-l testlagoon -p testproject update variable -e testbranch -N DREVOPS_PROVISION_OVERRIDE_DB -V 0 -S global" "$(mock_get_call_args "${mock_lagoon}" 6)" + assert_contains "--lagoon testlagoon --project testproject update variable --environment testbranch --name DREVOPS_PROVISION_OVERRIDE_DB --value 0 --scope global" "$(mock_get_call_args "${mock_lagoon}" 6)" # Assert that no other deployments ran. assert_output_not_contains "Started ARTIFACT deployment." diff --git a/scripts/drevops/deploy-lagoon.sh b/scripts/drevops/deploy-lagoon.sh index 940e851f1..d778d6ca6 100755 --- a/scripts/drevops/deploy-lagoon.sh +++ b/scripts/drevops/deploy-lagoon.sh @@ -109,15 +109,15 @@ for cmd in lagoon curl; do command -v ${cmd} >/dev/null || { note "Configuring Lagoon instance." #shellcheck disable=SC2218 -lagoon config add --force -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" -g "${DREVOPS_DEPLOY_LAGOON_INSTANCE_GRAPHQL}" -H "${DREVOPS_DEPLOY_LAGOON_INSTANCE_HOSTNAME}" -P "${DREVOPS_DEPLOY_LAGOON_INSTANCE_PORT}" +lagoon config add --force --lagoon "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" --graphql "${DREVOPS_DEPLOY_LAGOON_INSTANCE_GRAPHQL}" --hostname "${DREVOPS_DEPLOY_LAGOON_INSTANCE_HOSTNAME}" --port "${DREVOPS_DEPLOY_LAGOON_INSTANCE_PORT}" -lagoon() { command lagoon --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" -p "${LAGOON_PROJECT}" "$@"; } +lagoon() { command lagoon --force --skip-update-check --ssh-key "${DREVOPS_DEPLOY_SSH_FILE}" --lagoon "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" --project "${LAGOON_PROJECT}" "$@"; } # ACTION: 'destroy' # Explicitly specifying "destroy" action as a failsafe. if [ "${DREVOPS_DEPLOY_ACTION}" = "destroy" ]; then note "Destroying environment: project ${LAGOON_PROJECT}, branch: ${DREVOPS_DEPLOY_BRANCH}." - lagoon delete environment -e "${DREVOPS_DEPLOY_BRANCH}" || true + lagoon delete environment --environment "${DREVOPS_DEPLOY_BRANCH}" || true # ACTION: 'deploy' OR 'deploy_override_db' else @@ -144,17 +144,17 @@ else # Explicitly set DB overwrite flag to 0 due to a bug in Lagoon. # @see https://github.com/uselagoon/lagoon/issues/1922 - lagoon update variable -e "${deploy_pr_full}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 0 -S global || true + lagoon update variable --environment "${deploy_pr_full}" --name DREVOPS_PROVISION_OVERRIDE_DB --value 0 --scope global || true # Override DB during re-deployment. if [ "${DREVOPS_DEPLOY_ACTION}" = "deploy_override_db" ]; then note "Add a DB import override flag for the current deployment." # To update variable value, we need to remove it and add again. - lagoon update variable -e "${deploy_pr_full}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 1 -S global || true + lagoon update variable --environment "${deploy_pr_full}" --name DREVOPS_PROVISION_OVERRIDE_DB --value 1 --scope global || true fi note "Redeploying environment: project ${LAGOON_PROJECT}, PR: ${DREVOPS_DEPLOY_PR}." - lagoon deploy pullrequest -n "${DREVOPS_DEPLOY_PR}" -N "${DREVOPS_DEPLOY_PR_BASE_BRANCH}" -R "origin/${DREVOPS_DEPLOY_PR_BASE_BRANCH}" -H "${DREVOPS_DEPLOY_BRANCH}" -M "${DREVOPS_DEPLOY_PR_HEAD}" -t "${deploy_pr_full}" + lagoon deploy pullrequest --number "${DREVOPS_DEPLOY_PR}" --base-branch-name "${DREVOPS_DEPLOY_PR_BASE_BRANCH}" --base-branch-ref "origin/${DREVOPS_DEPLOY_PR_BASE_BRANCH}" --head-branch-name "${DREVOPS_DEPLOY_BRANCH}" --head-branch-ref "${DREVOPS_DEPLOY_PR_HEAD}" --title "${deploy_pr_full}" if [ "${DREVOPS_DEPLOY_ACTION:-}" = "deploy_override_db" ]; then note "Waiting for deployment to be queued." @@ -162,14 +162,14 @@ else note "Remove a DB import override flag for the current deployment." # Note that a variable will be read by Lagoon during queuing of the build. - lagoon update variable -e "${deploy_pr_full}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 0 -S global || true + lagoon update variable --environment "${deploy_pr_full}" --name DREVOPS_PROVISION_OVERRIDE_DB --value 0 --scope global || true fi # Deployment of the fresh environment. else # If PR deployments are not configured in Lagoon - it will filter it out and will not deploy. note "Deploying environment: project ${LAGOON_PROJECT}, PR: ${DREVOPS_DEPLOY_PR}." - lagoon deploy pullrequest -n "${DREVOPS_DEPLOY_PR}" -N "${DREVOPS_DEPLOY_PR_BASE_BRANCH}" -R "origin/${DREVOPS_DEPLOY_PR_BASE_BRANCH}" -H "${DREVOPS_DEPLOY_BRANCH}" -M "${DREVOPS_DEPLOY_PR_HEAD}" -t "${deploy_pr_full}" + lagoon deploy pullrequest --number "${DREVOPS_DEPLOY_PR}" --base-branch-name "${DREVOPS_DEPLOY_PR_BASE_BRANCH}" --base-branch-ref "origin/${DREVOPS_DEPLOY_PR_BASE_BRANCH}" --head-branch-name "${DREVOPS_DEPLOY_BRANCH}" --head-branch-ref "${DREVOPS_DEPLOY_PR_HEAD}" --title "${deploy_pr_full}" fi # Deploy branch. @@ -193,17 +193,17 @@ else # Explicitly set DB overwrite flag to 0 due to a bug in Lagoon. # @see https://github.com/uselagoon/lagoon/issues/1922 - lagoon update variable -e "${DREVOPS_DEPLOY_BRANCH}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 0 -S global || true + lagoon update variable --environment "${DREVOPS_DEPLOY_BRANCH}" --name DREVOPS_PROVISION_OVERRIDE_DB --value 0 --scope global || true # Override DB during re-deployment. if [ "${DREVOPS_DEPLOY_ACTION:-}" = "deploy_override_db" ]; then note "Add a DB import override flag for the current deployment." # To update variable value, we need to remove it and add again. - lagoon update variable -e "${DREVOPS_DEPLOY_BRANCH}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 1 -S global || true + lagoon update variable --environment "${DREVOPS_DEPLOY_BRANCH}" --name DREVOPS_PROVISION_OVERRIDE_DB --value 1 --scope global || true fi note "Redeploying environment: project ${LAGOON_PROJECT}, branch: ${DREVOPS_DEPLOY_BRANCH}." - lagoon deploy latest -e "${DREVOPS_DEPLOY_BRANCH}" || true + lagoon deploy latest --environment "${DREVOPS_DEPLOY_BRANCH}" || true if [ "${DREVOPS_DEPLOY_ACTION:-}" = "deploy_override_db" ]; then note "Waiting for deployment to be queued." @@ -211,14 +211,14 @@ else note "Remove a DB import override flag for the current deployment." # Note that a variable will be read by Lagoon during queuing of the build. - lagoon update variable -e "${DREVOPS_DEPLOY_BRANCH}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 0 -S global || true + lagoon update variable --environment "${DREVOPS_DEPLOY_BRANCH}" --name DREVOPS_PROVISION_OVERRIDE_DB --value 0 --scope global || true fi # Deployment of the fresh environment. else # If current branch deployments does not match a regex in Lagoon - it will filter it out and will not deploy. note "Deploying environment: project ${LAGOON_PROJECT}, branch: ${DREVOPS_DEPLOY_BRANCH}." - lagoon deploy branch -b "${DREVOPS_DEPLOY_BRANCH}" + lagoon deploy branch --branch "${DREVOPS_DEPLOY_BRANCH}" fi fi fi