summaryrefslogtreecommitdiff
path: root/libpod/buildah/util.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2018-04-03 12:34:19 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2018-04-10 13:31:59 +0000
commit1700f2b2381d9665810ed4764d0fe357150c5978 (patch)
treea7338bdc31da8ef48d337555911932b097c06f84 /libpod/buildah/util.go
parent998fd2ece0480e581e013124d0969a1af6305110 (diff)
downloadpodman-1700f2b2381d9665810ed4764d0fe357150c5978.tar.gz
podman-1700f2b2381d9665810ed4764d0fe357150c5978.tar.bz2
podman-1700f2b2381d9665810ed4764d0fe357150c5978.zip
Use buildah commit for podman commit
Resolves: #586 and #520 Signed-off-by: baude <bbaude@redhat.com> Closes: #592 Approved by: mheon
Diffstat (limited to 'libpod/buildah/util.go')
-rw-r--r--libpod/buildah/util.go67
1 files changed, 67 insertions, 0 deletions
diff --git a/libpod/buildah/util.go b/libpod/buildah/util.go
new file mode 100644
index 000000000..96f9ebf86
--- /dev/null
+++ b/libpod/buildah/util.go
@@ -0,0 +1,67 @@
+package buildah
+
+import (
+ "github.com/containers/image/docker/reference"
+ "github.com/containers/storage"
+ "github.com/containers/storage/pkg/reexec"
+ "github.com/pkg/errors"
+)
+
+// InitReexec is a wrapper for reexec.Init(). It should be called at
+// the start of main(), and if it returns true, main() should return
+// immediately.
+func InitReexec() bool {
+ return reexec.Init()
+}
+
+func copyStringStringMap(m map[string]string) map[string]string {
+ n := map[string]string{}
+ for k, v := range m {
+ n[k] = v
+ }
+ return n
+}
+
+func copyStringSlice(s []string) []string {
+ t := make([]string, len(s))
+ copy(t, s)
+ return t
+}
+
+// AddImageNames adds the specified names to the specified image.
+func AddImageNames(store storage.Store, image *storage.Image, addNames []string) error {
+ names, err := ExpandNames(addNames)
+ if err != nil {
+ return err
+ }
+ err = store.SetNames(image.ID, append(image.Names, names...))
+ if err != nil {
+ return errors.Wrapf(err, "error adding names (%v) to image %q", names, image.ID)
+ }
+ return nil
+}
+
+// ExpandNames takes unqualified names, parses them as image names, and returns
+// the fully expanded result, including a tag. Names which don't include a registry
+// name will be marked for the most-preferred registry (i.e., the first one in our
+// configuration).
+func ExpandNames(names []string) ([]string, error) {
+ expanded := make([]string, 0, len(names))
+ for _, n := range names {
+ name, err := reference.ParseNormalizedNamed(n)
+ if err != nil {
+ return nil, errors.Wrapf(err, "error parsing name %q", n)
+ }
+ name = reference.TagNameOnly(name)
+ tag := ""
+ digest := ""
+ if tagged, ok := name.(reference.NamedTagged); ok {
+ tag = ":" + tagged.Tag()
+ }
+ if digested, ok := name.(reference.Digested); ok {
+ digest = "@" + digested.Digest().String()
+ }
+ expanded = append(expanded, name.Name()+tag+digest)
+ }
+ return expanded, nil
+}