Skip to content

Commit

Permalink
Merge pull request #10622 from cdoern/imgImportFeature
Browse files Browse the repository at this point in the history
compat import imageFromSrc support for platform query parameter
  • Loading branch information
openshift-merge-robot authored Jun 15, 2021
2 parents 6b517a7 + 3ddadc5 commit 463a5a7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
25 changes: 19 additions & 6 deletions pkg/api/handlers/compat/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,11 @@ func CreateImageFromSrc(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value("runtime").(*libpod.Runtime)

query := struct {
FromSrc string `schema:"fromSrc"`
Changes []string `schema:"changes"`
Message string `schema:"message"`
Repo string `shchema:"repo"`
Changes []string `schema:"changes"`
FromSrc string `schema:"fromSrc"`
Message string `schema:"message"`
Platform string `schema:"platform"`
Repo string `shchema:"repo"`
}{
// This is where you can override the golang default value for one of fields
}
Expand All @@ -192,9 +193,21 @@ func CreateImageFromSrc(w http.ResponseWriter, r *http.Request) {
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "failed to write temporary file"))
}
}

platformSpecs := strings.Split(query.Platform, "/")
opts := entities.ImageImportOptions{
Source: source,
Changes: query.Changes,
Message: query.Message,
Reference: query.Repo,
OS: platformSpecs[0],
}
if len(platformSpecs) > 1 {
opts.Architecture = platformSpecs[1]
}

imageEngine := abi.ImageEngine{Libpod: runtime}
// TODO: add support for ImageImportOptions to take a platform parameter. Also import https://github.com/opencontainers/image-spec/tree/master/specs-go/v1 either here or within imageEngine.Import to get default platform
report, err := imageEngine.Import(r.Context(), entities.ImageImportOptions{Source: source, Changes: query.Changes, Message: query.Message, Reference: query.Repo})
report, err := imageEngine.Import(r.Context(), opts)
if err != nil {
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "unable to import tarball"))
return
Expand Down
2 changes: 2 additions & 0 deletions pkg/domain/entities/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,10 @@ type ImageLoadReport struct {
}

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

if !options.Quiet {
importOptions.Writer = os.Stderr
Expand Down
9 changes: 2 additions & 7 deletions test/apiv2/python/rest_api/test_v2_0_0_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,9 @@ def test_pull(self):

def test_create(self):
r = requests.post(
self.podman_url + "/v1.40/images/create?fromImage=alpine&platform=linux/amd64/v8",
timeout=15,
)
self.podman_url + "/v1.40/images/create?fromImage=alpine&platform=linux/amd64/v8", timeout=15)
self.assertEqual(r.status_code, 200, r.text)
r = requests.post(
self.podman_url + "/v1.40/images/create?fromSrc=-&repo=fedora&message=testing123",
timeout=15,
)
r = requests.post(self.podman_url + "/v1.40/images/create?fromSrc=-&repo=fedora&message=testing123&platform=linux/amd64", timeout=15)
self.assertEqual(r.status_code, 200, r.text)

def test_search_compat(self):
Expand Down

0 comments on commit 463a5a7

Please sign in to comment.