Skip to content

Commit

Permalink
Merge pull request containers#13588 from flouthoc/import-os-arch
Browse files Browse the repository at this point in the history
import: allow users to set `--os`, `--arch` and `--variant` of image imports
  • Loading branch information
openshift-merge-robot committed Mar 23, 2022
2 parents 9d8972e + eedce31 commit a8743d3
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 9 deletions.
12 changes: 12 additions & 0 deletions cmd/podman/images/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ func importFlags(cmd *cobra.Command) {
flags.StringVarP(&importOpts.Message, messageFlagName, "m", "", "Set commit message for imported image")
_ = 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")
if !registry.IsRemote() {
flags.StringVar(&importOpts.SignaturePolicy, "signature-policy", "", "Path to a signature-policy file")
Expand Down
12 changes: 12 additions & 0 deletions docs/source/markdown/podman-import.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Note: `:` is a restricted character and cannot be part of the file name.

## OPTIONS

#### **--arch**

Set architecture of the imported image.

#### **--change**=*instruction*, **-c**

Apply the following possible instructions to the created image:
Expand All @@ -30,10 +34,18 @@ Can be set multiple times

Set commit message for imported image

#### **--os**

Set OS of the imported image.

#### **--quiet**, **-q**

Shows progress on the import

#### **--variant**

Set variant of the imported image.

**--verbose**

Print additional debugging information
Expand Down
22 changes: 14 additions & 8 deletions pkg/api/handlers/libpod/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,13 @@ func ImagesImport(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder)
query := struct {
Changes []string `schema:"changes"`
Message string `schema:"message"`
Reference string `schema:"reference"`
URL string `schema:"URL"`
Changes []string `schema:"changes"`
Message string `schema:"message"`
Reference string `schema:"reference"`
URL string `schema:"URL"`
OS string `schema:"OS"`
Architecture string `schema:"Architecture"`
Variant string `schema:"Variant"`
}{
// Add defaults here once needed.
}
Expand Down Expand Up @@ -402,10 +405,13 @@ func ImagesImport(w http.ResponseWriter, r *http.Request) {

imageEngine := abi.ImageEngine{Libpod: runtime}
importOptions := entities.ImageImportOptions{
Changes: query.Changes,
Message: query.Message,
Reference: query.Reference,
Source: source,
Changes: query.Changes,
Message: query.Message,
Reference: query.Reference,
OS: query.OS,
Architecture: query.Architecture,
Variant: query.Variant,
Source: source,
}
report, err := imageEngine.Import(r.Context(), importOptions)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions pkg/bindings/images/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ type ImportOptions struct {
Reference *string
// Url to option image to import. Cannot be used with the reader
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
Expand Down
45 changes: 45 additions & 0 deletions pkg/bindings/images/types_import_options.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/domain/entities/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ type ImageLoadReport struct {

type ImageImportOptions struct {
Architecture string
Variant string
Changes []string
Message string
OS string
Expand Down
3 changes: 2 additions & 1 deletion pkg/domain/infra/abi/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,8 @@ func (ir *ImageEngine) Import(ctx context.Context, options entities.ImageImportO
importOptions.Tag = options.Reference
importOptions.SignaturePolicyPath = options.SignaturePolicy
importOptions.OS = options.OS
importOptions.Architecture = options.Architecture
importOptions.Arch = options.Architecture
importOptions.Variant = options.Variant

if !options.Quiet {
importOptions.Writer = os.Stderr
Expand Down
1 change: 1 addition & 0 deletions pkg/domain/infra/tunnel/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ func (ir *ImageEngine) Import(ctx context.Context, opts entities.ImageImportOpti
f *os.File
)
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 {
options.WithURL(opts.Source)
} else {
Expand Down
20 changes: 20 additions & 0 deletions test/e2e/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,26 @@ var _ = Describe("Podman import", func() {
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() {
outfile := filepath.Join(podmanTest.TempDir, "container.tar")
_, ec, cid := podmanTest.RunLsContainer("")
Expand Down

0 comments on commit a8743d3

Please sign in to comment.