estesp / manifest-tool

Command line tool to create and query container image manifest list/indexes
Apache License 2.0
741 stars 92 forks source link

Reword error about image mismatch #171

Closed jsoref closed 2 years ago

jsoref commented 2 years ago

There's a long story here -- usually I randomly visit repositories and offer spelling fixes. But in this case, I'm actually trying to fix a real problem in another repository and hoping to use manifest-tool to achieve that.

The main goal is to be able to add a new tag (latest) to a specific image. But, my testing environment doesn't have enough things (and I don't have write access to docker hub), so I'm cheating by trying to copy an image from docker hub to gcr.io.

Anyway, here's the step's I'm taking:

  1. use inspect to get a list of images (in a format that I get to massage)
  2. cat that file (or use manifest-tool on busybox:latest, which in theory is what i'm trying to do, but, I don't want to upset docker hub limits -- I did that while trying to make a PR to add manifest-tool to brew.sh...) and convert it into a format that would be compatible w/ manifest-tool push
  3. use push to create a new tag for my image
% manifest-tool inspect gcr.io/$GCR_PROJECT/josh/busybox:extra-tag > foox
% (cat foox || manifest-tool inspect busybox:latest) |perl -e 'while (<>) { if (/^Name:\s+(\S+):/) {
print "image: $1:latest\n"."manifests:\n";
} elsif (/Digest: (\S+)/) { 
$digest=$1; 
} elsif (/OS: (\S+)/) {
$os=$1;
} elsif (/Arch: (\S+)/) {
print "- image: $digest\n  platform:\n    architecture: $1\n    os: $os\n"; $os=""; $digest=""; 
} 
}' > fooy
% cat fooy
image: gcr.io/$GCR_PROJECT/josh/busybox:latest
manifests:
- image: sha256:2c5e2045f35086c019e80c86880fd5b7c7a619878b59e3b7592711e1781df51a
  platform:
    architecture: arm64
    os: linux
- image: sha256:dcdf379c574e1773d703f0c0d56d67594e7a91d6b84d11ff46799f60fb081c52
  platform:
    architecture: amd64
    os: linux
% manifest-tool push from-spec fooy
FATA[0000] Cannot use source images from a different registry than the target image: docker.io != gcr.io 

This message is problematic:

FATA[0000] Cannot use source images from a different registry than the target image: docker.io != gcr.io

This would be easier to read:

FATA[0000] Cannot use source images from a registry (docker.io) different than the target image (gcr.io)

But, it'd probably be better to use full image tags instead of just registry names. I have no idea what docker.io is in this context. Or even what gcr.io is. My manifest only has one gcr.io. It turns out that the image things I generated were bad (and needed to have a prefix) and thus they were defaulting to docker.io.

Had the message said:

FATA[0000] Cannot use source image (docker.io/sha256:dcdf379c574e1773d703f0c0d56d67594e7a91d6b84d11ff46799f60fb081c52) from a registry (docker.io) different than the target image (gcr.io/$GCR_PROJECT/josh/busybox:latest)

It would have been much clearer what I did wrong.

Note that I'm removing the s from images. The code in question is iterating over the list and failing at first fault. It has a specific image in mind, and might as well report that image. The human running the program will deduce that the error applies to all future images and not just the one.

If there's a longer list (I only have 2 here), then telling me the specific image to look for in the longer list will make it much easier to debug what's going on than giving me a generic warning about repositories.

Here's a fixed version of my script ```sh (cat foox || manifest-tool inspect busybox:latest) |perl -e 'while (<>) { if (/^Name:\s+(\S+):/) { $name=$1; print "image: $name:latest\n"."manifests:\n"; } elsif (/Digest: (\S+)/) { $digest=$1; } elsif (/OS: (\S+)/) { $os=$1; } elsif (/Arch: (\S+)/) {print "- image: $name\@$digest\n platform:\n architecture: $1\n os: $os\n"; $os=""; $digest=""; } }' > fooy ```