summaryrefslogtreecommitdiff
path: root/pkg/util
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2018-04-23 13:32:41 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2018-04-26 19:14:44 +0000
commit39a7a773a653176e294382bc6301275fd57aff6b (patch)
tree334db314ef5681bd6979e2be91dd39640f8e00ff /pkg/util
parent0ccfd7dc20c11bc2f9d646c98cc67fb399cd9013 (diff)
downloadpodman-39a7a773a653176e294382bc6301275fd57aff6b.tar.gz
podman-39a7a773a653176e294382bc6301275fd57aff6b.tar.bz2
podman-39a7a773a653176e294382bc6301275fd57aff6b.zip
varlink images
implement varlink image functions for working with libpod with the exception of a couple due to incompletions on the libpod side of things (build). also, created a first pass at a libpodpy package which will stand as a client to working with libpod's varlink methods using python. Signed-off-by: baude <bbaude@redhat.com> Closes: #669 Approved by: baude
Diffstat (limited to 'pkg/util')
-rw-r--r--pkg/util/utils.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/pkg/util/utils.go b/pkg/util/utils.go
index edcf63f80..1bbfe30d3 100644
--- a/pkg/util/utils.go
+++ b/pkg/util/utils.go
@@ -5,6 +5,7 @@ import (
"strings"
"github.com/containers/image/types"
+ "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"golang.org/x/crypto/ssh/terminal"
)
@@ -54,3 +55,68 @@ func StringInSlice(s string, sl []string) bool {
}
return false
}
+
+// GetImageConfig converts the --change flag values in the format "CMD=/bin/bash USER=example"
+// to a type v1.ImageConfig
+func GetImageConfig(changes []string) (v1.ImageConfig, error) {
+ // USER=value | EXPOSE=value | ENV=value | ENTRYPOINT=value |
+ // CMD=value | VOLUME=value | WORKDIR=value | LABEL=key=value | STOPSIGNAL=value
+
+ var (
+ user string
+ env []string
+ entrypoint []string
+ cmd []string
+ workingDir string
+ stopSignal string
+ )
+
+ exposedPorts := make(map[string]struct{})
+ volumes := make(map[string]struct{})
+ labels := make(map[string]string)
+
+ for _, ch := range changes {
+ pair := strings.Split(ch, "=")
+ if len(pair) == 1 {
+ return v1.ImageConfig{}, errors.Errorf("no value given for instruction %q", ch)
+ }
+ switch pair[0] {
+ case "USER":
+ user = pair[1]
+ case "EXPOSE":
+ var st struct{}
+ exposedPorts[pair[1]] = st
+ case "ENV":
+ env = append(env, pair[1])
+ case "ENTRYPOINT":
+ entrypoint = append(entrypoint, pair[1])
+ case "CMD":
+ cmd = append(cmd, pair[1])
+ case "VOLUME":
+ var st struct{}
+ volumes[pair[1]] = st
+ case "WORKDIR":
+ workingDir = pair[1]
+ case "LABEL":
+ if len(pair) == 3 {
+ labels[pair[1]] = pair[2]
+ } else {
+ labels[pair[1]] = ""
+ }
+ case "STOPSIGNAL":
+ stopSignal = pair[1]
+ }
+ }
+
+ return v1.ImageConfig{
+ User: user,
+ ExposedPorts: exposedPorts,
+ Env: env,
+ Entrypoint: entrypoint,
+ Cmd: cmd,
+ Volumes: volumes,
+ WorkingDir: workingDir,
+ Labels: labels,
+ StopSignal: stopSignal,
+ }, nil
+}