Bump to Buildah v1.37.0

Bump Buidah to v1.37.0

Signed-off-by: tomsweeneyredhat <tsweeney@redhat.com>
This commit is contained in:
tomsweeneyredhat
2024-07-29 16:12:07 -04:00
parent d38268062a
commit 286fbf98d1
33 changed files with 798 additions and 280 deletions

View File

@ -288,29 +288,38 @@ 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])
}
}
}
var headingArgs []string
if err := b.extractHeadingArgsFromNode(node); err != nil {
return stages, err
}
for k := range b.HeadingArgs {
headingArgs = append(headingArgs, k)
}
for i, root := range SplitBy(node, command.From) {
name, _ := extractNameFromNode(root.Children[0])
if len(name) == 0 {
name = strconv.Itoa(i)
}
filteredUserArgs := make(map[string]string)
for k, v := range b.UserArgs {
for _, a := range b.GlobalAllowedArgs {
if a == k {
filteredUserArgs[k] = v
}
}
}
userArgs := envMapAsSlice(filteredUserArgs)
userArgs = mergeEnv(envMapAsSlice(b.BuiltinArgDefaults), userArgs)
userArgs = mergeEnv(envMapAsSlice(builtinArgDefaults), userArgs)
userArgs = mergeEnv(envMapAsSlice(b.HeadingArgs), userArgs)
processedName, err := ProcessWord(name, userArgs)
if err != nil {
return nil, err
}
stages = append(stages, Stage{
Position: i,
Name: name,
Builder: b.builderForStage(allDeclaredArgs),
Name: processedName,
Builder: b.builderForStage(headingArgs),
Node: root,
})
}
@ -375,32 +384,41 @@ func extractNameFromNode(node *parser.Node) (string, bool) {
}
func (b *Builder) builderForStage(globalArgsList []string) *Builder {
stageBuilder := newBuilderWithGlobalAllowedArgs(b.UserArgs, globalArgsList)
for k, v := range b.HeadingArgs {
stageBuilder.HeadingArgs[k] = v
}
stageBuilder := newBuilderWithGlobalAllowedArgs(b.UserArgs, b.HeadingArgs, b.BuiltinArgDefaults, globalArgsList)
return stageBuilder
}
type Builder struct {
RunConfig docker.Config
Env []string
Args map[string]string
HeadingArgs map[string]string
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
Env []string
// Args contains values originally given to NewBuilder() or set due to
// ARG instructions in a stage, either with a default value provided,
// or with a default inherited from an ARG instruction in the header
Args map[string]string
// HeadingArgs contains the values for ARG instructions in the
// Dockerfile which occurred before the first FROM instruction, either
// with a default value provided as part of the ARG instruction, or
// expecting a value to be supplied in UserArgs via NewBuilder().
HeadingArgs map[string]string
// UserArgs includes a copy of the values that were passed to
// NewBuilder(), unmodified.
UserArgs map[string]string
CmdSet bool
Author string
// GlobalAllowedArgs are args which should be resolvable in a FROM
// instruction, either built-in and always available, or introduced by
// an ARG instruction in the header.
GlobalAllowedArgs []string
// AllowedArgs are args which should be resolvable in this stage,
// having been introduced by a previous ARG instruction in this stage.
AllowedArgs map[string]bool
Volumes VolumeSet
Excludes []string
Volumes VolumeSet
Excludes []string
PendingVolumes VolumeSet
PendingRuns []Run
@ -410,13 +428,18 @@ type Builder struct {
// Raw platform string specified with `FROM --platform` of the stage
// It's up to the implementation or client to parse and use this field
Platform string
// Overrides for TARGET... and BUILD... values. TARGET... values are
// typically only necessary if the builder's target platform is not the
// same as the build platform.
BuiltinArgDefaults map[string]string
}
func NewBuilder(args map[string]string) *Builder {
return newBuilderWithGlobalAllowedArgs(args, []string{})
return newBuilderWithGlobalAllowedArgs(args, nil, nil, []string{})
}
func newBuilderWithGlobalAllowedArgs(args map[string]string, globalallowedargs []string) *Builder {
func newBuilderWithGlobalAllowedArgs(args, headingArgs, userBuiltinArgDefaults map[string]string, globalAllowedArgs []string) *Builder {
allowed := make(map[string]bool)
for k, v := range builtinAllowedBuildArgs {
allowed[k] = v
@ -427,12 +450,28 @@ func newBuilderWithGlobalAllowedArgs(args map[string]string, globalallowedargs [
userArgs[k] = v
initialArgs[k] = v
}
var copiedGlobalAllowedArgs []string
if len(globalAllowedArgs) > 0 {
copiedGlobalAllowedArgs = append([]string{}, globalAllowedArgs...)
}
copiedHeadingArgs := make(map[string]string)
for k, v := range headingArgs {
copiedHeadingArgs[k] = v
}
copiedBuiltinArgDefaults := make(map[string]string)
for k, v := range builtinArgDefaults {
copiedBuiltinArgDefaults[k] = v
}
for k, v := range userBuiltinArgDefaults {
copiedBuiltinArgDefaults[k] = v
}
return &Builder{
Args: initialArgs,
UserArgs: userArgs,
HeadingArgs: make(map[string]string),
AllowedArgs: allowed,
GlobalAllowedArgs: globalallowedargs,
Args: initialArgs,
UserArgs: userArgs,
HeadingArgs: copiedHeadingArgs,
AllowedArgs: allowed,
GlobalAllowedArgs: copiedGlobalAllowedArgs,
BuiltinArgDefaults: copiedBuiltinArgDefaults,
}
}