@@ -321,6 +321,19 @@ 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 "
332
+ return 0
333
+ else
334
+ error " Error parsing reference $IMAGE is not a valid repository/tag: invalid reference format"
335
+ fi
336
+ }
324
337
325
338
# Function to cleanup resources
326
339
# TODO: review cleanup
@@ -375,8 +388,9 @@ if is_additional_tunneling_needed; then
375
388
success " Additional tunnel created: localhost:$PUSH_PORT → localhost:$LOCAL_PORT "
376
389
fi
377
390
391
+ IMAGE_NAME_TAG=$( extract_image_name_and_tag)
378
392
# Tag and push the image to unregistry through the forwarded port.
379
- REGISTRY_IMAGE=" localhost:$PUSH_PORT /$IMAGE "
393
+ REGISTRY_IMAGE=" localhost:$PUSH_PORT /$IMAGE_NAME_TAG "
380
394
docker tag " $IMAGE " " $REGISTRY_IMAGE "
381
395
info " Pushing '$REGISTRY_IMAGE ' to unregistry..."
382
396
@@ -390,20 +404,24 @@ if ! docker push ${DOCKER_PUSH_OPTS[@]+"${DOCKER_PUSH_OPTS[@]}"} "$REGISTRY_IMAG
390
404
error " Failed to push image."
391
405
fi
392
406
407
+ REMOTE_REGISTRY_IMAGE=" "
393
408
# Pull image from unregistry if remote Docker doesn't uses containerd image store.
394
409
# shellcheck disable=SC2029
395
410
if ! ssh " ${SSH_ARGS[@]} " " $REMOTE_SUDO docker info -f '{{ .DriverStatus }}' | grep -q 'containerd.snapshotter'" ; then
396
411
info " Remote Docker doesn't use containerd image store. Pulling image from unregistry..."
397
412
398
- remote_registry_image =" localhost:$UNREGISTRY_PORT /$IMAGE "
399
- if ! ssh " ${SSH_ARGS[@]} " " $REMOTE_SUDO docker pull $remote_registry_image " ; then
413
+ REMOTE_REGISTRY_IMAGE =" localhost:$UNREGISTRY_PORT /$IMAGE_NAME_TAG "
414
+ if ! ssh " ${SSH_ARGS[@]} " " $REMOTE_SUDO docker pull $REMOTE_REGISTRY_IMAGE " ; then
400
415
error " Failed to pull image from unregistry on remote host."
401
416
fi
402
- if ! ssh " ${SSH_ARGS[@]} " " $REMOTE_SUDO docker tag $remote_registry_image $IMAGE " ; then
403
- error " Failed to retag image on remote host $remote_registry_image → $IMAGE "
404
- fi
405
- ssh " ${SSH_ARGS[@]} " " $REMOTE_SUDO docker rmi $remote_registry_image " > /dev/null || true
417
+ else
418
+ REMOTE_REGISTRY_IMAGE=" $REGISTRY_IMAGE "
419
+ fi
420
+
421
+ if ! ssh " ${SSH_ARGS[@]} " " $REMOTE_SUDO docker tag $REMOTE_REGISTRY_IMAGE $IMAGE " ; then
422
+ error " Failed to retag image on remote host $REMOTE_REGISTRY_IMAGE → $IMAGE "
406
423
fi
424
+ ssh " ${SSH_ARGS[@]} " " $REMOTE_SUDO docker rmi $REMOTE_REGISTRY_IMAGE " > /dev/null || true
407
425
408
426
info " Removing unregistry container on remote host..."
409
427
# shellcheck disable=SC2029
0 commit comments