Files
podman/pkg/api/handlers/libpod/containers_create.go
Matthew Heon 02671a103f Add support for volumes-from, image volumes, init
This should complete Podmanv2's support for volume-related flags.
Most code was sourced from the old pkg/spec implementation with
modifications to account for the split between frontend flags
(volume, mount, tmpfs) and the backend flags implemented here.

Also enables tests for podman run with volumes

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-04-27 13:13:21 -04:00

38 lines
1.1 KiB
Go

package libpod
import (
"context"
"encoding/json"
"net/http"
"github.com/containers/libpod/pkg/domain/entities"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/api/handlers/utils"
"github.com/containers/libpod/pkg/specgen"
"github.com/containers/libpod/pkg/specgen/generate"
"github.com/pkg/errors"
)
// CreateContainer takes a specgenerator and makes a container. It returns
// the new container ID on success along with any warnings.
func CreateContainer(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value("runtime").(*libpod.Runtime)
var sg specgen.SpecGenerator
if err := json.NewDecoder(r.Body).Decode(&sg); err != nil {
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Decode()"))
return
}
if err := generate.CompleteSpec(r.Context(), runtime, &sg); err != nil {
utils.InternalServerError(w, err)
return
}
ctr, err := generate.MakeContainer(context.Background(), runtime, &sg)
if err != nil {
utils.InternalServerError(w, err)
return
}
response := entities.ContainerCreateResponse{ID: ctr.ID()}
utils.WriteJSON(w, http.StatusCreated, response)
}