Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Lagoon deployment script to use long-form options. #1369

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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

Check warning on line 120 in scripts/drevops/deploy-lagoon.sh

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/deploy-lagoon.sh#L120

Added line #L120 was not covered by tests

# ACTION: 'deploy' OR 'deploy_override_db'
else
Expand All @@ -144,32 +144,32 @@

# 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

Check warning on line 147 in scripts/drevops/deploy-lagoon.sh

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/deploy-lagoon.sh#L147

Added line #L147 was not covered by tests

# 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

Check warning on line 153 in scripts/drevops/deploy-lagoon.sh

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/deploy-lagoon.sh#L153

Added line #L153 was not covered by tests
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}"

Check warning on line 157 in scripts/drevops/deploy-lagoon.sh

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/deploy-lagoon.sh#L157

Added line #L157 was not covered by tests

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

Check warning on line 165 in scripts/drevops/deploy-lagoon.sh

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/deploy-lagoon.sh#L165

Added line #L165 was not covered by tests
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}"

Check warning on line 172 in scripts/drevops/deploy-lagoon.sh

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/deploy-lagoon.sh#L172

Added line #L172 was not covered by tests
fi

# Deploy branch.
Expand All @@ -193,32 +193,32 @@

# 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