diff options
author | baude <bbaude@redhat.com> | 2018-04-25 13:26:52 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-04-27 20:51:07 +0000 |
commit | a824186ac9803ef5f7548df790988a4ebd2d9c07 (patch) | |
tree | 63c64e9be4d9c44bd160dd974b740231497eabcd /vendor/github.com/openshift/imagebuilder/internals.go | |
parent | 4e468ce83d69e9748e80eb98a6f5bd3c5114cc7d (diff) | |
download | podman-a824186ac9803ef5f7548df790988a4ebd2d9c07.tar.gz podman-a824186ac9803ef5f7548df790988a4ebd2d9c07.tar.bz2 podman-a824186ac9803ef5f7548df790988a4ebd2d9c07.zip |
Use buildah commit and bud in podman
Vendor in buildah and use as much of commit and bug as possible for podman
build and commit.
Resolves #586
Signed-off-by: baude <bbaude@redhat.com>
Closes: #681
Approved by: mheon
Diffstat (limited to 'vendor/github.com/openshift/imagebuilder/internals.go')
-rw-r--r-- | vendor/github.com/openshift/imagebuilder/internals.go | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/vendor/github.com/openshift/imagebuilder/internals.go b/vendor/github.com/openshift/imagebuilder/internals.go new file mode 100644 index 000000000..9a8005bfc --- /dev/null +++ b/vendor/github.com/openshift/imagebuilder/internals.go @@ -0,0 +1,83 @@ +package imagebuilder + +import ( + "flag" + "fmt" + "os" + "path/filepath" + "runtime" + "strings" + "time" +) + +// hasEnvName returns true if the provided environment contains the named ENV var. +func hasEnvName(env []string, name string) bool { + for _, e := range env { + if strings.HasPrefix(e, name+"=") { + return true + } + } + return false +} + +// platformSupports is a short-term function to give users a quality error +// message if a Dockerfile uses a command not supported on the platform. +func platformSupports(command string) error { + if runtime.GOOS != "windows" { + return nil + } + switch command { + case "expose", "user", "stopsignal", "arg": + return fmt.Errorf("The daemon on this platform does not support the command '%s'", command) + } + return nil +} + +func handleJSONArgs(args []string, attributes map[string]bool) []string { + if len(args) == 0 { + return []string{} + } + + if attributes != nil && attributes["json"] { + return args + } + + // literal string command, not an exec array + return []string{strings.Join(args, " ")} +} + +// makeAbsolute ensures that the provided path is absolute. +func makeAbsolute(dest, workingDir string) string { + // Twiddle the destination when its a relative path - meaning, make it + // relative to the WORKINGDIR + if !filepath.IsAbs(dest) { + hasSlash := strings.HasSuffix(dest, string(os.PathSeparator)) || strings.HasSuffix(dest, string(os.PathSeparator)+".") + dest = filepath.Join(string(os.PathSeparator), filepath.FromSlash(workingDir), dest) + + // Make sure we preserve any trailing slash + if hasSlash { + dest += string(os.PathSeparator) + } + } + return dest +} + +// parseOptInterval(flag) is the duration of flag.Value, or 0 if +// empty. An error is reported if the value is given and is not positive. +func parseOptInterval(f *flag.Flag) (time.Duration, error) { + if f == nil { + return 0, fmt.Errorf("No flag defined") + } + s := f.Value.String() + if s == "" { + return 0, nil + } + d, err := time.ParseDuration(s) + if err != nil { + return 0, err + } + if d <= 0 { + return 0, fmt.Errorf("Interval %#v must be positive", f.Name) + } + return d, nil +} |