1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
package main
import (
"fmt"
"github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/libpod/adapter"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
var (
importCommand cliconfig.ImportValues
importDescription = `Create a container image from the contents of the specified tarball (.tar, .tar.gz, .tgz, .bzip, .tar.xz, .txz).
Note remote tar balls can be specified, via web address.
Optionally tag the image. You can specify the instructions using the --change option.
`
_importCommand = &cobra.Command{
Use: "import",
Short: "Import a tarball to create a filesystem image",
Long: importDescription,
RunE: func(cmd *cobra.Command, args []string) error {
importCommand.InputArgs = args
importCommand.GlobalFlags = MainGlobalOpts
return importCmd(&importCommand)
},
Example: "TARBALL [REFERENCE]",
}
)
func init() {
importCommand.Command = _importCommand
importCommand.SetUsageTemplate(UsageTemplate())
flags := importCommand.Flags()
flags.StringSliceVarP(&importCommand.Change, "change", "c", []string{}, "Apply the following possible instructions to the created image (default []): CMD | ENTRYPOINT | ENV | EXPOSE | LABEL | STOPSIGNAL | USER | VOLUME | WORKDIR")
flags.StringVarP(&importCommand.Message, "message", "m", "", "Set commit message for imported image")
flags.BoolVarP(&importCommand.Quiet, "quiet", "q", false, "Suppress output")
}
func importCmd(c *cliconfig.ImportValues) error {
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}
defer runtime.Shutdown(false)
var (
source string
reference string
)
args := c.InputArgs
switch len(args) {
case 0:
return errors.Errorf("need to give the path to the tarball, or must specify a tarball of '-' for stdin")
case 1:
source = args[0]
case 2:
source = args[0]
reference = args[1]
default:
return errors.Errorf("too many arguments. Usage TARBALL [REFERENCE]")
}
if err := validateFileName(source); err != nil {
return err
}
quiet := c.Quiet
if runtime.Remote {
quiet = false
}
iid, err := runtime.Import(getContext(), source, reference, c.StringSlice("change"), c.String("message"), quiet)
if err == nil {
fmt.Println(iid)
}
return err
}
|