From b0fcc1ad1d78a373a12c109491914b877fc2d56d Mon Sep 17 00:00:00 2001 From: Kenichi Omichi Date: Mon, 19 Jul 2021 09:58:51 +0900 Subject: [PATCH] Add error handling for registorying images (#7787) When running the script, I faced the following error but it was difficult to know the root problem due to lack of error handling. docker tag" requires exactly 2 arguments. See 'docker tag --help'. Usage: docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG] Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE To investigate such errors easily, this adds an error handling. --- contrib/offline/manage-offline-container-images.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/contrib/offline/manage-offline-container-images.sh b/contrib/offline/manage-offline-container-images.sh index 0f6c3a428..b64d7b748 100755 --- a/contrib/offline/manage-offline-container-images.sh +++ b/contrib/offline/manage-offline-container-images.sh @@ -109,6 +109,18 @@ function register_container_images() { 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"//) + if [ -z "${file_name}" ]; then + echo "Failed to get file_name for line ${line}" + exit 1 + fi + if [ -z "${org_image}" ]; then + echo "Failed to get org_image for line ${line}" + exit 1 + fi + if [ -z "${image_id}" ]; then + echo "Failed to get image_id for file ${file_name}" + exit 1 + fi sudo docker load -i ${IMAGE_DIR}/${file_name} sudo docker tag ${image_id} ${new_image} sudo docker push ${new_image}