Azure / acr

Azure Container Registry samples, troubleshooting tips and references
https://aka.ms/acr
Other
162 stars 106 forks source link

Dockerfile with extension is interpreted as YAML #744

Open hut8 opened 3 months ago

hut8 commented 3 months ago

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:

  1. Create two identical, valid Dockerfiles: one named Dockerfile.php and one named Dockerfile-php
  2. Run first and last commands in section above
  3. 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

Additional context

None

rosanch commented 2 months ago

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.