Sort the labels passed from build --labels#29624
Conversation
builder/dockerfile/builder.go
Outdated
There was a problem hiding this comment.
nit: we can trim the space here, and use strings.Join() instead of the loop in L246-L248.
There was a problem hiding this comment.
Probably this can be moved to UT, but I think it is ok to keep this IT at the moment.
There was a problem hiding this comment.
Thanks @AkihiroSuda. In #29619 the issue was only triggered by docker build --label A=A --label B=B ... through command line. LABEL inside Dockerfile directly will not trigger the issue. So I think it probably make sense to have a IT for it.
There was a problem hiding this comment.
I agree this should really be a unit test. Every bug is technically invoked from either the CLI or API, but I don't think that necessarily warrants an integration test. Integration tests are great for catching regressions where the bug was because of an integration between two components.
In this case the bug seems to be in a single component, so it could be tested directly.
A rule I like to follow is that if a function is hard to unit test, it's a good sign the function should be refactored in a way that makes it easier to test. Functions that are hard to test are often hard to re-use as well. Since this function is 100 lines long, it is difficult to test the behaviour in isolation. It might not be a bad idea to split it up, making it easier to test.
db9b50e to
4244624
Compare
|
LGTM |
4244624 to
ce089dd
Compare
|
Thanks @AkihiroSuda @dnephin. The PR has been updated with unit test. The Please take a look. |
ce089dd to
1bf2c13
Compare
|
1bf2c13 to
bf854ad
Compare
|
Thanks @cpuguy83 The PR has been updated. |
builder/dockerfile/builder_test.go
Outdated
There was a problem hiding this comment.
you may want to put the labels in out-of-order to test sording actually works. e.g. org.c, org.a, org.d, ...
There was a problem hiding this comment.
For clarity, yes I agree.
In practice, it won't make a difference, because Go always randomizes map order; see https://nathanleclaire.com/blog/2014/04/27/a-surprising-feature-of-golang-that-colored-me-impressed/
There was a problem hiding this comment.
@briceburg The map is always randomized:
ubuntu@ubuntu:~/tmp$ cat main.go
package main
import (
"fmt"
)
func main() {
labels := map[string]string{
"org.a": "cli-a",
"org.b": "cli-b",
"org.c": "cli-c",
"org.d": "cli-d",
"org.e": "cli-e",
}
for k, v := range labels {
fmt.Println(k, v)
}
}
ubuntu@ubuntu:~/tmp$
ubuntu@ubuntu:~/tmp$ go run main.go
org.a cli-a
org.b cli-b
org.c cli-c
org.d cli-d
org.e cli-e
ubuntu@ubuntu:~/tmp$ go run main.go
org.e cli-e
org.a cli-a
org.b cli-b
org.c cli-c
org.d cli-d
ubuntu@ubuntu:~/tmp$ go run main.go
org.d cli-d
org.e cli-e
org.a cli-a
org.b cli-b
org.c cli-c
ubuntu@ubuntu:~/tmp$ go run main.go
org.b cli-b
org.c cli-c
org.d cli-d
org.e cli-e
org.a cli-a
ubuntu@ubuntu:~/tmp$
I updated the PR to shuffle the order though to make it clear though.
There was a problem hiding this comment.
Yes, totally unnecessary but perhaps more clear to a gomature like myself. boy do I have a lot to learn! 😄
Many thanks for sharing, and for jumping on the label issue so quickly! It's inspiring to witness this project work.
bf854ad to
027ed81
Compare
|
@yongtang some tests failed |
This fix tries to fix the issue in 29619 where labels passed from `build --labels` are not sorted. As a result, if multiple labels have been passed, each `docker build --labels A=A --labels B=B --labels C=C` will generate different layers. This fix fixes the issue by sort the Labels before they are concatenated to `LABEL ...`. A unit test has been added to cover the changes This fix fixes 29619. Signed-off-by: Yong Tang <[email protected]>
027ed81 to
d32efdb
Compare
|
Thanks @coolljt0725 I tested locally and those tests passed. Think it might be flaky. Added an issue #29663 and will keep an eye on it. |
- What I did
This fix tries to fix the issue in #29619 where labels passed from
build --labelsare not sorted.As a result, if multiple labels have been passed, each
docker build --labels A=A --labels B=B --labels C=Crun will generate different layers.- How I did it
This fix fixes the issue by sort the Labels before they are concatenated to
LABEL ....- How to verify it
An integration test has been added to cover the changes
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)
This fix fixes #29619.
Signed-off-by: Yong Tang [email protected]