Make toolbox compatible with TPC
The toolbox script on the image will detect if the image is running
in TPC. If it is running in TPC, pull the toolbox container from
the in-universe artifact registry repository.
BUG=b/352136305
TEST=Installed and ran script in TPC and GDU instance
RELEASE_NOTE=None
Change-Id: Ia45a46d2c415a0ed62a763d4ad44031e7c8a879c
diff --git a/toolbox b/toolbox
index efde852..787ce9d 100755
--- a/toolbox
+++ b/toolbox
@@ -27,6 +27,14 @@
source "${toolboxrc}"
fi
+if [[ -f /etc/cloud-api-domains ]]; then
+ source "/etc/cloud-api-domains"
+fi
+
+if [[ -n "$API_DOMAIN" && $API_DOMAIN != "googleapis.com" && "${TOOLBOX_DOCKER_IMAGE}" == *"${COS_PROJECT}"* ]]; then
+ TOOLBOX_DOCKER_IMAGE="docker.${ARTIFACT_REGISTRY_DOMAIN}/${PROJECT_PREFIX::-1}/cos-cloud/toolbox/toolbox"
+fi
+
# Change toolbox container image name if location of the vm is available
# and it's from cos-cloud project.
if [[ "${TOOLBOX_DOCKER_IMAGE}" == *"${COS_PROJECT}"* ]]; then
@@ -60,6 +68,8 @@
registry_host="${TOOLBOX_DOCKER_IMAGE/gcr.io*/gcr.io}"
elif [[ "${TOOLBOX_DOCKER_IMAGE}" =~ ^[0-9a-z.-]*docker.pkg.dev/ ]]; then
registry_host="${TOOLBOX_DOCKER_IMAGE/docker.pkg.dev*/docker.pkg.dev}"
+ elif [[ -n "${ARTIFACT_REGISTRY_DOMAIN}" ]]; then
+ registry_host="docker.${ARTIFACT_REGISTRY_DOMAIN}"
fi
if [[ -n "${registry_host}" ]]; then
# docker-credential-gcr can fail if it runs in a