@@ -321,17 +321,17 @@ if [ -n "$SSH_KEY" ] && [ ! -f "$SSH_KEY" ]; then
321
321
error " SSH key file not found: $SSH_KEY "
322
322
fi
323
323
324
- extract_image_name_and_tag () {
325
- local regex= " ^(.*:.*?\/)?(.*\/)?(.*)$ "
326
- local image_name_tag
327
-
328
- if [[ $IMAGE =~ $regex ]]
329
- then
330
- image_name_tag =${BASH_REMATCH[3]}
331
- echo " $image_name_tag "
324
+ get_temp_image_name () {
325
+ local image= $1
326
+ local regex= " ^(.*:.*?\/)?(.*\/)?(.+)$ "
327
+ local repo_with_tag
328
+
329
+ if [[ $image =~ $regex ]] ; then
330
+ repo_with_tag =${BASH_REMATCH[3]}
331
+ echo " ${RANDOM} - ${repo_with_tag} "
332
332
return 0
333
333
else
334
- error " Error parsing reference $IMAGE is not a valid repository/tag: invalid reference format "
334
+ error " Error parsing reference: ${image} is not a valid image reference. "
335
335
fi
336
336
}
337
337
@@ -388,7 +388,7 @@ if is_additional_tunneling_needed; then
388
388
success " Additional tunnel created: localhost:$PUSH_PORT → localhost:$LOCAL_PORT "
389
389
fi
390
390
391
- IMAGE_NAME_TAG=$( extract_image_name_and_tag )
391
+ IMAGE_NAME_TAG=$( get_temp_image_name " ${IMAGE} " )
392
392
# Tag and push the image to unregistry through the forwarded port.
393
393
REGISTRY_IMAGE=" localhost:$PUSH_PORT /$IMAGE_NAME_TAG "
394
394
docker tag " $IMAGE " " $REGISTRY_IMAGE "
407
407
REMOTE_REGISTRY_IMAGE=" "
408
408
# Pull image from unregistry if remote Docker doesn't uses containerd image store.
409
409
# shellcheck disable=SC2029
410
- if ! ssh " ${SSH_ARGS[@]} " " $REMOTE_SUDO docker info -f '{{ .DriverStatus }}' | grep -q 'containerd.snapshotter'" ; then
410
+ if ssh " ${SSH_ARGS[@]} " " $REMOTE_SUDO docker info -f '{{ .DriverStatus }}' | grep -q 'containerd.snapshotter'" ; then
411
+ # Remote image store uses containerd, so we can use the image directly.
412
+ REMOTE_REGISTRY_IMAGE=" $IMAGE_NAME_TAG "
413
+ else
411
414
info " Remote Docker doesn't use containerd image store. Pulling image from unregistry..."
412
-
413
415
REMOTE_REGISTRY_IMAGE=" localhost:$UNREGISTRY_PORT /$IMAGE_NAME_TAG "
414
416
if ! ssh " ${SSH_ARGS[@]} " " $REMOTE_SUDO docker pull $REMOTE_REGISTRY_IMAGE " ; then
415
417
error " Failed to pull image from unregistry on remote host."
416
418
fi
417
- else
418
- REMOTE_REGISTRY_IMAGE=" $REGISTRY_IMAGE "
419
419
fi
420
420
421
+ # shellcheck disable=SC2029
421
422
if ! ssh " ${SSH_ARGS[@]} " " $REMOTE_SUDO docker tag $REMOTE_REGISTRY_IMAGE $IMAGE " ; then
422
423
error " Failed to retag image on remote host $REMOTE_REGISTRY_IMAGE → $IMAGE "
423
424
fi
425
+ # shellcheck disable=SC2029
424
426
ssh " ${SSH_ARGS[@]} " " $REMOTE_SUDO docker rmi $REMOTE_REGISTRY_IMAGE " > /dev/null || true
425
427
426
428
info " Removing unregistry container on remote host..."
0 commit comments