-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #430 from danskernesdigitalebibliotek/cms-env-cleanup
Cleanup development environments in our core Lagoon project
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Cleanup development environments in our core Lagoon project. | ||
# | ||
# With our setup Lagoon creates a development environment automatically each | ||
# time a pull request is created. Such an environments should also be deleted | ||
# when the pull request is closed. This is usually the case when the PR is | ||
# merged but often failed when the pull request is closed without merging. | ||
# | ||
# To work around this issue this script tries to close all development | ||
# environments in Lagoon where the corresponding pull request has been either | ||
# closed or merged. | ||
|
||
LAGOON_PROJECT="dpl-cms" | ||
REPO="danskernesdigitalebibliotek/dpl-cms" | ||
|
||
if ! gh auth status >/dev/null 2>&1; then | ||
echo "Error: You are not logged into GitHub. Please log in using 'gh auth login' and try again." | ||
exit 1 | ||
fi | ||
|
||
DRY_RUN=false | ||
if [ "$1" == "--dry-run" ]; then | ||
DRY_RUN=true | ||
fi | ||
|
||
DEV_ENVS=$(lagoon raw --raw "query dplCmsEnvs { | ||
projectByName(name: \"$LAGOON_PROJECT\") { | ||
environments { | ||
name | ||
environmentType | ||
} | ||
} | ||
}" | jq -c '.projectByName.environments[] | select(.environmentType == "development" and .name != "develop")') | ||
|
||
echo "$DEV_ENVS" | while read -r environment; do | ||
ENV_NAME=$(echo "$environment" | jq -r '.name') | ||
# Lagoon development environments are named after the number of their | ||
# corresponding pull request. | ||
PR_NUMBER=$(echo "$environment" | jq -r '.name | gsub("^pr-"; "") | tonumber') | ||
|
||
# Check the status of the PR using the gh CLI | ||
PR_STATUS=$(gh pr view "$PR_NUMBER" --repo $REPO --json state -q '.state') | ||
|
||
if [[ "$PR_STATUS" == "CLOSED" || "$PR_STATUS" == "MERGED" ]]; then | ||
|
||
echo "PR #$PR_NUMBER is $PR_STATUS. Closing development environment: $ENV_NAME." | ||
|
||
if [ "$DRY_RUN" = true ]; then | ||
echo "Dry-run: lagoon delete environment -p \"$LAGOON_PROJECT\" -e \"$ENV_NAME\"" | ||
else | ||
lagoon delete environment -p "$LAGOON_PROJECT" -e "$ENV_NAME" | ||
fi | ||
fi | ||
done; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ RUN apk add --no-cache \ | |
docker-cli \ | ||
gettext \ | ||
git \ | ||
github-cli \ | ||
rsync \ | ||
shadow \ | ||
vim \ | ||
|