diff --git a/builder/dockerfile/builder.go b/builder/dockerfile/builder.go index c63661e7f8..1455fd966e 100644 --- a/builder/dockerfile/builder.go +++ b/builder/dockerfile/builder.go @@ -350,15 +350,6 @@ func (b *Builder) dispatchDockerfileWithCancellation(parseResult []instructions. return dispatchRequest.state, nil } -func addNodesForLabelOption(dockerfile *parser.Node, labels map[string]string) { - if len(labels) == 0 { - return - } - - node := parser.NodeFromLabels(labels) - dockerfile.Children = append(dockerfile.Children, node) -} - // BuildFromConfig builds directly from `changes`, treating it as if it were the contents of a Dockerfile // It will: // - Call parse.Parse() to get an AST root for the concatenated Dockerfile entries. diff --git a/builder/dockerfile/builder_test.go b/builder/dockerfile/builder_test.go deleted file mode 100644 index 6c73b6cced..0000000000 --- a/builder/dockerfile/builder_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package dockerfile // import "github.com/docker/docker/builder/dockerfile" - -import ( - "strings" - "testing" - - "github.com/docker/docker/builder/dockerfile/parser" - "github.com/gotestyourself/gotestyourself/assert" - is "github.com/gotestyourself/gotestyourself/assert/cmp" -) - -func TestAddNodesForLabelOption(t *testing.T) { - dockerfile := "FROM scratch" - result, err := parser.Parse(strings.NewReader(dockerfile)) - assert.Check(t, err) - - labels := map[string]string{ - "org.e": "cli-e", - "org.d": "cli-d", - "org.c": "cli-c", - "org.b": "cli-b", - "org.a": "cli-a", - } - nodes := result.AST - addNodesForLabelOption(nodes, labels) - - expected := []string{ - "FROM scratch", - `LABEL "org.a"='cli-a' "org.b"='cli-b' "org.c"='cli-c' "org.d"='cli-d' "org.e"='cli-e'`, - } - assert.Check(t, is.Len(nodes.Children, 2)) - for i, v := range nodes.Children { - assert.Check(t, is.Equal(expected[i], v.Original)) - } -} diff --git a/builder/dockerfile/parser/line_parsers.go b/builder/dockerfile/parser/line_parsers.go index 94091f5f6b..c454835373 100644 --- a/builder/dockerfile/parser/line_parsers.go +++ b/builder/dockerfile/parser/line_parsers.go @@ -10,12 +10,9 @@ import ( "encoding/json" "errors" "fmt" - "sort" "strings" "unicode" "unicode/utf8" - - "github.com/docker/docker/builder/dockerfile/command" ) var ( @@ -205,34 +202,6 @@ func parseLabel(rest string, d *Directive) (*Node, map[string]bool, error) { return node, nil, err } -// NodeFromLabels returns a Node for the injected labels -func NodeFromLabels(labels map[string]string) *Node { - keys := []string{} - for key := range labels { - keys = append(keys, key) - } - // Sort the label to have a repeatable order - sort.Strings(keys) - - labelPairs := []string{} - var rootNode *Node - var prevNode *Node - for _, key := range keys { - value := labels[key] - labelPairs = append(labelPairs, fmt.Sprintf("%q='%s'", key, value)) - // Value must be single quoted to prevent env variable expansion - // See https://github.com/docker/docker/issues/26027 - node := newKeyValueNode(key, "'"+value+"'") - rootNode, prevNode = appendKeyValueNode(node, rootNode, prevNode) - } - - return &Node{ - Value: command.Label, - Original: commandLabel + " " + strings.Join(labelPairs, " "), - Next: rootNode, - } -} - // parses a statement containing one or more keyword definition(s) and/or // value assignments, like `name1 name2= name3="" name4=value`. // Note that this is a stricter format than the old format of assignment, diff --git a/builder/dockerfile/parser/line_parsers_test.go b/builder/dockerfile/parser/line_parsers_test.go index 50b8d03c23..f7580efa3e 100644 --- a/builder/dockerfile/parser/line_parsers_test.go +++ b/builder/dockerfile/parser/line_parsers_test.go @@ -42,32 +42,6 @@ func TestParseNameValNewFormat(t *testing.T) { assert.DeepEqual(t, expected, node, cmpNodeOpt) } -func TestNodeFromLabels(t *testing.T) { - labels := map[string]string{ - "foo": "bar", - "weird": "first' second", - } - expected := &Node{ - Value: "label", - Original: `LABEL "foo"='bar' "weird"='first' second'`, - Next: &Node{ - Value: "foo", - Next: &Node{ - Value: "'bar'", - Next: &Node{ - Value: "weird", - Next: &Node{ - Value: "'first' second'", - }, - }, - }, - }, - } - - node := NodeFromLabels(labels) - assert.DeepEqual(t, expected, node, cmpNodeOpt) -} - func TestParseNameValWithoutVal(t *testing.T) { directive := Directive{} // In Config.Env, a variable without `=` is removed from the environment. (#31634)