From 8f44cd35d80f74823f9898acb7e743fc2facc9a8 Mon Sep 17 00:00:00 2001 From: Kenichi Omichi Date: Mon, 26 Jul 2021 16:56:33 +0900 Subject: [PATCH] Fix how to get image ID on offline deployment (#7808) Previously IDs of container images were gotten from tar files of container images but that way was wrong. If multiple json files are contained in a tar file, the script got multiple IDs and tried to pass these IDs on `docker tag` command. Then the command was failed. This updates the script to get image IDs from `docker image inspect` command to fix this issue. In addition, this adds a check a registry container exists already or not before deploying registry container to avoid a container conflict failure. --- .../offline/manage-offline-container-images.sh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/contrib/offline/manage-offline-container-images.sh b/contrib/offline/manage-offline-container-images.sh index b64d7b748..891441c5f 100755 --- a/contrib/offline/manage-offline-container-images.sh +++ b/contrib/offline/manage-offline-container-images.sh @@ -100,19 +100,27 @@ function register_container_images() { tar -zxvf ${IMAGE_TAR_FILE} sudo docker load -i ${IMAGE_DIR}/registry-latest.tar - sudo docker run --restart=always -d -p 5000:5000 --name registry registry:latest set +e - + sudo docker container inspect registry >/dev/null 2>&1 + if [ $? -ne 0 ]; then + sudo docker run --restart=always -d -p 5000:5000 --name registry registry:latest + fi set -e + while read -r line; do file_name=$(echo ${line} | awk '{print $1}') - org_image=$(echo ${line} | awk '{print $2}') - new_image="${LOCALHOST_NAME}:5000/${org_image}" - image_id=$(tar -tf ${IMAGE_DIR}/${file_name} | grep "\.json" | grep -v manifest.json | sed s/"\.json"//) + raw_image=$(echo ${line} | awk '{print $2}') + new_image="${LOCALHOST_NAME}:5000/${raw_image}" + org_image=$(sudo docker load -i ${IMAGE_DIR}/${file_name} | head -n1 | awk '{print $3}') + image_id=$(sudo docker image inspect ${org_image} | grep "\"Id\":" | awk -F: '{print $3}'| sed s/'\",'//) if [ -z "${file_name}" ]; then echo "Failed to get file_name for line ${line}" exit 1 fi + if [ -z "${raw_image}" ]; then + echo "Failed to get raw_image for line ${line}" + exit 1 + fi if [ -z "${org_image}" ]; then echo "Failed to get org_image for line ${line}" exit 1