mirror of
https://github.com/containers/podman.git
synced 2025-06-22 09:58:10 +08:00
Merge pull request #1607 from baude/runlabelfixes
fix runlabel functions based on QA feedback
This commit is contained in:
@ -6,9 +6,11 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/containers/image/types"
|
||||||
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
||||||
"github.com/containers/libpod/cmd/podman/shared"
|
"github.com/containers/libpod/cmd/podman/shared"
|
||||||
"github.com/containers/libpod/libpod/image"
|
"github.com/containers/libpod/libpod/image"
|
||||||
|
"github.com/containers/libpod/pkg/util"
|
||||||
"github.com/containers/libpod/utils"
|
"github.com/containers/libpod/utils"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -23,7 +25,7 @@ var (
|
|||||||
},
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "display",
|
Name: "display",
|
||||||
Usage: "preview the command that `podman install` would execute",
|
Usage: "preview the command that the label would run",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "cert-dir",
|
Name: "cert-dir",
|
||||||
@ -74,13 +76,14 @@ var (
|
|||||||
Executes a command as described by a container image label.
|
Executes a command as described by a container image label.
|
||||||
`
|
`
|
||||||
runlabelCommand = cli.Command{
|
runlabelCommand = cli.Command{
|
||||||
Name: "runlabel",
|
Name: "runlabel",
|
||||||
Usage: "Execute the command described by an image label",
|
Usage: "Execute the command described by an image label",
|
||||||
Description: runlabelDescription,
|
Description: runlabelDescription,
|
||||||
Flags: runlabelFlags,
|
Flags: runlabelFlags,
|
||||||
Action: runlabelCmd,
|
Action: runlabelCmd,
|
||||||
ArgsUsage: "",
|
ArgsUsage: "",
|
||||||
OnUsageError: usageErrorHandler,
|
SkipArgReorder: true,
|
||||||
|
OnUsageError: usageErrorHandler,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -110,12 +113,8 @@ func runlabelCmd(c *cli.Context) error {
|
|||||||
defer runtime.Shutdown(false)
|
defer runtime.Shutdown(false)
|
||||||
|
|
||||||
args := c.Args()
|
args := c.Args()
|
||||||
if len(args) == 0 {
|
|
||||||
logrus.Errorf("an image name must be specified")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if len(args) < 2 {
|
if len(args) < 2 {
|
||||||
logrus.Errorf("the runlabel command requires at least 2 arguments")
|
logrus.Errorf("the runlabel command requires at least 2 arguments: LABEL IMAGE")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := validateFlags(c, runlabelFlags); err != nil {
|
if err := validateFlags(c, runlabelFlags); err != nil {
|
||||||
@ -130,18 +129,17 @@ func runlabelCmd(c *cli.Context) error {
|
|||||||
|
|
||||||
runlabelImage := args[1]
|
runlabelImage := args[1]
|
||||||
|
|
||||||
if c.IsSet("opts1") {
|
if c.IsSet("opt1") {
|
||||||
opts["opts1"] = c.String("opts1")
|
opts["opt1"] = c.String("opt1")
|
||||||
}
|
}
|
||||||
if c.IsSet("opts2") {
|
if c.IsSet("opt2") {
|
||||||
opts["opts2"] = c.String("opts2")
|
opts["opt2"] = c.String("opt2")
|
||||||
}
|
}
|
||||||
if c.IsSet("opts3") {
|
if c.IsSet("opt3") {
|
||||||
opts["opts3"] = c.String("opts3")
|
opts["opt3"] = c.String("opt3")
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := getContext()
|
ctx := getContext()
|
||||||
rtc := runtime.GetConfig()
|
|
||||||
|
|
||||||
stdErr = os.Stderr
|
stdErr = os.Stderr
|
||||||
stdOut = os.Stdout
|
stdOut = os.Stdout
|
||||||
@ -154,7 +152,21 @@ func runlabelCmd(c *cli.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if pull {
|
if pull {
|
||||||
newImage, err = runtime.ImageRuntime().New(ctx, runlabelImage, rtc.SignaturePolicyPath, "", stdOut, nil, image.SigningOptions{}, false, false)
|
var registryCreds *types.DockerAuthConfig
|
||||||
|
if c.IsSet("creds") {
|
||||||
|
creds, err := util.ParseRegistryCreds(c.String("creds"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
registryCreds = creds
|
||||||
|
}
|
||||||
|
dockerRegistryOptions := image.DockerRegistryOptions{
|
||||||
|
DockerRegistryCreds: registryCreds,
|
||||||
|
DockerCertPath: c.String("cert-dir"),
|
||||||
|
DockerInsecureSkipTLSVerify: !c.BoolT("tls-verify"),
|
||||||
|
}
|
||||||
|
|
||||||
|
newImage, err = runtime.ImageRuntime().New(ctx, runlabelImage, c.String("signature-policy"), c.String("authfile"), stdOut, &dockerRegistryOptions, image.SigningOptions{}, false, false)
|
||||||
} else {
|
} else {
|
||||||
newImage, err = runtime.ImageRuntime().NewFromLocal(runlabelImage)
|
newImage, err = runtime.ImageRuntime().NewFromLocal(runlabelImage)
|
||||||
}
|
}
|
||||||
@ -187,6 +199,23 @@ func runlabelCmd(c *cli.Context) error {
|
|||||||
env := shared.GenerateRunEnvironment(c.String("name"), imageName, opts)
|
env := shared.GenerateRunEnvironment(c.String("name"), imageName, opts)
|
||||||
env = append(env, "PODMAN_RUNLABEL_NESTED=1")
|
env = append(env, "PODMAN_RUNLABEL_NESTED=1")
|
||||||
|
|
||||||
|
envmap := envSliceToMap(env)
|
||||||
|
|
||||||
|
envmapper := func(k string) string {
|
||||||
|
switch k {
|
||||||
|
case "OPT1":
|
||||||
|
return envmap["OPT1"]
|
||||||
|
case "OPT2":
|
||||||
|
return envmap["OPT2"]
|
||||||
|
case "OPT3":
|
||||||
|
return envmap["OPT3"]
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
newS := os.Expand(strings.Join(cmd, " "), envmapper)
|
||||||
|
cmd = strings.Split(newS, " ")
|
||||||
|
|
||||||
if !c.Bool("quiet") {
|
if !c.Bool("quiet") {
|
||||||
fmt.Printf("Command: %s\n", strings.Join(cmd, " "))
|
fmt.Printf("Command: %s\n", strings.Join(cmd, " "))
|
||||||
if c.Bool("display") {
|
if c.Bool("display") {
|
||||||
@ -195,3 +224,12 @@ func runlabelCmd(c *cli.Context) error {
|
|||||||
}
|
}
|
||||||
return utils.ExecCmdWithStdStreams(stdIn, stdOut, stdErr, env, cmd[0], cmd[1:]...)
|
return utils.ExecCmdWithStdStreams(stdIn, stdOut, stdErr, env, cmd[0], cmd[1:]...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func envSliceToMap(env []string) map[string]string {
|
||||||
|
m := make(map[string]string)
|
||||||
|
for _, i := range env {
|
||||||
|
split := strings.Split(i, "=")
|
||||||
|
m[split[0]] = strings.Join(split[1:], " ")
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
@ -24,10 +24,14 @@ func GenerateCommand(command, imageName, name string) []string {
|
|||||||
newArg = imageName
|
newArg = imageName
|
||||||
case "IMAGE=IMAGE":
|
case "IMAGE=IMAGE":
|
||||||
newArg = fmt.Sprintf("IMAGE=%s", imageName)
|
newArg = fmt.Sprintf("IMAGE=%s", imageName)
|
||||||
|
case "IMAGE=$IMAGE":
|
||||||
|
newArg = fmt.Sprintf("IMAGE=%s", imageName)
|
||||||
case "NAME":
|
case "NAME":
|
||||||
newArg = name
|
newArg = name
|
||||||
case "NAME=NAME":
|
case "NAME=NAME":
|
||||||
newArg = fmt.Sprintf("NAME=%s", name)
|
newArg = fmt.Sprintf("NAME=%s", name)
|
||||||
|
case "NAME=$NAME":
|
||||||
|
newArg = fmt.Sprintf("NAME=%s", name)
|
||||||
default:
|
default:
|
||||||
newArg = arg
|
newArg = arg
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,8 @@ If the container image has a LABEL INSTALL instruction like the following:
|
|||||||
|
|
||||||
Note: Podman will always ensure that `podman` is the first argument of the command being executed.
|
Note: Podman will always ensure that `podman` is the first argument of the command being executed.
|
||||||
|
|
||||||
**NAME**
|
**LABEL**
|
||||||
The name specified via the command. NAME will be replaced with IMAGE if it is not specified.
|
The label name specified via the command.
|
||||||
|
|
||||||
**IMAGE**
|
**IMAGE**
|
||||||
Image name specified via the command.
|
Image name specified via the command.
|
||||||
@ -95,6 +95,23 @@ Require HTTPS and verify certificates when contacting registries (default: true)
|
|||||||
then tls verification will be used, If set to false then tls verification will not be used. If not specified
|
then tls verification will be used, If set to false then tls verification will not be used. If not specified
|
||||||
tls verification will be used unless the target registry is listed as an insecure registry in registries.conf
|
tls verification will be used unless the target registry is listed as an insecure registry in registries.conf
|
||||||
|
|
||||||
|
## Examples ##
|
||||||
|
|
||||||
|
Execute the run label of an image called foobar.
|
||||||
|
```
|
||||||
|
$ sudo podman container runlabel run foobar
|
||||||
|
```
|
||||||
|
|
||||||
|
Execute the install label of an image called foobar with additional arguments.
|
||||||
|
```
|
||||||
|
$ sudo podman container runlabel install foobar apples oranges
|
||||||
|
```
|
||||||
|
|
||||||
|
Display the command that would be executed by runlabel.
|
||||||
|
```
|
||||||
|
$ sudo podman container runlabel --display run foobar
|
||||||
|
```
|
||||||
|
|
||||||
## SEE ALSO
|
## SEE ALSO
|
||||||
podman(1)
|
podman(1)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user