dotnet / docker-tools

This is a repo to house some common tools for our various docker repos.
MIT License
122 stars 46 forks source link

Images retrieved from cache are tagged with new dynamic tag value #1102

Open mthalman opened 1 year ago

mthalman commented 1 year ago

For repos like https://github.com/dotnet/dotnet-buildtools-prereqs-docker where the tags contain dynamically generated values like a timestamp, there's an issue when applied to cache images. If the image gets a cache hit and is pulled from the registry, it ends up getting tagged with the new dynamically generated tag rather than its original tag. This new tag gets pushed as well.

An example: The Dockerfile in https://github.com/dotnet/dotnet-buildtools-prereqs-docker with path src/ubuntu/22.04/cross/arm-alpine gets built. The tag of the previously published image is ubuntu-22.04-cross-arm-alpine-20221207144316-3fc5553. During the build, it detects a cache hit and pulls it from the registry. As part of loading the manifest, it dynamically generates a new tag value of ubuntu-22.04-cross-arm-alpine-20230106221608-3fc5553 and tags the image with that and pushes that tag. Now the image is tagged with both of those tags.

This is not good because a new tag implies a new image but it's actually just a new tag on the original cached image.

The pending changes in https://github.com/dotnet/docker-tools/pull/1091 do not fix this issue either.