dotnet / docker-tools

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

Fix regex for FROM image overwrite #1109

Closed mthalman closed 1 year ago

mthalman commented 1 year ago

The changes from https://github.com/dotnet/dotnet-buildtools-prereqs-docker/pull/754 caused a failure in the internal build:

Error response from daemon: dockerfile parse error line 1: FROM requires either one or three arguments

This occurs because Image Builder is incorrectly rewriting the Dockerfile to target the locally built tag instead of the public MCR tag. It ends up replacing the whitespace between the end of the tag and the AS keyword, producing this FROM instruction: FROM dotnetdocker.azurecr.io/build-staging/2090449/dotnet-buildtools/prereqs:ubuntu-20.04-crossdeps-localAS binutils. Notice there's no space before AS. This is invalid syntax and causes the error to occur.

This is fixed by using the correct character class in the Regex which does the string replacement. The string its search to replace should stop before hitting any whitespace (\s) but it was using the non-whitespace character class (\S).

dotnet-issue-labeler[bot] commented 1 year ago

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.