mirror of
https://github.com/containers/podman.git
synced 2025-05-22 01:27:07 +08:00
Merge pull request #13588 from flouthoc/import-os-arch
import: allow users to set `--os`, `--arch` and `--variant` of image imports
This commit is contained in:
@ -76,6 +76,18 @@ func importFlags(cmd *cobra.Command) {
|
|||||||
flags.StringVarP(&importOpts.Message, messageFlagName, "m", "", "Set commit message for imported image")
|
flags.StringVarP(&importOpts.Message, messageFlagName, "m", "", "Set commit message for imported image")
|
||||||
_ = cmd.RegisterFlagCompletionFunc(messageFlagName, completion.AutocompleteNone)
|
_ = cmd.RegisterFlagCompletionFunc(messageFlagName, completion.AutocompleteNone)
|
||||||
|
|
||||||
|
osFlagName := "os"
|
||||||
|
flags.StringVar(&importOpts.OS, osFlagName, "", "Set the OS of the imported image")
|
||||||
|
_ = cmd.RegisterFlagCompletionFunc(osFlagName, completion.AutocompleteNone)
|
||||||
|
|
||||||
|
archFlagName := "arch"
|
||||||
|
flags.StringVar(&importOpts.Architecture, archFlagName, "", "Set the architecture of the imported image")
|
||||||
|
_ = cmd.RegisterFlagCompletionFunc(archFlagName, completion.AutocompleteNone)
|
||||||
|
|
||||||
|
variantFlagName := "variant"
|
||||||
|
flags.StringVar(&importOpts.Variant, variantFlagName, "", "Set the variant of the imported image")
|
||||||
|
_ = cmd.RegisterFlagCompletionFunc(variantFlagName, completion.AutocompleteNone)
|
||||||
|
|
||||||
flags.BoolVarP(&importOpts.Quiet, "quiet", "q", false, "Suppress output")
|
flags.BoolVarP(&importOpts.Quiet, "quiet", "q", false, "Suppress output")
|
||||||
if !registry.IsRemote() {
|
if !registry.IsRemote() {
|
||||||
flags.StringVar(&importOpts.SignaturePolicy, "signature-policy", "", "Path to a signature-policy file")
|
flags.StringVar(&importOpts.SignaturePolicy, "signature-policy", "", "Path to a signature-policy file")
|
||||||
|
@ -19,6 +19,10 @@ Note: `:` is a restricted character and cannot be part of the file name.
|
|||||||
|
|
||||||
## OPTIONS
|
## OPTIONS
|
||||||
|
|
||||||
|
#### **--arch**
|
||||||
|
|
||||||
|
Set architecture of the imported image.
|
||||||
|
|
||||||
#### **--change**=*instruction*, **-c**
|
#### **--change**=*instruction*, **-c**
|
||||||
|
|
||||||
Apply the following possible instructions to the created image:
|
Apply the following possible instructions to the created image:
|
||||||
@ -30,10 +34,18 @@ Can be set multiple times
|
|||||||
|
|
||||||
Set commit message for imported image
|
Set commit message for imported image
|
||||||
|
|
||||||
|
#### **--os**
|
||||||
|
|
||||||
|
Set OS of the imported image.
|
||||||
|
|
||||||
#### **--quiet**, **-q**
|
#### **--quiet**, **-q**
|
||||||
|
|
||||||
Shows progress on the import
|
Shows progress on the import
|
||||||
|
|
||||||
|
#### **--variant**
|
||||||
|
|
||||||
|
Set variant of the imported image.
|
||||||
|
|
||||||
**--verbose**
|
**--verbose**
|
||||||
|
|
||||||
Print additional debugging information
|
Print additional debugging information
|
||||||
|
@ -371,6 +371,9 @@ func ImagesImport(w http.ResponseWriter, r *http.Request) {
|
|||||||
Message string `schema:"message"`
|
Message string `schema:"message"`
|
||||||
Reference string `schema:"reference"`
|
Reference string `schema:"reference"`
|
||||||
URL string `schema:"URL"`
|
URL string `schema:"URL"`
|
||||||
|
OS string `schema:"OS"`
|
||||||
|
Architecture string `schema:"Architecture"`
|
||||||
|
Variant string `schema:"Variant"`
|
||||||
}{
|
}{
|
||||||
// Add defaults here once needed.
|
// Add defaults here once needed.
|
||||||
}
|
}
|
||||||
@ -405,6 +408,9 @@ func ImagesImport(w http.ResponseWriter, r *http.Request) {
|
|||||||
Changes: query.Changes,
|
Changes: query.Changes,
|
||||||
Message: query.Message,
|
Message: query.Message,
|
||||||
Reference: query.Reference,
|
Reference: query.Reference,
|
||||||
|
OS: query.OS,
|
||||||
|
Architecture: query.Architecture,
|
||||||
|
Variant: query.Variant,
|
||||||
Source: source,
|
Source: source,
|
||||||
}
|
}
|
||||||
report, err := imageEngine.Import(r.Context(), importOptions)
|
report, err := imageEngine.Import(r.Context(), importOptions)
|
||||||
|
@ -103,6 +103,12 @@ type ImportOptions struct {
|
|||||||
Reference *string
|
Reference *string
|
||||||
// Url to option image to import. Cannot be used with the reader
|
// Url to option image to import. Cannot be used with the reader
|
||||||
URL *string
|
URL *string
|
||||||
|
// OS for the imported image
|
||||||
|
OS *string
|
||||||
|
// Architecture for the imported image
|
||||||
|
Architecture *string
|
||||||
|
// Variant for the imported image
|
||||||
|
Variant *string
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:generate go run ../generator/generator.go PushOptions
|
//go:generate go run ../generator/generator.go PushOptions
|
||||||
|
@ -76,3 +76,48 @@ func (o *ImportOptions) GetURL() string {
|
|||||||
}
|
}
|
||||||
return *o.URL
|
return *o.URL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithOS set field OS to given value
|
||||||
|
func (o *ImportOptions) WithOS(value string) *ImportOptions {
|
||||||
|
o.OS = &value
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetOS returns value of field OS
|
||||||
|
func (o *ImportOptions) GetOS() string {
|
||||||
|
if o.OS == nil {
|
||||||
|
var z string
|
||||||
|
return z
|
||||||
|
}
|
||||||
|
return *o.OS
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithArchitecture set field Architecture to given value
|
||||||
|
func (o *ImportOptions) WithArchitecture(value string) *ImportOptions {
|
||||||
|
o.Architecture = &value
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetArchitecture returns value of field Architecture
|
||||||
|
func (o *ImportOptions) GetArchitecture() string {
|
||||||
|
if o.Architecture == nil {
|
||||||
|
var z string
|
||||||
|
return z
|
||||||
|
}
|
||||||
|
return *o.Architecture
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithVariant set field Variant to given value
|
||||||
|
func (o *ImportOptions) WithVariant(value string) *ImportOptions {
|
||||||
|
o.Variant = &value
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetVariant returns value of field Variant
|
||||||
|
func (o *ImportOptions) GetVariant() string {
|
||||||
|
if o.Variant == nil {
|
||||||
|
var z string
|
||||||
|
return z
|
||||||
|
}
|
||||||
|
return *o.Variant
|
||||||
|
}
|
||||||
|
@ -279,6 +279,7 @@ type ImageLoadReport struct {
|
|||||||
|
|
||||||
type ImageImportOptions struct {
|
type ImageImportOptions struct {
|
||||||
Architecture string
|
Architecture string
|
||||||
|
Variant string
|
||||||
Changes []string
|
Changes []string
|
||||||
Message string
|
Message string
|
||||||
OS string
|
OS string
|
||||||
|
@ -445,7 +445,8 @@ func (ir *ImageEngine) Import(ctx context.Context, options entities.ImageImportO
|
|||||||
importOptions.Tag = options.Reference
|
importOptions.Tag = options.Reference
|
||||||
importOptions.SignaturePolicyPath = options.SignaturePolicy
|
importOptions.SignaturePolicyPath = options.SignaturePolicy
|
||||||
importOptions.OS = options.OS
|
importOptions.OS = options.OS
|
||||||
importOptions.Architecture = options.Architecture
|
importOptions.Arch = options.Architecture
|
||||||
|
importOptions.Variant = options.Variant
|
||||||
|
|
||||||
if !options.Quiet {
|
if !options.Quiet {
|
||||||
importOptions.Writer = os.Stderr
|
importOptions.Writer = os.Stderr
|
||||||
|
@ -230,6 +230,7 @@ func (ir *ImageEngine) Import(ctx context.Context, opts entities.ImageImportOpti
|
|||||||
f *os.File
|
f *os.File
|
||||||
)
|
)
|
||||||
options := new(images.ImportOptions).WithChanges(opts.Changes).WithMessage(opts.Message).WithReference(opts.Reference)
|
options := new(images.ImportOptions).WithChanges(opts.Changes).WithMessage(opts.Message).WithReference(opts.Reference)
|
||||||
|
options.WithOS(opts.OS).WithArchitecture(opts.Architecture).WithVariant(opts.Variant)
|
||||||
if opts.SourceIsURL {
|
if opts.SourceIsURL {
|
||||||
options.WithURL(opts.Source)
|
options.WithURL(opts.Source)
|
||||||
} else {
|
} else {
|
||||||
|
@ -52,6 +52,26 @@ var _ = Describe("Podman import", func() {
|
|||||||
Expect(results).Should(Exit(0))
|
Expect(results).Should(Exit(0))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman import with custom os, arch and variant", func() {
|
||||||
|
outfile := filepath.Join(podmanTest.TempDir, "container.tar")
|
||||||
|
_, ec, cid := podmanTest.RunLsContainer("")
|
||||||
|
Expect(ec).To(Equal(0))
|
||||||
|
|
||||||
|
export := podmanTest.Podman([]string{"export", "-o", outfile, cid})
|
||||||
|
export.WaitWithDefaultTimeout()
|
||||||
|
Expect(export).Should(Exit(0))
|
||||||
|
|
||||||
|
importImage := podmanTest.Podman([]string{"import", "--os", "testos", "--arch", "testarch", outfile, "foobar.com/imported-image:latest"})
|
||||||
|
importImage.WaitWithDefaultTimeout()
|
||||||
|
Expect(importImage).Should(Exit(0))
|
||||||
|
|
||||||
|
results := podmanTest.Podman([]string{"inspect", "--type", "image", "foobar.com/imported-image:latest"})
|
||||||
|
results.WaitWithDefaultTimeout()
|
||||||
|
Expect(results).Should(Exit(0))
|
||||||
|
Expect(results.OutputToString()).To(ContainSubstring("testos"))
|
||||||
|
Expect(results.OutputToString()).To(ContainSubstring("testarch"))
|
||||||
|
})
|
||||||
|
|
||||||
It("podman import without reference", func() {
|
It("podman import without reference", func() {
|
||||||
outfile := filepath.Join(podmanTest.TempDir, "container.tar")
|
outfile := filepath.Join(podmanTest.TempDir, "container.tar")
|
||||||
_, ec, cid := podmanTest.RunLsContainer("")
|
_, ec, cid := podmanTest.RunLsContainer("")
|
||||||
|
Reference in New Issue
Block a user