[2.16] Fix how to get image ID on offline deployment (#7829)
* 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. * 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.
This commit is contained in:
parent
9fa051780e
commit
247d062c02
1 changed files with 25 additions and 5 deletions
|
@ -100,15 +100,35 @@ function register_container_images() {
|
||||||
|
|
||||||
tar -zxvf ${IMAGE_TAR_FILE}
|
tar -zxvf ${IMAGE_TAR_FILE}
|
||||||
sudo docker load -i ${IMAGE_DIR}/registry-latest.tar
|
sudo docker load -i ${IMAGE_DIR}/registry-latest.tar
|
||||||
sudo docker run --restart=always -d -p 5000:5000 --name registry registry:latest
|
|
||||||
set +e
|
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
|
set -e
|
||||||
|
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
file_name=$(echo ${line} | awk '{print $1}')
|
file_name=$(echo ${line} | awk '{print $1}')
|
||||||
org_image=$(echo ${line} | awk '{print $2}')
|
raw_image=$(echo ${line} | awk '{print $2}')
|
||||||
new_image="${LOCALHOST_NAME}:5000/${org_image}"
|
new_image="${LOCALHOST_NAME}:5000/${raw_image}"
|
||||||
image_id=$(tar -tf ${IMAGE_DIR}/${file_name} | grep "\.json" | grep -v manifest.json | sed s/"\.json"//)
|
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
|
||||||
|
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 load -i ${IMAGE_DIR}/${file_name}
|
||||||
sudo docker tag ${image_id} ${new_image}
|
sudo docker tag ${image_id} ${new_image}
|
||||||
sudo docker push ${new_image}
|
sudo docker push ${new_image}
|
||||||
|
|
Loading…
Reference in a new issue