Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reliable way to determine the gcloud_build_image image name #543

Closed
DazWilkin opened this issue Jun 15, 2021 · 3 comments
Closed

Reliable way to determine the gcloud_build_image image name #543

DazWilkin opened this issue Jun 15, 2021 · 3 comments
Labels
question Further information is requested

Comments

@DazWilkin
Copy link

Is there a reliable way to determine the image name generated by gcloud_build_image?

I'd been using:

IMAGE=gcr.io/${PROJECT}/endpoints-runtime-serverless:${ESP_HOST}-${CONFIG}

But this has recently revised to include the ESP version:

IMAGE=gcr.io/${PROJECT}/endpoints-runtime-serverless:${ESP_VERS}-${ESP_HOST}-${CONFIG}

And I'm currently manually updating the ESP_VERS in my script :-(

gcloud services enable ${ESP_HOST} \
--project=${PROJECT}

# Build an ESPv2 proxy
wget https://raw.githubusercontent.com/GoogleCloudPlatform/esp-v2/master/docker/serverless/gcloud_build_image
chmod +x ./gcloud_build_image

CONFIG="$(\
  gcloud endpoints configs list \
  --service=${ESP_HOST} \
  --project=${PROJECT} \
  --format="json" \
  | jq -r .[0].id)"
./gcloud_build_image \
-s ${ESP_HOST} \
-c ${CONFIG} \
-p ${PROJECT}

# Deploy the ESPv2 proxy in place of the placeholder
ESP_VERS="2.28.0"
IMAGE=gcr.io/${PROJECT}/endpoints-runtime-serverless:${ESP_VERS}-${ESP_HOST}-${CONFIG}

gcloud run deploy ${ESP_NAME} \
--image=${IMAGE} \
--no-allow-unauthenticated \
--platform=managed \
--region=${REGION} \
--project=${PROJECT}
@DazWilkin DazWilkin changed the title Reliable way to determine the proxy's image name Reliable way to determine the gcloud_build_image image name Jun 15, 2021
@nareddyt
Copy link
Contributor

The name change was almost a year ago in #229. We plan to keep the name as gcr.io/${PROJECT}/endpoints-runtime-serverless:${ESP_VERS}-${ESP_HOST}-${CONFIG} for the foreseeable future :)

This format is also documented in our tutorials: https://cloud.google.com/endpoints/docs/openapi/get-started-cloud-run#configure_esp

@nareddyt nareddyt added the question Further information is requested label Jun 15, 2021
@nareddyt nareddyt reopened this Jun 15, 2021
@nareddyt
Copy link
Contributor

I see, your question is about how to automatically determine the image name in your scripts. You can copy this code snippet into your scripts to get the latest ESPv2 version:

if [ -z "${ESP_FULL_VERSION}" ]; then
echo "Determining fully-qualified ESP version for tag: ${ESP_TAG}"
ALL_TAGS=$(gcloud container images list-tags "${BASE_IMAGE_NAME}" \
--filter="tags~^${ESP_TAG}$" \
--format="value(tags)")
IFS=',' read -ra TAGS_ARRAY <<< "${ALL_TAGS}"
if [ ${#TAGS_ARRAY[@]} -eq 0 ]; then
error_exit "Did not find ESP version: ${ESP_TAG}"
fi;
# Find the tag with the longest length.
ESP_FULL_VERSION=""
for tag in "${TAGS_ARRAY[@]}"; do
if [ ${#tag} -gt ${#ESP_FULL_VERSION} ]; then
ESP_FULL_VERSION=${tag}
fi
done
fi
echo "Building image for ESP version: ${ESP_FULL_VERSION}"

@DazWilkin
Copy link
Author

Perfect! Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants