docker / cli

The Docker CLI
Apache License 2.0
4.91k stars 1.93k forks source link

20.10.8 introduces breaking change to go templates #3241

Open razzeee opened 3 years ago

razzeee commented 3 years ago

Description Running 20.10.8 we're getting errors with our template parsing.

Steps to reproduce the issue:

  1. Try to run the cli with a command similar to docker run --detach --network="$NETWORK_NAME" $(echo --env LOG_LEVEL=$(docker inspect --format='{{((index .Config.Labels "loglevel") 0)}}' $IMAGE_NAME:$IMAGE_TAG_FEATURE))
  2. It should fail.

Describe the results you received:

Template parsing error: template: :1:3: executing "" at <(index .Config.Labels "loglevel") 0>: can't give argument to non-function index .Config.Labels "loglevel"

Describe the results you expected: It should parse without an error, as it does with version 20.10.7 - a breaking change with a bugfix version is surprising.

Additional environment details (AWS, VirtualBox, physical, etc.): Virtual runner controlled via gitlab

bruegth commented 3 years ago

Maybe related to golang update from 1.13 to 1.16 from this commit (https://github.com/docker/cli/commit/a477a727fccdcd392ad495076b99c359af8f8d18)

Because of this text/template change in golang 1.14: https://golang.org/doc/go1.14#text/template

bruegth commented 3 years ago

Steps to reproduce the issue:

  1. docker pull timescale/timescaledb:latest-pg12
  2. docker inspect --format='{{((index .Config.Labels "maintainer") 0)}}' timescale/timescaledb:latest-pg12

Output of 20.10.7: Timescale https://www.timescale.com Output of 20.10.8: Template parsing error: template: :1:3: executing "" at <(index .Config.Labels "maintainer") (0)>: can't give argument to non-function index .Config.Labels "maintainer"

Go Template has to be modified to: docker inspect --format='{{if (index .Config.Labels \"maintainer\")}}{{index .Config.Labels \"maintainer\"}}{{else}}0{{end}}' timescale/timescaledb:latest-pg12

@thaJeztah @razzeee PTL

thaJeztah commented 3 years ago

Thanks for the ping; yes this looks indeed caused by that change in Golang.

Go mentions:

As always, there are various minor changes and updates to the library, made with the Go 1 promise of compatibility in mind.

But that compatibility is limited;

Compatibility is at the source level. Binary compatibility for compiled packages is not guaranteed between releases.

And they document it as a bugfix, which probably is considered an additional exception;

The erroneous case never worked as expected, and will now be reported with an error can't give argument to non-function.

Not sure there's much we can do 🤔