Skip to content

Instantly share code, notes, and snippets.

@sheva29
Last active April 1, 2018 18:13
Show Gist options
  • Save sheva29/adb60bee1236c5499f4d52b42e2201eb to your computer and use it in GitHub Desktop.
Save sheva29/adb60bee1236c5499f4d52b42e2201eb to your computer and use it in GitHub Desktop.
Shell script to remove old versions of GAE services while deploying in Drone
#!/bin/bash
# keep only latest 2 versions of a GAE service based on the latest version numbers
VERSIONS=$(gcloud app versions list --service $1 --sort-by '~version' --format 'value(version.id)')
COUNT=0
echo "Keeping the $2 latest versions of the $1 service"
for VERSION in $VERSIONS
do
((COUNT++))
if [ $COUNT -gt $2 ]
then
echo "Going to delete version $VERSION of the $1 service."
# gcloud app versions delete $VERSION --service $1 -q
else
echo "Going to keep version $VERSION of the $1 service."
fi
done
#!/bin/bash
#Deletes old versions of current services in GAE
# $1 = service_name
# $2 = future_instance_to_keep
VERSIONS=$(gcloud app versions list --service $1 --sort-by '~version' --format 'value(version.id)')
VERSION_TRAFFIC=$(gcloud app versions list --service $1 --sort-by '~version' --format 'value(version.id)' --hide-no-traffic)
DEPLOYED_VERSION=$2
echo "Keeping $DEPLOYED_VERSION and $VERSION_TRAFFIC of the $1 service"
for VERSION in $VERSIONS
do
if [ $VERSION -ne $VERSION_TRAFFIC ] && [ $VERSION -ne $DEPLOYED_VERSION ]
then
echo "Going to delete version $VERSION of the $1 service."
gcloud app versions delete $VERSION --service $1 -q
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment