|
@@ -6,6 +6,7 @@ import (
|
|
"fmt"
|
|
"fmt"
|
|
"io"
|
|
"io"
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
|
|
+ "sort"
|
|
"strings"
|
|
"strings"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
@@ -208,13 +209,26 @@ func newBuilder(clientCtx context.Context, options builderOptions) *Builder {
|
|
return b
|
|
return b
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// Build 'LABEL' command(s) from '--label' options and add to the last stage
|
|
|
|
+func buildLabelOptions(labels map[string]string, stages []instructions.Stage) {
|
|
|
|
+ keys := []string{}
|
|
|
|
+ for key := range labels {
|
|
|
|
+ keys = append(keys, key)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Sort the label to have a repeatable order
|
|
|
|
+ sort.Strings(keys)
|
|
|
|
+ for _, key := range keys {
|
|
|
|
+ value := labels[key]
|
|
|
|
+ stages[len(stages)-1].AddCommand(instructions.NewLabelCommand(key, value, true))
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
// Build runs the Dockerfile builder by parsing the Dockerfile and executing
|
|
// Build runs the Dockerfile builder by parsing the Dockerfile and executing
|
|
// the instructions from the file.
|
|
// the instructions from the file.
|
|
func (b *Builder) build(source builder.Source, dockerfile *parser.Result) (*builder.Result, error) {
|
|
func (b *Builder) build(source builder.Source, dockerfile *parser.Result) (*builder.Result, error) {
|
|
defer b.imageSources.Unmount()
|
|
defer b.imageSources.Unmount()
|
|
|
|
|
|
- addNodesForLabelOption(dockerfile.AST, b.options.Labels)
|
|
|
|
-
|
|
|
|
stages, metaArgs, err := instructions.Parse(dockerfile.AST)
|
|
stages, metaArgs, err := instructions.Parse(dockerfile.AST)
|
|
if err != nil {
|
|
if err != nil {
|
|
if instructions.IsUnknownInstruction(err) {
|
|
if instructions.IsUnknownInstruction(err) {
|
|
@@ -231,6 +245,9 @@ func (b *Builder) build(source builder.Source, dockerfile *parser.Result) (*buil
|
|
stages = stages[:targetIx+1]
|
|
stages = stages[:targetIx+1]
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // Add 'LABEL' command specified by '--label' option to the last stage
|
|
|
|
+ buildLabelOptions(b.options.Labels, stages)
|
|
|
|
+
|
|
dockerfile.PrintWarnings(b.Stderr)
|
|
dockerfile.PrintWarnings(b.Stderr)
|
|
dispatchState, err := b.dispatchDockerfileWithCancellation(stages, metaArgs, dockerfile.EscapeToken, source)
|
|
dispatchState, err := b.dispatchDockerfileWithCancellation(stages, metaArgs, dockerfile.EscapeToken, source)
|
|
if err != nil {
|
|
if err != nil {
|