From 7c6dbfdb8e23b2fb58d4e398f7a5bdf8fab094d5 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Wed, 25 Nov 2020 15:22:24 +0100 Subject: [PATCH] ci: strip localhost/ prefix after importing images in minikube Some versions of minikube/docker add a "localhost/" prefix to imported images. In that case, the image needs to get tagged without the prefix as well. When running podman2minikube.sh, the docker process inside the minikube VM sometimes responds with: # ./podman2minikube.sh rook/ceph:v1.3.9 Loaded image: localhost/rook/ceph:v1.3.9 When the "localhost/" prefix is added to the image name, deploying Rook will try to pull the rook/ceph:v1.3.9 image again. This can fail when the Docker Hub pull rate-limit is hit. Without the "localhost/" prefix, there should be no further attempt to pull the image, as it should be detected that the image is available. Signed-off-by: Niels de Vos --- podman2minikube.sh | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/podman2minikube.sh b/podman2minikube.sh index 6261438d8..67b00b263 100755 --- a/podman2minikube.sh +++ b/podman2minikube.sh @@ -2,14 +2,34 @@ # # When an image was built with podman, it needs importing into minikube. # +# Some versions of minikube/docker add a "localhost/" prefix to imported +# images. In that case, the image needs to get tagged without the prefix as +# well. +# # fail when a command returns an error set -e -o pipefail # "minikube ssh" fails to read the image, so use standard ssh instead -podman image save "${1}" | \ +function minikube_ssh() { ssh \ -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \ -l docker -i "$(minikube ssh-key)" \ - "$(minikube ip)" docker image load + "$(minikube ip)" "${*}" +} +IMAGE="${1}" +# if IMAGE is empty, fail the script +[ -n "${IMAGE}" ] + +# import the image, save response in STDOUT +STDOUT=$(podman image save "${IMAGE}" | minikube_ssh docker image load) + +# check the name of the image that was imported in docker +DOCKER_IMAGE=$(awk '/Loaded image/ {print $NF}' <<< "${STDOUT}") + +# strip "localhost/" from the image name +if [[ "${DOCKER_IMAGE}" =~ ^localhost/* ]] +then + minikube_ssh docker tag "${DOCKER_IMAGE}" "${IMAGE}" +fi