Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overwriting existing ARG value leads to duplication in history #5505

Open
tianon opened this issue Nov 9, 2024 · 0 comments · May be fixed by #5508
Open

overwriting existing ARG value leads to duplication in history #5505

tianon opened this issue Nov 9, 2024 · 0 comments · May be fixed by #5508

Comments

@tianon
Copy link
Member

tianon commented Nov 9, 2024

(all credit for this goes out to @serious-angel / Lore in the #docker channel on Libera.Chat, who discovered this bug and was ready to file an issue before I stole their thunder! 🙇 ❤️ 🙈)

The basic gist is that specifying an ARG more than once appropriately overwrites the previous value, but the "history" entries in the resulting image end up with one copy of the value for every "reset".

FROM busybox
ARG foo=bar
RUN echo $foo # prints "bar"
ARG foo=baz
RUN echo $foo # prints "baz"
ARG foo=
RUN echo $foo # prints the empty string

I made a builder named master from a build against commit c9a17ff (current master branch tip), and verified it's still an issue there:

$ docker buildx build --builder master --pull .
...
#9 exporting to docker image format
#9 exporting layers 0.1s done
#9 exporting manifest sha256:b6da5b1e8eed59b5b8b073657c3d70d7cb49ac027bfde5dcfda3f2bcd0013617 done
#9 exporting config sha256:680eea8c842b72f0efe81874bdfb2591c640f756ebbfdc5a4fee476a776525c7 done
#9 sending tarball 0.2s done
#9 DONE 0.2s

And then what I got:

$ docker history sha256:680eea8c842b72f0efe81874bdfb2591c640f756ebbfdc5a4fee476a776525c7
IMAGE          CREATED          CREATED BY                                      SIZE      COMMENT
680eea8c842b   23 seconds ago   RUN |3 foo= foo= foo= /bin/sh -c echo $foo #…   0B        buildkit.dockerfile.v0
<missing>      23 seconds ago   ARG foo=                                        0B        buildkit.dockerfile.v0
<missing>      23 seconds ago   RUN |2 foo=baz foo=baz /bin/sh -c echo $foo …   0B        buildkit.dockerfile.v0
<missing>      23 seconds ago   ARG foo=baz                                     0B        buildkit.dockerfile.v0
<missing>      23 seconds ago   RUN |1 foo=bar /bin/sh -c echo $foo # prints…   0B        buildkit.dockerfile.v0
<missing>      23 seconds ago   ARG foo=bar                                     0B        buildkit.dockerfile.v0
<missing>      6 weeks ago      BusyBox 1.37.0 (glibc), Debian 12               4.27MB    

(note RUN |3 foo= foo= foo= , RUN |2 foo=baz foo=baz , RUN |1 foo=bar )

Vs what I expected (output simulated by hand, please forgive errors 😂):

$ docker history sha256:680eea8c842b72f0efe81874bdfb2591c640f756ebbfdc5a4fee476a776525c7
IMAGE          CREATED          CREATED BY                                      SIZE      COMMENT
680eea8c842b   23 seconds ago   RUN |1 foo= /bin/sh -c echo $foo # prints th…   0B        buildkit.dockerfile.v0
<missing>      23 seconds ago   ARG foo=                                        0B        buildkit.dockerfile.v0
<missing>      23 seconds ago   RUN |1 foo=baz /bin/sh -c echo $foo # prints…   0B        buildkit.dockerfile.v0
<missing>      23 seconds ago   ARG foo=baz                                     0B        buildkit.dockerfile.v0
<missing>      23 seconds ago   RUN |1 foo=bar /bin/sh -c echo $foo # prints…   0B        buildkit.dockerfile.v0
<missing>      23 seconds ago   ARG foo=bar                                     0B        buildkit.dockerfile.v0
<missing>      6 weeks ago      BusyBox 1.37.0 (glibc), Debian 12               4.27MB    

And the diff, to be extra clear:

 $ docker history sha256:680eea8c842b72f0efe81874bdfb2591c640f756ebbfdc5a4fee476a776525c7
 IMAGE          CREATED          CREATED BY                                      SIZE      COMMENT
-680eea8c842b   23 seconds ago   RUN |3 foo= foo= foo= /bin/sh -c echo $foo #…   0B        buildkit.dockerfile.v0
+680eea8c842b   23 seconds ago   RUN |1 foo= /bin/sh -c echo $foo # prints th…   0B        buildkit.dockerfile.v0
 <missing>      23 seconds ago   ARG foo=                                        0B        buildkit.dockerfile.v0
-<missing>      23 seconds ago   RUN |2 foo=baz foo=baz /bin/sh -c echo $foo …   0B        buildkit.dockerfile.v0
+<missing>      23 seconds ago   RUN |1 foo=baz /bin/sh -c echo $foo # prints…   0B        buildkit.dockerfile.v0
 <missing>      23 seconds ago   ARG foo=baz                                     0B        buildkit.dockerfile.v0
 <missing>      23 seconds ago   RUN |1 foo=bar /bin/sh -c echo $foo # prints…   0B        buildkit.dockerfile.v0
 <missing>      23 seconds ago   ARG foo=bar                                     0B        buildkit.dockerfile.v0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants