Skip to content

Commit

Permalink
Remove unused 'label' related functions
Browse files Browse the repository at this point in the history
Since we use `NewLabelCommand()` instead of `addNodesForLabelOption()`
to create the 'LABEL' commands from '--label' options, so all the related
functions should be removed.

Signed-off-by: Dennis Chen <[email protected]>
  • Loading branch information
arm64b committed May 17, 2018
1 parent f7add42 commit c7b5431
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 101 deletions.
9 changes: 0 additions & 9 deletions builder/dockerfile/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
35 changes: 0 additions & 35 deletions builder/dockerfile/builder_test.go

This file was deleted.

31 changes: 0 additions & 31 deletions builder/dockerfile/parser/line_parsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ import (
"encoding/json"
"errors"
"fmt"
"sort"
"strings"
"unicode"
"unicode/utf8"

"github.com/docker/docker/builder/dockerfile/command"
)

var (
Expand Down Expand Up @@ -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,
Expand Down
26 changes: 0 additions & 26 deletions builder/dockerfile/parser/line_parsers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c7b5431

Please sign in to comment.