Skip to content

Commit

Permalink
Added lagoon wrapper to cmds.
Browse files Browse the repository at this point in the history
  • Loading branch information
richardgaunt committed Mar 25, 2024
1 parent 6486bfb commit 84704f2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
28 changes: 15 additions & 13 deletions scripts/drevops/deploy-lagoon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,15 @@ if ! command -v lagoon >/dev/null || [ -n "${DREVOPS_DEPLOY_LAGOON_LAGOONCLI_FOR
fi

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() { command lagoon --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" -p "${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 --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" delete environment -p "${LAGOON_PROJECT}" -e "${DREVOPS_DEPLOY_BRANCH}" || true
lagoon delete environment -e "${DREVOPS_DEPLOY_BRANCH}" || true

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

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/deploy-lagoon.sh#L114

Added line #L114 was not covered by tests

# ACTION: 'deploy' OR 'deploy_override_db'
else
Expand All @@ -119,7 +121,7 @@ else

# Discover all available environments to check if this is a fresh deployment
# or a re-deployment of the existing environment.
lagoon --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" list environments -p "${LAGOON_PROJECT}" --output-json --pretty >/tmp/lagoon-envs.json
lagoon list environments --output-json --pretty >/tmp/lagoon-envs.json

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

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/deploy-lagoon.sh#L124

Added line #L124 was not covered by tests
names="$(jq -r '.data[] | select(.deploytype | contains("pullrequest")) | .name' /tmp/lagoon-envs.json /dev/null 2>&1 || echo '')"

is_redeploy=0
Expand All @@ -136,39 +138,39 @@ else

# 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}" update variable -p "${LAGOON_PROJECT}" -e "${deploy_pr_full}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 0 -S global || true
lagoon update variable -e "${deploy_pr_full}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 0 -S global || true

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

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/deploy-lagoon.sh#L141

Added line #L141 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}" update variable -p "${LAGOON_PROJECT}" -e "${deploy_pr_full}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 1 -S global || true
lagoon update variable -e "${deploy_pr_full}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 1 -S 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
fi

note "Redeploying environment: project ${LAGOON_PROJECT}, PR: ${DREVOPS_DEPLOY_PR}."
lagoon --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" deploy pullrequest -p "${LAGOON_PROJECT}" -n "${DREVOPS_DEPLOY_PR}" --baseBranchName "${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 -n "${DREVOPS_DEPLOY_PR}" --baseBranchName "${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}"

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

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/deploy-lagoon.sh#L151

Added line #L151 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 --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
lagoon update variable -e "${deploy_pr_full}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 0 -S global || true

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

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/deploy-lagoon.sh#L159

Added line #L159 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 --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" deploy pullrequest -p "${LAGOON_PROJECT}" -n "${DREVOPS_DEPLOY_PR}" --baseBranchName "${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 -n "${DREVOPS_DEPLOY_PR}" --baseBranchName "${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}"

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

# Deploy branch.
else
# Discover all available environments to check if this is a fresh deployment
# or a re-deployment of the existing environment.
lagoon --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" list environments -p "${LAGOON_PROJECT}" --output-json --pretty >/tmp/lagoon-envs.json
lagoon list environments --output-json --pretty >/tmp/lagoon-envs.json

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

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/deploy-lagoon.sh#L173

Added line #L173 was not covered by tests
names="$(jq -r '.data[] | select(.deploytype | contains("branch")) | .name' /tmp/lagoon-envs.json /dev/null 2>&1 || echo '')"

is_redeploy=0
Expand All @@ -185,32 +187,32 @@ else

# 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}" update variable -p "${LAGOON_PROJECT}" -e "${DREVOPS_DEPLOY_BRANCH}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 0 -S global || true
lagoon update variable -e "${DREVOPS_DEPLOY_BRANCH}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 0 -S global || true

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

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/deploy-lagoon.sh#L190

Added line #L190 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}" update variable -p "${LAGOON_PROJECT}" -e "${DREVOPS_DEPLOY_BRANCH}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 1 -S global || true
lagoon update variable -e "${DREVOPS_DEPLOY_BRANCH}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 1 -S global || true

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

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/deploy-lagoon.sh#L196

Added line #L196 was not covered by tests
fi

note "Redeploying environment: project ${LAGOON_PROJECT}, branch: ${DREVOPS_DEPLOY_BRANCH}."
lagoon --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" deploy latest -p "${LAGOON_PROJECT}" -e "${DREVOPS_DEPLOY_BRANCH}" || true
lagoon deploy latest -e "${DREVOPS_DEPLOY_BRANCH}" || true

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

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/deploy-lagoon.sh#L200

Added line #L200 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 --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
lagoon update variable -e "${DREVOPS_DEPLOY_BRANCH}" -N DREVOPS_PROVISION_OVERRIDE_DB -V 0 -S global || true

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

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/deploy-lagoon.sh#L208

Added line #L208 was not covered by tests
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 --force --skip-update-check -i "${DREVOPS_DEPLOY_SSH_FILE}" -l "${DREVOPS_DEPLOY_LAGOON_INSTANCE}" deploy branch -p "${LAGOON_PROJECT}" -b "${DREVOPS_DEPLOY_BRANCH}"
lagoon deploy branch -b "${DREVOPS_DEPLOY_BRANCH}"

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

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/deploy-lagoon.sh#L215

Added line #L215 was not covered by tests
fi
fi
fi
Expand Down
4 changes: 3 additions & 1 deletion scripts/drevops/task-custom-lagoon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ if ! command -v lagoon >/dev/null || [ -n "${DREVOPS_TASK_LAGOON_INSTALL_CLI_FOR
fi

note "Configuring Lagoon instance."
#shellcheck disable=SC2218
lagoon config add --force -l "${DREVOPS_TASK_LAGOON_INSTANCE}" -g "${DREVOPS_TASK_LAGOON_INSTANCE_GRAPHQL}" -H "${DREVOPS_TASK_LAGOON_INSTANCE_HOSTNAME}" -P "${DREVOPS_TASK_LAGOON_INSTANCE_PORT}"
lagoon() { command lagoon --force --skip-update-check -i "${DREVOPS_TASK_SSH_FILE}" -l "${DREVOPS_TASK_LAGOON_INSTANCE}" -p "${DREVOPS_TASK_LAGOON_PROJECT}" "$@";}

note "Creating ${DREVOPS_TASK_LAGOON_NAME} task: project ${DREVOPS_TASK_LAGOON_PROJECT}, branch: ${DREVOPS_TASK_LAGOON_BRANCH}."
lagoon --force --skip-update-check -i "${DREVOPS_TASK_SSH_FILE}" -l "${DREVOPS_TASK_LAGOON_INSTANCE}" run custom -p "${DREVOPS_TASK_LAGOON_PROJECT}" -e "${DREVOPS_TASK_LAGOON_BRANCH}" -N "${DREVOPS_TASK_LAGOON_NAME}" -c "${DREVOPS_TASK_LAGOON_COMMAND}"
lagoon run custom -e "${DREVOPS_TASK_LAGOON_BRANCH}" -N "${DREVOPS_TASK_LAGOON_NAME}" -c "${DREVOPS_TASK_LAGOON_COMMAND}"

Check warning on line 95 in scripts/drevops/task-custom-lagoon.sh

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/task-custom-lagoon.sh#L95

Added line #L95 was not covered by tests

pass "Finished Lagoon task ${DREVOPS_TASK_LAGOON_NAME}."

0 comments on commit 84704f2

Please sign in to comment.