docker-build-with-cache-action
docker-build-with-cache-action copied to clipboard
YAML is not parsed correctly
I originally discovered this as a bug where a docker-compose file containing image:
would also require setting build: context:
For example, this docker-compose file should build successfully:
version: "3"
services:
nginx:
image: registry.hub.docker.com/library/nginx
using this workflow:
name: foo
jobs:
foo:
steps:
- uses: whoan/[email protected]
with:
registry: registry.hub.docker.com
compose_file: docker-compose.yml
however it fails with the following:
[Compose file] Building image: registry.hub.docker.com/library/nginx
Failed to get context
Expanding the docker-compose to
version: "3"
services:
nginx:
image: registry.hub.docker.com/library/nginx
build:
context: .
resolves the issue, but this should not be needed -- we have all of the information we need to build the image.
After poking around more I realized this is due to how the tool attempts to parse YAML, which ultimately creates a number of additional bugs:
- Adding additional but valid spaces in front of the
foo
example above causes a failure withFailed to get service name
, because the parser doesn't account for inconsistent indentation levels (valid in YAML). - Adding a comment anywhere after a key causes the entire line to be consumed by the tool. So for example
image: nginx # ignore me
attempts to fetch an image callednginx # ignore me
from the registry.
Instead of trying to re-implement YAML parsing, the tool should instead consume the compose file via an existing YAML parser. This would simplify service & registry discovery and make for a more user-friendly API.