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 <dennis.chen@arm.com>
| ... | ... |
@@ -350,15 +350,6 @@ func (b *Builder) dispatchDockerfileWithCancellation(parseResult []instructions. |
| 350 | 350 |
return dispatchRequest.state, nil |
| 351 | 351 |
} |
| 352 | 352 |
|
| 353 |
-func addNodesForLabelOption(dockerfile *parser.Node, labels map[string]string) {
|
|
| 354 |
- if len(labels) == 0 {
|
|
| 355 |
- return |
|
| 356 |
- } |
|
| 357 |
- |
|
| 358 |
- node := parser.NodeFromLabels(labels) |
|
| 359 |
- dockerfile.Children = append(dockerfile.Children, node) |
|
| 360 |
-} |
|
| 361 |
- |
|
| 362 | 353 |
// BuildFromConfig builds directly from `changes`, treating it as if it were the contents of a Dockerfile |
| 363 | 354 |
// It will: |
| 364 | 355 |
// - Call parse.Parse() to get an AST root for the concatenated Dockerfile entries. |
| 365 | 356 |
deleted file mode 100644 |
| ... | ... |
@@ -1,35 +0,0 @@ |
| 1 |
-package dockerfile // import "github.com/docker/docker/builder/dockerfile" |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "strings" |
|
| 5 |
- "testing" |
|
| 6 |
- |
|
| 7 |
- "github.com/docker/docker/builder/dockerfile/parser" |
|
| 8 |
- "github.com/gotestyourself/gotestyourself/assert" |
|
| 9 |
- is "github.com/gotestyourself/gotestyourself/assert/cmp" |
|
| 10 |
-) |
|
| 11 |
- |
|
| 12 |
-func TestAddNodesForLabelOption(t *testing.T) {
|
|
| 13 |
- dockerfile := "FROM scratch" |
|
| 14 |
- result, err := parser.Parse(strings.NewReader(dockerfile)) |
|
| 15 |
- assert.Check(t, err) |
|
| 16 |
- |
|
| 17 |
- labels := map[string]string{
|
|
| 18 |
- "org.e": "cli-e", |
|
| 19 |
- "org.d": "cli-d", |
|
| 20 |
- "org.c": "cli-c", |
|
| 21 |
- "org.b": "cli-b", |
|
| 22 |
- "org.a": "cli-a", |
|
| 23 |
- } |
|
| 24 |
- nodes := result.AST |
|
| 25 |
- addNodesForLabelOption(nodes, labels) |
|
| 26 |
- |
|
| 27 |
- expected := []string{
|
|
| 28 |
- "FROM scratch", |
|
| 29 |
- `LABEL "org.a"='cli-a' "org.b"='cli-b' "org.c"='cli-c' "org.d"='cli-d' "org.e"='cli-e'`, |
|
| 30 |
- } |
|
| 31 |
- assert.Check(t, is.Len(nodes.Children, 2)) |
|
| 32 |
- for i, v := range nodes.Children {
|
|
| 33 |
- assert.Check(t, is.Equal(expected[i], v.Original)) |
|
| 34 |
- } |
|
| 35 |
-} |
| ... | ... |
@@ -10,12 +10,9 @@ import ( |
| 10 | 10 |
"encoding/json" |
| 11 | 11 |
"errors" |
| 12 | 12 |
"fmt" |
| 13 |
- "sort" |
|
| 14 | 13 |
"strings" |
| 15 | 14 |
"unicode" |
| 16 | 15 |
"unicode/utf8" |
| 17 |
- |
|
| 18 |
- "github.com/docker/docker/builder/dockerfile/command" |
|
| 19 | 16 |
) |
| 20 | 17 |
|
| 21 | 18 |
var ( |
| ... | ... |
@@ -205,34 +202,6 @@ func parseLabel(rest string, d *Directive) (*Node, map[string]bool, error) {
|
| 205 | 205 |
return node, nil, err |
| 206 | 206 |
} |
| 207 | 207 |
|
| 208 |
-// NodeFromLabels returns a Node for the injected labels |
|
| 209 |
-func NodeFromLabels(labels map[string]string) *Node {
|
|
| 210 |
- keys := []string{}
|
|
| 211 |
- for key := range labels {
|
|
| 212 |
- keys = append(keys, key) |
|
| 213 |
- } |
|
| 214 |
- // Sort the label to have a repeatable order |
|
| 215 |
- sort.Strings(keys) |
|
| 216 |
- |
|
| 217 |
- labelPairs := []string{}
|
|
| 218 |
- var rootNode *Node |
|
| 219 |
- var prevNode *Node |
|
| 220 |
- for _, key := range keys {
|
|
| 221 |
- value := labels[key] |
|
| 222 |
- labelPairs = append(labelPairs, fmt.Sprintf("%q='%s'", key, value))
|
|
| 223 |
- // Value must be single quoted to prevent env variable expansion |
|
| 224 |
- // See https://github.com/docker/docker/issues/26027 |
|
| 225 |
- node := newKeyValueNode(key, "'"+value+"'") |
|
| 226 |
- rootNode, prevNode = appendKeyValueNode(node, rootNode, prevNode) |
|
| 227 |
- } |
|
| 228 |
- |
|
| 229 |
- return &Node{
|
|
| 230 |
- Value: command.Label, |
|
| 231 |
- Original: commandLabel + " " + strings.Join(labelPairs, " "), |
|
| 232 |
- Next: rootNode, |
|
| 233 |
- } |
|
| 234 |
-} |
|
| 235 |
- |
|
| 236 | 208 |
// parses a statement containing one or more keyword definition(s) and/or |
| 237 | 209 |
// value assignments, like `name1 name2= name3="" name4=value`. |
| 238 | 210 |
// Note that this is a stricter format than the old format of assignment, |
| ... | ... |
@@ -42,32 +42,6 @@ func TestParseNameValNewFormat(t *testing.T) {
|
| 42 | 42 |
assert.DeepEqual(t, expected, node, cmpNodeOpt) |
| 43 | 43 |
} |
| 44 | 44 |
|
| 45 |
-func TestNodeFromLabels(t *testing.T) {
|
|
| 46 |
- labels := map[string]string{
|
|
| 47 |
- "foo": "bar", |
|
| 48 |
- "weird": "first' second", |
|
| 49 |
- } |
|
| 50 |
- expected := &Node{
|
|
| 51 |
- Value: "label", |
|
| 52 |
- Original: `LABEL "foo"='bar' "weird"='first' second'`, |
|
| 53 |
- Next: &Node{
|
|
| 54 |
- Value: "foo", |
|
| 55 |
- Next: &Node{
|
|
| 56 |
- Value: "'bar'", |
|
| 57 |
- Next: &Node{
|
|
| 58 |
- Value: "weird", |
|
| 59 |
- Next: &Node{
|
|
| 60 |
- Value: "'first' second'", |
|
| 61 |
- }, |
|
| 62 |
- }, |
|
| 63 |
- }, |
|
| 64 |
- }, |
|
| 65 |
- } |
|
| 66 |
- |
|
| 67 |
- node := NodeFromLabels(labels) |
|
| 68 |
- assert.DeepEqual(t, expected, node, cmpNodeOpt) |
|
| 69 |
-} |
|
| 70 |
- |
|
| 71 | 45 |
func TestParseNameValWithoutVal(t *testing.T) {
|
| 72 | 46 |
directive := Directive{}
|
| 73 | 47 |
// In Config.Env, a variable without `=` is removed from the environment. (#31634) |