summaryrefslogtreecommitdiff
path: root/cmd/podman/import.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman/import.go')
-rw-r--r--cmd/podman/import.go72
1 files changed, 4 insertions, 68 deletions
diff --git a/cmd/podman/import.go b/cmd/podman/import.go
index f57d70af0..5a4fa45d9 100644
--- a/cmd/podman/import.go
+++ b/cmd/podman/import.go
@@ -7,11 +7,12 @@ import (
"net/http"
"net/url"
"os"
- "strings"
"github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
+ "github.com/projectatomic/libpod/cmd/podman/libpodruntime"
"github.com/projectatomic/libpod/libpod/image"
+ "github.com/projectatomic/libpod/pkg/util"
"github.com/urfave/cli"
)
@@ -49,7 +50,7 @@ func importCmd(c *cli.Context) error {
return err
}
- runtime, err := getRuntime(c)
+ runtime, err := libpodruntime.GetRuntime(c)
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}
@@ -76,7 +77,7 @@ func importCmd(c *cli.Context) error {
changes := v1.ImageConfig{}
if c.IsSet("change") {
- changes, err = getImageConfig(c.StringSlice("change"))
+ changes, err = util.GetImageConfig(c.StringSlice("change"))
if err != nil {
return errors.Wrapf(err, "error adding config changes to image %q", source)
}
@@ -138,68 +139,3 @@ func downloadFromURL(source string) (string, error) {
return outFile.Name(), nil
}
-
-// 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
-}