-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Description
What is the problem?
When loading an image tarball that has different contents, but the same image tag, it will fail to load with an error similar to the following:
Error parsing reference: "The image bazel/projects/my_image:my_image already exists, renaming the old one with ID sha256:b9bf91fbc75ee3d7f9d78c7c2f27d06205f8c71f274b444ebfe573c9d159c26f to empty string\nbazel/projects/my_image:my_image" is not a valid repository/tag: invalid reference format: repository name must be lowercase
Reproduction Steps
This is a complete example script to show reproduce the root cause error without a bunch of CDK code:
echo "FROM busybox\nWORKDIR /" | docker build -t cdk_example:test -
docker save cdk_example:test -o test.tar
echo "FROM busybox\nWORKDIR /different" | docker build -t cdk_example:test -
docker load -i test.tar
When executing that final load, you'll get the output:
The image cdk_example:test already exists, renaming the old one with ID sha256:3e782920eed15d9f99ae20b58d734022aacd6f510a128c3baad4377b3541b419 to empty string
Loaded image: cdk_example:test
When CDK itself loads an image, it gets the repository and tag for an image by piping the output of docker load to sed "s/Loaded image: //g"
If that sed command is run on the typical output, you correctly get the image name. But when run on the output above, you get:
The image cdk_example:test already exists, renaming the old one with ID sha256:3e782920eed15d9f99ae20b58d734022aacd6f510a128c3baad4377b3541b419 to empty string
cdk_example:test
Which then fails when CDK attempts to re-tag the image for upload to ECR.
What did you expect to happen?
The image would deploy successfully
What actually happened?
The image fails to deploy when trying to load the tarball for pushing
CDK CLI Version
2.9.0 (build a69725c)
Framework Version
No response
Node.js Version
v16.13.2
OS
Linux
Language
Python
Language Version
No response
Other information
The following sed command is able to accurately extract the image name:
sed -nr 's/^Loaded image: (.*)$/\1/p'
Credit to this comment for a more robust way to do this: docker/cli#2212 (comment)