Image import fromSrc now supports OS/Arch
added handling in entities and compat to support passing a specified OS/Arch while importing from SRC. fixes #10566 Signed-off-by: cdoern <cbdoer23@g.holycross.edu>
This commit is contained in:
parent
2970e3518c
commit
3ddadc5326
|
|
@ -166,10 +166,11 @@ func CreateImageFromSrc(w http.ResponseWriter, r *http.Request) {
|
||||||
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
||||||
|
|
||||||
query := struct {
|
query := struct {
|
||||||
FromSrc string `schema:"fromSrc"`
|
Changes []string `schema:"changes"`
|
||||||
Changes []string `schema:"changes"`
|
FromSrc string `schema:"fromSrc"`
|
||||||
Message string `schema:"message"`
|
Message string `schema:"message"`
|
||||||
Repo string `shchema:"repo"`
|
Platform string `schema:"platform"`
|
||||||
|
Repo string `shchema:"repo"`
|
||||||
}{
|
}{
|
||||||
// This is where you can override the golang default value for one of fields
|
// This is where you can override the golang default value for one of fields
|
||||||
}
|
}
|
||||||
|
|
@ -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"))
|
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}
|
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(), opts)
|
||||||
report, err := imageEngine.Import(r.Context(), entities.ImageImportOptions{Source: source, Changes: query.Changes, Message: query.Message, Reference: query.Repo})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "unable to import tarball"))
|
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "unable to import tarball"))
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -271,8 +271,10 @@ type ImageLoadReport struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ImageImportOptions struct {
|
type ImageImportOptions struct {
|
||||||
|
Architecture string
|
||||||
Changes []string
|
Changes []string
|
||||||
Message string
|
Message string
|
||||||
|
OS string
|
||||||
Quiet bool
|
Quiet bool
|
||||||
Reference string
|
Reference string
|
||||||
SignaturePolicy string
|
SignaturePolicy string
|
||||||
|
|
|
||||||
|
|
@ -388,6 +388,8 @@ func (ir *ImageEngine) Import(ctx context.Context, options entities.ImageImportO
|
||||||
importOptions.CommitMessage = options.Message
|
importOptions.CommitMessage = options.Message
|
||||||
importOptions.Tag = options.Reference
|
importOptions.Tag = options.Reference
|
||||||
importOptions.SignaturePolicyPath = options.SignaturePolicy
|
importOptions.SignaturePolicyPath = options.SignaturePolicy
|
||||||
|
importOptions.OS = options.OS
|
||||||
|
importOptions.Architecture = options.Architecture
|
||||||
|
|
||||||
if !options.Quiet {
|
if !options.Quiet {
|
||||||
importOptions.Writer = os.Stderr
|
importOptions.Writer = os.Stderr
|
||||||
|
|
|
||||||
|
|
@ -89,14 +89,9 @@ class ImageTestCase(APITestCase):
|
||||||
|
|
||||||
def test_create(self):
|
def test_create(self):
|
||||||
r = requests.post(
|
r = requests.post(
|
||||||
self.podman_url + "/v1.40/images/create?fromImage=alpine&platform=linux/amd64/v8",
|
self.podman_url + "/v1.40/images/create?fromImage=alpine&platform=linux/amd64/v8", timeout=15)
|
||||||
timeout=15,
|
|
||||||
)
|
|
||||||
self.assertEqual(r.status_code, 200, r.text)
|
self.assertEqual(r.status_code, 200, r.text)
|
||||||
r = requests.post(
|
r = requests.post(self.podman_url + "/v1.40/images/create?fromSrc=-&repo=fedora&message=testing123&platform=linux/amd64", timeout=15)
|
||||||
self.podman_url + "/v1.40/images/create?fromSrc=-&repo=fedora&message=testing123",
|
|
||||||
timeout=15,
|
|
||||||
)
|
|
||||||
self.assertEqual(r.status_code, 200, r.text)
|
self.assertEqual(r.status_code, 200, r.text)
|
||||||
|
|
||||||
def test_search_compat(self):
|
def test_search_compat(self):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue