Skip to content

Commit 1eb13f5

Browse files
authored
Delete old versions after deployment (#4527)
* Delete old versions after deployment This changes the order in which deletion of old versions of wpt.fyi is deleted from the infrastructure. Prior to this change the deletion happened at the beginning of the deployment. The deletion itself takes many minutes per service, with prompts inbetween, so the time from start of deplyment to the new image actually being available in the infrastructure was longer than it needed to be. With this change, the deployment starts right away, and once the deployment is done, we ask whether old versions should be deleted and do those deletions w/o prompting per service, meaning the person doing the deployment doesn't need to sit and wait etc. * Fix nesting of if statement.
1 parent d351685 commit 1eb13f5

File tree

1 file changed

+37
-16
lines changed

1 file changed

+37
-16
lines changed

util/deploy-production.sh

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ usage() {
1717
echo "${USAGE}"
1818
}
1919

20-
# Deletes the service passed as a parameter.
21-
delete_oldest_version() {
22-
OLDEST_REV=$(gcloud app --project=wptdashboard versions list --sort-by=last_deployed_time --filter="service=$1" --limit=1 --format=json | jq -r '.[] | .id')
23-
echo "Deleting $1 service version $OLDEST_REV"
24-
gcloud app --project=wptdashboard versions delete --service=$SERVICE ${QUIET:+--quiet} $OLDEST_REV
25-
}
26-
2720
while getopts ':bfqh' flag; do
2821
case "${flag}" in
2922
b) SKIP_ISSUE_CREATION='true' ;;
@@ -94,22 +87,22 @@ EOF
9487
fi
9588
fi
9689

97-
# Confirm there are 3 versions for each service and delete the oldest version.
90+
# Confirm there are no more than two versions for each service to make sure
91+
# there's room for the ones we're about to push. If there are more than two
92+
# versions available, something didn't go as planned in the previous
93+
# deployment. If so, delete old versions manually in the cloud console.
9894
SERVICES="default processor searchcache"
9995
for SERVICE in $SERVICES
10096
do
10197
VERSIONS=$(gcloud app --project=wptdashboard versions list --filter="service=$SERVICE" --format=list | wc -l)
102-
if [[ "${VERSIONS}" -eq "3" ]];
98+
if ((${VERSIONS} > 2));
10399
then
104-
echo "Found 3 versions for service $SERVICE, will delete the oldest"
105-
delete_oldest_version $SERVICE
106-
elif [[ "${VERSIONS}" -lt "3" ]];
107-
then
108-
echo -e "\n$VERSIONS versions found for service $SERVICE"
109-
else
110-
echo -e "\n$VERSIONS versions found for service $SERVICE!"
100+
echo -e "Found more than 2 versions ($VERSIONS) for service $SERVICE.\nPlease make sure there are no more than 2 versions of each service and try\nagain."
101+
111102
exit 3
112103
fi
104+
105+
echo "Found $VERSIONS versions for service $SERVICE. Good to proceed."
113106
done
114107

115108
# Start a docker instance.
@@ -143,3 +136,31 @@ fi
143136
# Update and close deployment bug.
144137
LAST_DEPLOYMENT_ISSUE=$(gh issue list --state open --label "$PROD_LABEL" --label "$RELEASE_LABEL" --limit 1 --json number --jq '.[] | .number')
145138
gh issue close "$LAST_DEPLOYMENT_ISSUE" -c "Deployment is now complete."
139+
140+
# Check if there are more more than two versions of the default service left
141+
# after we're done with this deplyment to make sure there's room for the next
142+
# deployment. If there are, ask to delete the oldest default service version,
143+
# and also delete the same version from the other services which will also exist
144+
# if all went well during the deployment. This check isn't fail safe, but
145+
# combined with the check we do before doing any deployments earlier in this
146+
# script, this should leave us in a good state.
147+
148+
VERSIONS=$(gcloud app --project=wptdashboard versions list --filter="service=default" --format=list | wc -l)
149+
150+
if (($VERSIONS == 3)); then
151+
echo -e "Please ensure the deployment was successful. If so, we can go ahead and\ndelete the oldest version of all services if necessary, leaving the one just\ndeployed and the one running before this deployment. This will ensure we leave\nroom for the next deployment.\n"
152+
153+
read -p "Delete oldest version of all services to leave room for the next deplyment? (y/n): " DELETE
154+
155+
if [[ $DELETE == "y" ]]; then
156+
echo "Found $VERSIONS for the default service, deleting the oldest version of all services."
157+
158+
OLDEST_REV=$(gcloud app --project=wptdashboard versions list --sort-by=last_deployed_time --filter="service=$SERVICE" --limit=1 --format=json | jq -r '.[] | .id')
159+
for SERVICE in $SERVICES; do
160+
echo "Deleting $SERVICE service version $OLDEST_REV"
161+
gcloud app --project=wptdashboard versions delete --service=$SERVICE --quiet $OLDEST_REV
162+
done
163+
fi
164+
elif (($VERSIONS > 3)); then
165+
echo -e "\nUnexpectedly found $VERSIONS versions for the default service.\nPlease delete old versions for all services manually until there are no more than two left."
166+
fi

0 commit comments

Comments
 (0)