acr
acr copied to clipboard
Dockerfile with extension is interpreted as YAML
Describe the bug
When running a command like this:
az acr task create --registry my-registry \
--name php-build-task \
--file Dockerfile.php \
--context 'https://github.com/hut8/base-images.git#main' \
--git-access-token 'TOKEN HERE' \
-t 'base-php:{{.Run.ID}}'
I very mysteriously get:
failed to unmarshal task before running: failed to deserialize task and validate: yaml: line 5: could not find expected ':'
I was very confused because there was no YAML anywhere.
Google pointed me to this issue: https://github.com/Azure/acr/issues/390 which only partially helped me. It made me realize that --file can either specify a YAML file or a Dockerfile. I then began to believe that maybe the Dockerfile was being interpreted as a YAML file.
There seems to be some logic in Azure that will determine whether the file specified with --file is a Dockerfile or a YAML descriptor of a potentially multi-step build process. That logic seems to be a little faulty. I have a Dockerfile.base which defines my organization's most basic image. That one is correctly detected as a Dockerfile. Then, I need to build an image that has the correct installation of PHP. Following a convention I've seen elsewhere (for example, this post which specifies multiple Dockerfiles differing only by their "extension" ), I named this Dockerfile.php
Replacing the first command in this bug report with:
az acr task create --registry my-registry \
--name php-build-task \
--file Dockerfile-php \ # Change happens here - dot to dash!
--context 'https://github.com/hut8/base-images.git#main' \
--git-access-token 'TOKEN HERE' \
-t 'base-php:{{.Run.ID}}'
succeeds. The only change is Dockerfile.php becomes Dockerfile-php.
To Reproduce
Steps to reproduce the behavior:
- Create two identical, valid Dockerfiles: one named Dockerfile.php and one named Dockerfile-php
- Run first and last commands in section above
- First one breaks, second one succeeds
Expected behavior
Dockerfile.php will be interpreted as a Dockerfile. I think that Dockerfile.* should be considered a dockerfile.
Screenshots
None.
Any relevant environment information
- Azure CLI:
{
"azure-cli": "2.58.0",
"azure-cli-core": "2.58.0",
"azure-cli-telemetry": "1.1.0",
"extensions": {}
}
- OS: Mac
- Azure CLI/PowerShell/SDK version
Additional context
None
The tasks create command determines which of the supported 3 types of tasks (FilteTaskStep, EncodedTaskStep and DockerBuildStep) needs to process based on the parameters input. If a context path is provided (-c) it discards EnconcedTaskStep scenario and checks for the file extension. Then if the file extension is any of the following: '.yaml', '.yml', '.toml', '.json', '.sh', '.bash', '.zsh', '.ps1', '.ps', '.cmd', '.bat', '.ts', '.js', '.php', '.py', '.rb', '.lua', it assumes is a FileTaskStep, otherwise, it'll treat it as a dockerBuildStep. Since php was not part of the allowed task file steps extensions in the CLI, it's handling php files or any other that don't match the previous list as a Docker file.