2020-11-18 07:52:18 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# When an image was built with podman, it needs importing into minikube.
|
|
|
|
#
|
2020-11-25 14:22:24 +00:00
|
|
|
# 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.
|
|
|
|
#
|
2020-11-18 07:52:18 +00:00
|
|
|
|
2022-10-12 08:30:17 +00:00
|
|
|
# no need to ssh-copy images if everything runs local
|
|
|
|
if [[ "${VM_DRIVER}" == "none" ]]
|
2022-10-07 15:38:34 +00:00
|
|
|
then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2020-11-18 07:52:18 +00:00
|
|
|
# fail when a command returns an error
|
|
|
|
set -e -o pipefail
|
|
|
|
|
|
|
|
# "minikube ssh" fails to read the image, so use standard ssh instead
|
2020-11-25 14:22:24 +00:00
|
|
|
function minikube_ssh() {
|
2020-11-18 07:52:18 +00:00
|
|
|
ssh \
|
|
|
|
-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \
|
|
|
|
-l docker -i "$(minikube ssh-key)" \
|
2020-11-25 14:22:24 +00:00
|
|
|
"$(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)
|
2020-12-01 16:37:53 +00:00
|
|
|
echo "${STDOUT}"
|
2020-11-25 14:22:24 +00:00
|
|
|
|
|
|
|
# check the name of the image that was imported in docker
|
|
|
|
DOCKER_IMAGE=$(awk '/Loaded image/ {print $NF}' <<< "${STDOUT}")
|
2020-11-18 07:52:18 +00:00
|
|
|
|
2020-11-25 14:22:24 +00:00
|
|
|
# strip "localhost/" from the image name
|
|
|
|
if [[ "${DOCKER_IMAGE}" =~ ^localhost/* ]]
|
|
|
|
then
|
|
|
|
minikube_ssh docker tag "${DOCKER_IMAGE}" "${IMAGE}"
|
|
|
|
fi
|