mirror of
https://github.com/containers/podman.git
synced 2026-10-31 06:11:20 -04:00
Replace direct calls to context.Background() and registry.Context() in the CLI with use of a context.Context carried down from the main cobra Command, which should be the only place that context.Background() is used. Drop registry.Context() now that it's no longer used. The shutting down of the image and container engine objects before exiting now uses a one-off context with a timeout instead of context.Background(). Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
130 lines
4.3 KiB
Go
130 lines
4.3 KiB
Go
//go:build (linux || freebsd) && !remote
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
"go.podman.io/common/pkg/completion"
|
|
"go.podman.io/podman/v6/cmd/podman/validate"
|
|
"go.podman.io/podman/v6/internal/domain/entities"
|
|
)
|
|
|
|
var (
|
|
createStorageLayerDescription = `Create an unmanaged layer in local storage.`
|
|
createStorageLayerCmd = &cobra.Command{
|
|
Use: "create-storage-layer [options]",
|
|
Args: validate.NoArgs,
|
|
Short: "Create an unmanaged layer",
|
|
Long: createStorageLayerDescription,
|
|
RunE: createStorageLayer,
|
|
ValidArgsFunction: completion.AutocompleteNone,
|
|
Example: `podman-testing create-storage-layer`,
|
|
}
|
|
|
|
createStorageLayerOpts entities.CreateStorageLayerOptions
|
|
|
|
createLayerDescription = `Create an unused layer in local storage.`
|
|
createLayerCmd = &cobra.Command{
|
|
Use: "create-layer [options]",
|
|
Args: validate.NoArgs,
|
|
Short: "Create an unused layer",
|
|
Long: createLayerDescription,
|
|
RunE: createLayer,
|
|
ValidArgsFunction: completion.AutocompleteNone,
|
|
Example: `podman-testing create-layer`,
|
|
}
|
|
|
|
createLayerOpts entities.CreateLayerOptions
|
|
|
|
createImageDescription = `Create an image in local storage.`
|
|
createImageCmd = &cobra.Command{
|
|
Use: "create-image [options]",
|
|
Args: validate.NoArgs,
|
|
Short: "Create an image",
|
|
Long: createImageDescription,
|
|
RunE: createImage,
|
|
ValidArgsFunction: completion.AutocompleteNone,
|
|
Example: `podman-testing create-image`,
|
|
}
|
|
|
|
createImageOpts entities.CreateImageOptions
|
|
|
|
createContainerDescription = `Create a container in local storage.`
|
|
createContainerCmd = &cobra.Command{
|
|
Use: "create-container [options]",
|
|
Args: validate.NoArgs,
|
|
Short: "Create a container",
|
|
Long: createContainerDescription,
|
|
RunE: createContainer,
|
|
ValidArgsFunction: completion.AutocompleteNone,
|
|
Example: `podman-testing create-container`,
|
|
}
|
|
|
|
createContainerOpts entities.CreateContainerOptions
|
|
)
|
|
|
|
func init() {
|
|
mainCmd.AddCommand(createStorageLayerCmd)
|
|
flags := createStorageLayerCmd.Flags()
|
|
flags.StringVarP(&createStorageLayerOpts.ID, "id", "i", "", "ID to assign the new layer (default random)")
|
|
flags.StringVarP(&createStorageLayerOpts.Parent, "parent", "p", "", "ID of parent of new layer (default none)")
|
|
|
|
mainCmd.AddCommand(createLayerCmd)
|
|
flags = createLayerCmd.Flags()
|
|
flags.StringVarP(&createLayerOpts.ID, "id", "i", "", "ID to assign the new layer (default random)")
|
|
flags.StringVarP(&createLayerOpts.Parent, "parent", "p", "", "ID of parent of new layer (default none)")
|
|
|
|
mainCmd.AddCommand(createImageCmd)
|
|
flags = createImageCmd.Flags()
|
|
flags.StringVarP(&createImageOpts.ID, "id", "i", "", "ID to assign the new image (default random)")
|
|
flags.StringVarP(&createImageOpts.Layer, "layer", "l", "", "ID of image's main layer (default none)")
|
|
|
|
mainCmd.AddCommand(createContainerCmd)
|
|
flags = createContainerCmd.Flags()
|
|
flags.StringVarP(&createContainerOpts.ID, "id", "i", "", "ID to assign the new container (default random)")
|
|
flags.StringVarP(&createContainerOpts.Image, "image", "b", "", "ID of containers's base image (default none)")
|
|
flags.StringVarP(&createContainerOpts.Layer, "layer", "l", "", "ID of containers's read-write layer (default none)")
|
|
}
|
|
|
|
func createStorageLayer(cmd *cobra.Command, _ []string) error {
|
|
results, err := testingEngine.CreateStorageLayer(cmd.Context(), createStorageLayerOpts)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Println(results.ID)
|
|
return nil
|
|
}
|
|
|
|
func createLayer(cmd *cobra.Command, _ []string) error {
|
|
results, err := testingEngine.CreateLayer(cmd.Context(), createLayerOpts)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Println(results.ID)
|
|
return nil
|
|
}
|
|
|
|
func createImage(cmd *cobra.Command, _ []string) error {
|
|
results, err := testingEngine.CreateImage(cmd.Context(), createImageOpts)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Println(results.ID)
|
|
return nil
|
|
}
|
|
|
|
func createContainer(cmd *cobra.Command, _ []string) error {
|
|
results, err := testingEngine.CreateContainer(cmd.Context(), createContainerOpts)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Println(results.ID)
|
|
return nil
|
|
}
|