Workaround hash tagger incorrect parsed image ref
Fixes: #9830
Description
Buildkit AST parser library seems to return 'image:latest' when a FROM has a variable expansion template instead of the actual image name, for example, $BASE in the following stanza:
ARG BASE
FROM $BASE AS base
This breaks input digest tagger for images that have a dependency to other skaffold build artifacts, as parseOnbuild later fails to pull the incorrect/inexistent image.
Note that empty images in the from were being ignored, but no this incorrect value. So, as a workaround, this condition is extended to include and ignore incorrect 'image:latest' values.
Actual digest seems not affected, changes in parent base dockerfiles are still computed for the digest via the transitive dependencies.
A more complete fix would be to inject the proper resolved image refs in expandBuildArgs (so correct image is downloaded and ONBUILD instructions can be properly parsed), but this will need to solve the issue in buildkit parser to return the template.
Also, probably it will require having pre-computed the previous image tags dependencies.
Full error message:
generating tag: evaluating custom template component: parsing ONBUILD instructions: retrieving image \"image:latest\": GET https://index.docker.io/v2/library/image/manifests/latest: UNAUTHORIZED: authentication required; [map[Action:pull Class: Name:library/image Type:repository]]
User facing changes
Example for simple artifact has been updated to show/reproduce, check in tests & confirm fix for issue #9830
Before (note that taggers failed and image is not found, being rebuilt unnecessarily):
$ skaffold build
Generating tags...
- app -> localhost:32000/app:latest
- base -> localhost:32000/base:f06ab6582db5b2f039bbfe557419b897c31a4161c69c6e7c7832f839b021a7e4
Some taggers failed. Rerun with -vdebug for errors.
Checking cache...
- app: Not found. Building
- base: Found Remotely
Starting build...
After (note tagger works ok):
$ ../../out/skaffold build
Generating tags...
- app -> localhost:32000/app:6e10fde24150d5d16ab976db4d4f5a479522d3f82aa38606b7f15e1aef18be00
- base -> localhost:32000/base:f06ab6582db5b2f039bbfe557419b897c31a4161c69c6e7c7832f839b021a7e4
Checking cache...
- app: Found. Tagging
- base: Found Remotely
Can you rebase this? I think the Windows unit tests will pass once #9880 is in your branch. Thanks and sorry for the delay