From 3185cf2a98d45683aaf4c7ac43df2efebd201a55 Mon Sep 17 00:00:00 2001 From: Alex Sloan Date: Thu, 31 Aug 2017 14:53:41 -0400 Subject: [PATCH] AE integration tests use unique version IDs (#143) --- scripts/ae_integration_test.sh | 25 +++++++++++++++++-------- scripts/integration_test_cleanup.yaml | 5 +++++ 2 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 scripts/integration_test_cleanup.yaml diff --git a/scripts/ae_integration_test.sh b/scripts/ae_integration_test.sh index 25eb5241..4273ff64 100755 --- a/scripts/ae_integration_test.sh +++ b/scripts/ae_integration_test.sh @@ -30,15 +30,15 @@ if [ -z "${imageUnderTest}" ]; then exit 1 fi -# for local tests it makes sense sometimes to pin the deployment to an -# active version as that will speed up the deployment, for CI/CD this feature -# is not recommended -readonly gaeDeploymentVersion=$2 -if [ "${gaeDeploymentVersion}" ]; then - DEPLOYMENT_OPTS="-v $gaeDeploymentVersion --no-promote" - DEPLOYMENT_VERSION_URL_PREFIX="$gaeDeploymentVersion-dot-" - +# If provided, pin to a specific version. Otherwise, generate a random new version ID to prevent +# inadvertent collisions. +gaeDeploymentVersion=$2 +if [ -z "${gaeDeploymentVersion}" ]; then + gaeDeploymentVersion=$(uuidgen) + readonly tearDown="true" fi +DEPLOYMENT_OPTS="-v $gaeDeploymentVersion --no-promote --no-stop-previous-version" +DEPLOYMENT_VERSION_URL_PREFIX="$gaeDeploymentVersion-dot-" # build the test app pushd $testAppDir @@ -77,3 +77,12 @@ gcloud container builds submit \ --substitutions "_DEPLOYED_APP_URL=$DEPLOYED_APP_URL" \ $dir +if [ "$tearDown" == "true" ]; then + # run a cleanup build once tests have finished executing + gcloud container builds submit \ + --config $dir/integration_test_cleanup.yaml \ + --substitutions "_VERSION=$gaeDeploymentVersion" \ + --async \ + --no-source +fi + diff --git a/scripts/integration_test_cleanup.yaml b/scripts/integration_test_cleanup.yaml new file mode 100644 index 00000000..3018c037 --- /dev/null +++ b/scripts/integration_test_cleanup.yaml @@ -0,0 +1,5 @@ +# Cloud Builder pipeline for tearing down integration test resources +steps: + - name: 'gcr.io/cloud-builders/gcloud' + args: ['app', 'versions', 'delete', '$_VERSION'] +