From 87d50ee94e831b8119060655cdddef45d01e8a96 Mon Sep 17 00:00:00 2001 From: Mridula <66699525+mpeddada1@users.noreply.github.com> Date: Thu, 5 Oct 2023 19:13:59 +0000 Subject: [PATCH] chore: add kokoro job for verifying presence of docker image (#664) * chore: add kokoro job for verifying presence of docker image --- .kokoro/presubmit/graalvm-docker.cfg | 12 +++++++++ .kokoro/verify-docker-images.sh | 37 ++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 .kokoro/presubmit/graalvm-docker.cfg create mode 100755 .kokoro/verify-docker-images.sh diff --git a/.kokoro/presubmit/graalvm-docker.cfg b/.kokoro/presubmit/graalvm-docker.cfg new file mode 100644 index 00000000..63d5b090 --- /dev/null +++ b/.kokoro/presubmit/graalvm-docker.cfg @@ -0,0 +1,12 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/java8" +} + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/java-shared-config/.kokoro/verify-docker-images.sh" +} \ No newline at end of file diff --git a/.kokoro/verify-docker-images.sh b/.kokoro/verify-docker-images.sh new file mode 100755 index 00000000..3f15d3a2 --- /dev/null +++ b/.kokoro/verify-docker-images.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# Script to verify the presence of GraalVM docker test images tagged with the latest java-shared-config version. + +function fetch_image_names() { + imageNames="$(grep " - gcr.io/cloud-devrel-public-resources/" .cloudbuild/cloudbuild.yaml | cut -d "/" -f 3 | cut -d ":" -f 1)" + export imageNames + echo "$imageNames" +} + +# Get the directory of the build script +scriptDir=$(realpath "$(dirname "${BASH_SOURCE[0]}")") +# cd to the parent directory, i.e. the root of the git repo +cd ${scriptDir}/.. || exit + +# Fetch the java-shared-config version in source of the current commit. +javaSharedConfigVersion="$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" + +branchName=$(git name-rev "$KOKORO_GIT_COMMIT" | sed 's/.* //') +gitCommitMessage=$(git log -1 "$(git rev-parse --short "$KOKORO_GIT_COMMIT")" | grep "chore(main): release *") + +# GraalVM docker images are not tagged with SNAPSHOT versions. +if [[ "${branchName}" == *"release-please--branches--main"* ]] && [[ ! $gitCommitMessage =~ "SNAPSHOT" ]]; then + imageNames=$(fetch_image_names) + for name in $imageNames; do + fullContainerName="gcr.io/cloud-devrel-public-resources/${name}:${javaSharedConfigVersion}" + echo "Verifying presence of ${fullContainerName}." + gcloud container images describe "${fullContainerName}" > /dev/null; exit_status=$? + if [[ $exit_status = 0 ]]; then + echo "Success. Found $fullContainerName." + fi + done + RETURN_CODE=$? +else + echo "Skipping check for non-release and SNAPSHOT update branches" + exit 0 +fi