blob: 3c49673597cce604cdafc926f5e310b9794d3449 [file] [log] [blame]
#!/bin/bash
##########################################################################################
# This script saves the docker container images that are pulled on to Kubernetes worker
# nodes. Once the save process is completed, all the resulting tar files are rsynched
# to localhost in order to load, tag, and push them to Nordix Harbor Container Image
# registry, followed by creation of onap_docker_images.list file for promotion.
##########################################################################################
# set the directorty where image tarfiles will be saves
DIRECTORY_TO_SAVE_IMAGES="/tmp/onap-container-images/$HOSTNAME"
# array to keep the list of docker images to save and their filenames
declare -A ONAP_IMAGES_TO_SAVE # array to keep the list of docker images to save and their filenames
# gather ONAP container image metadata from docker
while read -r line; do
ONAP_IMAGE_REPO=$(echo $line | cut -d'#' -f1)
ONAP_IMAGE_TAG=$(echo $line | cut -d'#' -f2)
ONAP_IMAGES_TO_SAVE[$ONAP_IMAGE_REPO]=$(echo $ONAP_IMAGE_REPO.$ONAP_IMAGE_TAG.tar | sed "s|^nexus[^/]*||" | sed "s|/|__|g")
done < <(docker images --no-trunc --format '{{.Repository}}#{{.Tag}}#{{.ID}}' | grep 'nexus.*/onap' | sort)
# remove/recreate the target folder to ensure there is no leftover
sudo /bin/rm -rf $DIRECTORY_TO_SAVE_IMAGES && /bin/mkdir -p $DIRECTORY_TO_SAVE_IMAGES
cd $DIRECTORY_TO_SAVE_IMAGES
# save ONAP container images
echo "Info : Total ${#ONAP_IMAGES_TO_SAVE[@]} ONAP images to save"
for IMAGE_TO_SAVE in ${!ONAP_IMAGES_TO_SAVE[@]}; do
IMAGE_FILENAME=${ONAP_IMAGES_TO_SAVE[$IMAGE_TO_SAVE]}
docker save $IMAGE_TO_SAVE > $IMAGE_FILENAME
echo "Saved $IMAGE_TO_SAVE as $IMAGE_FILENAME"
done