[NO TESTS NEEDED] Vendor in containers/buildah v1.20.0

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh
2021-03-26 11:23:46 -04:00
parent fa6ba9b00f
commit fc197fb4f5
158 changed files with 3931 additions and 1954 deletions

View File

@ -30,6 +30,7 @@ type Copy struct {
// If set, the owner:group for the destination. This value is passed
// to the executor for handling.
Chown string
Chmod string
}
// Run defines a run operation required in the container.
@ -60,7 +61,7 @@ func (logExecutor) EnsureContainerPath(path string) error {
func (logExecutor) Copy(excludes []string, copies ...Copy) error {
for _, c := range copies {
log.Printf("COPY %v -> %s (from:%s download:%t), chown: %s", c.Src, c.Dest, c.From, c.Download, c.Chown)
log.Printf("COPY %v -> %s (from:%s download:%t), chown: %s, chmod %s", c.Src, c.Dest, c.From, c.Download, c.Chown, c.Chmod)
}
return nil
}
@ -562,24 +563,41 @@ var builtinAllowedBuildArgs = map[string]bool{
"no_proxy": true,
}
// ParseDockerIgnore returns a list of the excludes in the .dockerignore file.
// ParseIgnore returns a list of the excludes in the specified path
// path should be a file with the .dockerignore format
// extracted from fsouza/go-dockerclient and modified to drop comments and
// empty lines.
func ParseDockerignore(root string) ([]string, error) {
func ParseIgnore(path string) ([]string, error) {
var excludes []string
ignore, err := ioutil.ReadFile(filepath.Join(root, ".dockerignore"))
if err != nil && !os.IsNotExist(err) {
return excludes, fmt.Errorf("error reading .dockerignore: '%s'", err)
ignores, err := ioutil.ReadFile(path)
if err != nil {
return excludes, err
}
for _, e := range strings.Split(string(ignore), "\n") {
if len(e) == 0 || e[0] == '#' {
for _, ignore := range strings.Split(string(ignores), "\n") {
if len(ignore) == 0 || ignore[0] == '#' {
continue
}
excludes = append(excludes, e)
ignore = strings.Trim(ignore, "/")
if len(ignore) > 0 {
excludes = append(excludes, ignore)
}
}
return excludes, nil
}
// ParseDockerIgnore returns a list of the excludes in the .containerignore or .dockerignore file.
func ParseDockerignore(root string) ([]string, error) {
excludes, err := ParseIgnore(filepath.Join(root, ".containerignore"))
if err != nil && os.IsNotExist(err) {
excludes, err = ParseIgnore(filepath.Join(root, ".dockerignore"))
}
if err != nil && os.IsNotExist(err) {
return excludes, nil
}
return excludes, err
}
// ExportEnv creates an export statement for a shell that contains all of the
// provided environment.
func ExportEnv(env []string) string {

View File

@ -139,6 +139,7 @@ func add(b *Builder, args []string, attributes map[string]bool, flagArgs []strin
return errAtLeastOneArgument("ADD")
}
var chown string
var chmod string
last := len(args) - 1
dest := makeAbsolute(args[last], b.RunConfig.WorkingDir)
userArgs := mergeEnv(envMapAsSlice(b.Args), b.Env)
@ -150,11 +151,17 @@ func add(b *Builder, args []string, attributes map[string]bool, flagArgs []strin
switch {
case strings.HasPrefix(arg, "--chown="):
chown = strings.TrimPrefix(arg, "--chown=")
case strings.HasPrefix(arg, "--chmod="):
chmod = strings.TrimPrefix(arg, "--chmod=")
err = checkChmodConversion(chmod)
if err != nil {
return err
}
default:
return fmt.Errorf("ADD only supports the --chown=<uid:gid> flag")
return fmt.Errorf("ADD only supports the --chmod=<permissions> and the --chown=<uid:gid> flag")
}
}
b.PendingCopies = append(b.PendingCopies, Copy{Src: args[0:last], Dest: dest, Download: true, Chown: chown})
b.PendingCopies = append(b.PendingCopies, Copy{Src: args[0:last], Dest: dest, Download: true, Chown: chown, Chmod: chmod})
return nil
}
@ -169,6 +176,7 @@ func dispatchCopy(b *Builder, args []string, attributes map[string]bool, flagArg
last := len(args) - 1
dest := makeAbsolute(args[last], b.RunConfig.WorkingDir)
var chown string
var chmod string
var from string
userArgs := mergeEnv(envMapAsSlice(b.Args), b.Env)
for _, a := range flagArgs {
@ -179,13 +187,19 @@ func dispatchCopy(b *Builder, args []string, attributes map[string]bool, flagArg
switch {
case strings.HasPrefix(arg, "--chown="):
chown = strings.TrimPrefix(arg, "--chown=")
case strings.HasPrefix(arg, "--chmod="):
chmod = strings.TrimPrefix(arg, "--chmod=")
err = checkChmodConversion(chmod)
if err != nil {
return err
}
case strings.HasPrefix(arg, "--from="):
from = strings.TrimPrefix(arg, "--from=")
default:
return fmt.Errorf("COPY only supports the --chown=<uid:gid> and the --from=<image|stage> flags")
return fmt.Errorf("COPY only supports the --chmod=<permissions> --chown=<uid:gid> and the --from=<image|stage> flags")
}
}
b.PendingCopies = append(b.PendingCopies, Copy{From: from, Src: args[0:last], Dest: dest, Download: false, Chown: chown})
b.PendingCopies = append(b.PendingCopies, Copy{From: from, Src: args[0:last], Dest: dest, Download: false, Chown: chown, Chmod: chmod})
return nil
}
@ -624,6 +638,14 @@ func shell(b *Builder, args []string, attributes map[string]bool, flagArgs []str
return nil
}
func checkChmodConversion(chmod string) error {
_, err := strconv.ParseUint(chmod, 8, 32)
if err != nil {
return fmt.Errorf("Error parsing chmod %s", chmod)
}
return nil
}
func errAtLeastOneArgument(command string) error {
return fmt.Errorf("%s requires at least one argument", command)
}

View File

@ -12,7 +12,7 @@
#
%global golang_version 1.8.1
%{!?version: %global version 1.1.8}
%{!?version: %global version 1.2.0}
%{!?release: %global release 1}
%global package_name imagebuilder
%global product_name Container Image Builder