Skip to content

Commit

Permalink
Updated Lagoon deployment script to use long-form options.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Aug 27, 2024
1 parent f0bbe9e commit e5832d8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
18 changes: 9 additions & 9 deletions .scaffold/tests/bats/deployment1.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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."
Expand Down
26 changes: 13 additions & 13 deletions scripts/drevops/deploy-lagoon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -144,32 +144,32 @@ 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."
sleep 10

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.
Expand All @@ -193,32 +193,32 @@ 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."
sleep 10

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
Expand Down

1 comment on commit e5832d8

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.