aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/openshift/imagebuilder/builder.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/openshift/imagebuilder/builder.go')
-rw-r--r--vendor/github.com/openshift/imagebuilder/builder.go36
1 files changed, 29 insertions, 7 deletions
diff --git a/vendor/github.com/openshift/imagebuilder/builder.go b/vendor/github.com/openshift/imagebuilder/builder.go
index 71dc41ea5..db0c2f11b 100644
--- a/vendor/github.com/openshift/imagebuilder/builder.go
+++ b/vendor/github.com/openshift/imagebuilder/builder.go
@@ -215,6 +215,17 @@ type Stage struct {
func NewStages(node *parser.Node, b *Builder) (Stages, error) {
var stages Stages
+ var allDeclaredArgs []string
+ for _, root := range SplitBy(node, command.Arg) {
+ argNode := root.Children[0]
+ if argNode.Value == command.Arg {
+ // extract declared variable
+ s := strings.SplitN(argNode.Original, " ", 2)
+ if len(s) == 2 && (strings.ToLower(s[0]) == command.Arg) {
+ allDeclaredArgs = append(allDeclaredArgs, s[1])
+ }
+ }
+ }
if err := b.extractHeadingArgsFromNode(node); err != nil {
return stages, err
}
@@ -226,7 +237,7 @@ func NewStages(node *parser.Node, b *Builder) (Stages, error) {
stages = append(stages, Stage{
Position: i,
Name: name,
- Builder: b.builderForStage(),
+ Builder: b.builderForStage(allDeclaredArgs),
Node: root,
})
}
@@ -290,8 +301,8 @@ func extractNameFromNode(node *parser.Node) (string, bool) {
return n.Next.Value, true
}
-func (b *Builder) builderForStage() *Builder {
- stageBuilder := NewBuilder(b.UserArgs)
+func (b *Builder) builderForStage(globalArgsList []string) *Builder {
+ stageBuilder := newBuilderWithGlobalAllowedArgs(b.UserArgs, globalArgsList)
for k, v := range b.HeadingArgs {
stageBuilder.HeadingArgs[k] = v
}
@@ -307,6 +318,12 @@ type Builder struct {
UserArgs map[string]string
CmdSet bool
Author string
+ // Certain instructions like `FROM` will need to use
+ // `ARG` decalred before or not in this stage hence
+ // while processing instruction like `FROM ${SOME_ARG}`
+ // we will make sure to verify if they are declared any
+ // where in containerfile or not.
+ GlobalAllowedArgs []string
AllowedArgs map[string]bool
Volumes VolumeSet
@@ -323,6 +340,10 @@ type Builder struct {
}
func NewBuilder(args map[string]string) *Builder {
+ return newBuilderWithGlobalAllowedArgs(args, []string{})
+}
+
+func newBuilderWithGlobalAllowedArgs(args map[string]string, globalallowedargs []string) *Builder {
allowed := make(map[string]bool)
for k, v := range builtinAllowedBuildArgs {
allowed[k] = v
@@ -334,10 +355,11 @@ func NewBuilder(args map[string]string) *Builder {
initialArgs[k] = v
}
return &Builder{
- Args: initialArgs,
- UserArgs: userArgs,
- HeadingArgs: make(map[string]string),
- AllowedArgs: allowed,
+ Args: initialArgs,
+ UserArgs: userArgs,
+ HeadingArgs: make(map[string]string),
+ AllowedArgs: allowed,
+ GlobalAllowedArgs: globalallowedargs,
}
}