v2 api: /libpod/images/import
Implement the /libpod/images/import endpoint Tested manually with curl: curl -X POST --data-binary "@image.tar" --header "Content-Type: application/x-tar" Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
parent
926c9f8fbb
commit
185c82bc80
|
|
@ -222,8 +222,50 @@ func ImagesLoad(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ImagesImport(w http.ResponseWriter, r *http.Request) {
|
func ImagesImport(w http.ResponseWriter, r *http.Request) {
|
||||||
//TODO ...
|
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
||||||
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.New("/libpod/images/import is not yet implemented"))
|
decoder := r.Context().Value("decoder").(*schema.Decoder)
|
||||||
|
query := struct {
|
||||||
|
Changes []string `schema:"changes"`
|
||||||
|
Message string `schema:"message"`
|
||||||
|
Reference string `schema:"reference"`
|
||||||
|
URL string `schema:"URL"`
|
||||||
|
}{
|
||||||
|
// Add defaults here once needed.
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
|
||||||
|
utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest,
|
||||||
|
errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if we need to load the image from a URL or from the request's body.
|
||||||
|
source := query.URL
|
||||||
|
if len(query.URL) == 0 {
|
||||||
|
tmpfile, err := ioutil.TempFile("", "libpod-images-import.tar")
|
||||||
|
if err != nil {
|
||||||
|
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "unable to create tempfile"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer os.Remove(tmpfile.Name())
|
||||||
|
defer tmpfile.Close()
|
||||||
|
|
||||||
|
if _, err := io.Copy(tmpfile, r.Body); err != nil && err != io.EOF {
|
||||||
|
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "unable to write archive to temporary file"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpfile.Close()
|
||||||
|
source = tmpfile.Name()
|
||||||
|
}
|
||||||
|
|
||||||
|
importedImage, err := runtime.Import(context.Background(), source, query.Reference, query.Changes, query.Message, true)
|
||||||
|
if err != nil {
|
||||||
|
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "unable to import image"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.WriteResponse(w, http.StatusOK, handlers.LibpodImagesImportReport{ID: importedImage})
|
||||||
}
|
}
|
||||||
|
|
||||||
func ImagesPull(w http.ResponseWriter, r *http.Request) {
|
func ImagesPull(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,7 @@ type LibpodImagesLoadReport struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type LibpodImagesImportReport struct {
|
type LibpodImagesImportReport struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
RepoTags []string `json:"repoTags"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type LibpodImagesPullReport struct {
|
type LibpodImagesPullReport struct {
|
||||||
|
|
|
||||||
|
|
@ -665,17 +665,23 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
|
||||||
// description: Import a previously exported tarball as an image.
|
// description: Import a previously exported tarball as an image.
|
||||||
// parameters:
|
// parameters:
|
||||||
// - in: query
|
// - in: query
|
||||||
// name: change
|
// name: changes
|
||||||
// description: "Apply the following possible instructions to the created image (default []): CMD | ENTRYPOINT | ENV | EXPOSE | LABEL | STOPSIGNAL | USER | VOLUME | WORKDIR. JSON encoded string"
|
// description: "Apply the following possible instructions to the created image: CMD | ENTRYPOINT | ENV | EXPOSE | LABEL | STOPSIGNAL | USER | VOLUME | WORKDIR. JSON encoded string"
|
||||||
// type: string
|
// type: array
|
||||||
|
// items:
|
||||||
|
// type: string
|
||||||
// - in: query
|
// - in: query
|
||||||
// name: message
|
// name: message
|
||||||
// description: Set commit message for imported image
|
// description: Set commit message for imported image
|
||||||
// type: string
|
// type: string
|
||||||
// - in: query
|
// - in: query
|
||||||
|
// name: change
|
||||||
|
// description: "Optional Name[:TAG] for the image"
|
||||||
|
// type: reference
|
||||||
|
// - in: query
|
||||||
// name: url
|
// name: url
|
||||||
// description: Specify a URL instead of a tarball
|
// description: Load image from the specified URL
|
||||||
// type: boolean
|
// type: string
|
||||||
// - in: formData
|
// - in: formData
|
||||||
// name: upload
|
// name: upload
|
||||||
// type: file
|
// type: file
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue