Add 'LABEL' command from '--label' to the last stage

This PR is tring to fix issue #36996.

Currently for multi-stage build, if `--target` specified, the `--label` option
will be ignored. The root cause is the last stage build will remove the `LABEL`
command(s) node created from the `--label` option. In order to address this issue,
we can create `LABEL` command(s) and add it/tem to the last stage.

Signed-off-by: Dennis Chen <dennis.chen@arm.com>

rewritten from github.com/moby/moby 9c238ebd55e4105ad7f7edc04231ea61bb278ae8
docker-18.09
Dennis Chen 2018-05-07 13:28:55 +08:00 committed by Tonis Tiigi
parent 29887cc5b2
commit c35701d68d
1 changed files with 21 additions and 1 deletions

View File

@ -110,17 +110,37 @@ type MaintainerCommand struct {
Maintainer string
}
// NewLabelCommand creates a new 'LABEL' command
func NewLabelCommand(k string, v string, NoExp bool) *LabelCommand {
kvp := KeyValuePair{Key: k, Value: v}
c := "LABEL "
c += kvp.String()
nc := withNameAndCode{code: c, name: "label"}
cmd := &LabelCommand{
withNameAndCode: nc,
Labels: KeyValuePairs{
kvp,
},
noExpand: NoExp,
}
return cmd
}
// LabelCommand : LABEL some json data describing the image
//
// Sets the Label variable foo to bar,
//
type LabelCommand struct {
withNameAndCode
Labels KeyValuePairs // kvp slice instead of map to preserve ordering
Labels KeyValuePairs // kvp slice instead of map to preserve ordering
noExpand bool
}
// Expand variables
func (c *LabelCommand) Expand(expander SingleWordExpander) error {
if c.noExpand {
return nil
}
return expandKvpsInPlace(c.Labels, expander)
}