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

[#952] Updated Lagoon deployment script to use variable update. #1209

Merged
merged 3 commits into from
Mar 1, 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
22 changes: 8 additions & 14 deletions .drevops/tests/bats/deployment1.bats
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,12 @@ load _helper.deployment.bash
mock_set_output "${mock_lagoon}" '{"data": [{"deploytype": "branch", "environment": "development", "id": "364889", "name": "testbranch", "openshiftprojectname": "testproject-testbranch", "route": "https://nginx-php.develop.civic.au2.amazee.io"}]}' 2
# Set variables.
mock_set_output "${mock_lagoon}" "success" 3
mock_set_output "${mock_lagoon}" "success" 4
# Set variables.
mock_set_output "${mock_lagoon}" "success" 5
mock_set_output "${mock_lagoon}" "success" 6
mock_set_output "${mock_lagoon}" "success" 4
# Redeploying env.
mock_set_output "${mock_lagoon}" "success" 7
mock_set_output "${mock_lagoon}" "success" 5
# Remove variables.
mock_set_output "${mock_lagoon}" "success" 8
mock_set_output "${mock_lagoon}" "success" 9
mock_set_output "${mock_lagoon}" "success" 6

# Deployment action to override db.
export DREVOPS_DEPLOY_ACTION="deploy_override_db"
Expand All @@ -307,23 +304,20 @@ load _helper.deployment.bash
assert_file_exists "${DREVOPS_DEPLOY_LAGOON_LAGOONCLI_BIN_PATH}/lagoon"

# Deployment script calls API several times.
assert_equal 9 "$(mock_get_call_num "${mock_lagoon}")"
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)"
# Get a list of environments.
assert_contains "-l testlagoon list environments -p testproject --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 delete variable -p testproject -e testbranch -N DREVOPS_PROVISION_OVERRIDE_DB" "$(mock_get_call_args "${mock_lagoon}" 3)"
assert_contains "-l testlagoon add variable -p testproject -e testbranch -N DREVOPS_PROVISION_OVERRIDE_DB -V 0 -S global" "$(mock_get_call_args "${mock_lagoon}" 4)"
assert_contains "-l testlagoon update variable -p testproject -e testbranch -N DREVOPS_PROVISION_OVERRIDE_DB -V 0 -S global" "$(mock_get_call_args "${mock_lagoon}" 3)"
# Override DB during re-deployment.
assert_contains "-l testlagoon delete variable -p testproject -e testbranch -N DREVOPS_PROVISION_OVERRIDE_DB" "$(mock_get_call_args "${mock_lagoon}" 5)"
assert_contains "-l testlagoon add variable -p testproject -e testbranch -N DREVOPS_PROVISION_OVERRIDE_DB -V 1 -S global" "$(mock_get_call_args "${mock_lagoon}" 6)"
assert_contains "-l testlagoon update variable -p testproject -e testbranch -N DREVOPS_PROVISION_OVERRIDE_DB -V 1 -S global" "$(mock_get_call_args "${mock_lagoon}" 4)"
# Redeploy.
assert_contains "-l testlagoon deploy latest -p testproject -e testbranch" "$(mock_get_call_args "${mock_lagoon}" 7)"
assert_contains "-l testlagoon deploy latest -p testproject -e testbranch" "$(mock_get_call_args "${mock_lagoon}" 5)"
# Remove a DB import override flag for the current deployment.
assert_contains "-l testlagoon delete variable -p testproject -e testbranch -N DREVOPS_PROVISION_OVERRIDE_DB" "$(mock_get_call_args "${mock_lagoon}" 8)"
assert_contains "-l testlagoon add variable -p testproject -e testbranch -N DREVOPS_PROVISION_OVERRIDE_DB -V 0 -S global" "$(mock_get_call_args "${mock_lagoon}" 9)"
assert_contains "-l testlagoon update variable -p testproject -e testbranch -N DREVOPS_PROVISION_OVERRIDE_DB -V 0 -S global" "$(mock_get_call_args "${mock_lagoon}" 6)"

# Assert that no other deployments ran.
assert_output_not_contains "Started ARTIFACT deployment."
Expand Down
18 changes: 6 additions & 12 deletions scripts/drevops/deploy-lagoon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,13 @@

# Explicitly set DB overwrite flag to 0 due to a bug in Lagoon.
# @see https://github.com/uselagoon/lagoon/issues/1922
lagoon --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" delete variable -p "${LAGOON_PROJECT}" -e "${deploy_pr_full}" -N DREVOPS_PROVISION_OVERRIDE_DB || true
lagoon --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" add variable -p "${LAGOON_PROJECT}" -e "${deploy_pr_full}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 0 -S global || true
lagoon --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" update variable -p "${LAGOON_PROJECT}" -e "${deploy_pr_full}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 0 -S global || true

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

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/deploy-lagoon.sh#L160

Added line #L160 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 --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" delete variable -p "${LAGOON_PROJECT}" -e "${deploy_pr_full}" -N DREVOPS_PROVISION_OVERRIDE_DB || true
lagoon --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" add variable -p "${LAGOON_PROJECT}" -e "${deploy_pr_full}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 1 -S global || true
lagoon --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" update variable -p "${LAGOON_PROJECT}" -e "${deploy_pr_full}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 1 -S global || true

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

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/deploy-lagoon.sh#L166

Added line #L166 was not covered by tests
fi

note "Redeploying environment: project ${LAGOON_PROJECT}, PR: ${DREVOPS_DEPLOY_PR}."
Expand All @@ -177,8 +175,7 @@

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 --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" delete variable -p "${LAGOON_PROJECT}" -e "${deploy_pr_full}" -N DREVOPS_PROVISION_OVERRIDE_DB || true
lagoon --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" add variable -p "${LAGOON_PROJECT}" -e "${deploy_pr_full}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 0 -S global || true
lagoon --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" update variable -p "${LAGOON_PROJECT}" -e "${deploy_pr_full}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 0 -S global || true

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

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/deploy-lagoon.sh#L178

Added line #L178 was not covered by tests
fi

# Deployment of the fresh environment.
Expand Down Expand Up @@ -209,15 +206,13 @@

# Explicitly set DB overwrite flag to 0 due to a bug in Lagoon.
# @see https://github.com/uselagoon/lagoon/issues/1922
lagoon --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" delete variable -p "${LAGOON_PROJECT}" -e "${DREVOPS_DEPLOY_BRANCH}" -N DREVOPS_PROVISION_OVERRIDE_DB || true
lagoon --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" add variable -p "${LAGOON_PROJECT}" -e "${DREVOPS_DEPLOY_BRANCH}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 0 -S global || true
lagoon --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" update variable -p "${LAGOON_PROJECT}" -e "${DREVOPS_DEPLOY_BRANCH}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 0 -S 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 --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" delete variable -p "${LAGOON_PROJECT}" -e "${DREVOPS_DEPLOY_BRANCH}" -N DREVOPS_PROVISION_OVERRIDE_DB || true
lagoon --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" add variable -p "${LAGOON_PROJECT}" -e "${DREVOPS_DEPLOY_BRANCH}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 1 -S global || true
lagoon --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" update variable -p "${LAGOON_PROJECT}" -e "${DREVOPS_DEPLOY_BRANCH}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 1 -S global || true
fi

note "Redeploying environment: project ${LAGOON_PROJECT}, branch: ${DREVOPS_DEPLOY_BRANCH}."
Expand All @@ -229,8 +224,7 @@

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 --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" delete variable -p "${LAGOON_PROJECT}" -e "${DREVOPS_DEPLOY_BRANCH}" -N DREVOPS_PROVISION_OVERRIDE_DB || true
lagoon --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" add variable -p "${LAGOON_PROJECT}" -e "${DREVOPS_DEPLOY_BRANCH}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 0 -S global || true
lagoon --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" update variable -p "${LAGOON_PROJECT}" -e "${DREVOPS_DEPLOY_BRANCH}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 0 -S global || true
fi

# Deployment of the fresh environment.
Expand Down
Loading