From d924494f561bb878a2b3a7ce438d87ecb934b5fb Mon Sep 17 00:00:00 2001 From: Jhon Honce Date: Fri, 1 Nov 2019 13:03:34 -0700 Subject: Initial commit on compatible API Signed-off-by: Jhon Honce Create service command Use cd cmd/service && go build . $ systemd-socket-activate -l 8081 cmd/service/service & $ curl http://localhost:8081/v1.24/images/json Signed-off-by: Jhon Honce Correct Makefile Signed-off-by: Jhon Honce Two more stragglers Signed-off-by: Jhon Honce Report errors back as http headers Signed-off-by: Jhon Honce Split out handlers, updated output Output aligned to docker structures Signed-off-by: Jhon Honce Refactored routing, added more endpoints and types * Encapsulated all the routing information in the handler_* files. * Added more serviceapi/types, including podman additions. See Info Signed-off-by: Jhon Honce Cleaned up code, implemented info content * Move Content-Type check into serviceHandler * Custom 404 handler showing the url, mostly for debugging * Refactored images: better method names and explicit http codes * Added content to /info * Added podman fields to Info struct * Added Container struct Signed-off-by: Jhon Honce Add a bunch of endpoints containers: stop, pause, unpause, wait, rm images: tag, rmi, create (pull only) Signed-off-by: baude Add even more handlers * Add serviceapi/Error() to improve error handling * Better support for API return payloads * Renamed unimplemented to unsupported these are generic endpoints we don't intend to ever support. Swarm broken out since it uses different HTTP codes to signal that the node is not in a swarm. * Added more types * API Version broken out so it can be validated in the future Signed-off-by: Jhon Honce Refactor to introduce ServiceWriter Signed-off-by: Jhon Honce populate pods endpoints /libpod/pods/.. exists, kill, pause, prune, restart, remove, start, stop, unpause Signed-off-by: baude Add components to Version, fix Error body Signed-off-by: Jhon Honce Add images pull output, fix swarm routes * docker-py tests/integration/api_client_test.py pass 100% * docker-py tests/integration/api_image_test.py pass 4/16 + Test failures include services podman does not support Signed-off-by: Jhon Honce pods endpoint submission 2 add create and others; only top and stats is left. Signed-off-by: baude Update pull image to work from empty registry Signed-off-by: Jhon Honce pod create and container create first pass at pod and container create. the container create does not quite work yet but it is very close. pod create needs a partial rewrite. also broken off the DELETE (rm/rmi) to specific handler funcs. Signed-off-by: baude Add docker-py demos, GET .../containers/json * Update serviceapi/types to reflect libpod not podman * Refactored removeImage() to provide non-streaming return Signed-off-by: Jhon Honce create container part2 finished minimal config needed for create container. started demo.py for upcoming talk Signed-off-by: baude Stop server after honoring request * Remove casting for method calls * Improve WriteResponse() * Update Container API type to match docker API Signed-off-by: Jhon Honce fix namespace assumptions cleaned up namespace issues with libpod. Signed-off-by: baude wip Signed-off-by: baude Add sliding window when shutting down server * Added a Timeout rather than closing down service on each call * Added gorilla/schema dependency for Decode'ing query parameters * Improved error handling * Container logs returned and multiplexed for stdout and stderr * .../containers/{name}/logs?stdout=True&stderr=True * Container stats * .../containers/{name}/stats Signed-off-by: Jhon Honce Improve error handling * Add check for at least one std stream required for /containers/{id}/logs * Add check for state in /containers/{id}/top * Fill in more fields for /info * Fixed error checking in service start code Signed-off-by: Jhon Honce get rest of image tests for pass Signed-off-by: baude linting our content Signed-off-by: baude more linting Signed-off-by: baude more linting Signed-off-by: baude pruning Signed-off-by: baude [CI:DOCS]apiv2 pods migrate from using args in the url to using a json struct in body for pod create. Signed-off-by: baude fix handler_images prune prune's api changed slightly to deal with filters. Signed-off-by: baude [CI:DOCS]enabled base container create tests enabling the base container create tests which allow us to get more into the stop, kill, etc tests. many new tests now pass. Signed-off-by: baude serviceapi errors: append error message to API message I dearly hope this is not breaking any other tests but debugging "Internal Server Error" is not helpful to any user. In case, it breaks tests, we can rever the commit - that's why it's a small one. Signed-off-by: Valentin Rothberg serviceAPI: add containers/prune endpoint Signed-off-by: Valentin Rothberg add `service` make target Also remove the non-functional sub-Makefile. Signed-off-by: Valentin Rothberg add make targets for testing the service * `sudo make run-service` for running the service. * `DOCKERPY_TEST="tests/integration/api_container_test.py::ListContainersTest" \ make run-docker-py-tests` for running a specific tests. Run all tests by leaving the env variable empty. Signed-off-by: Valentin Rothberg Split handlers and server packages The files were split to help contain bloat. The api/server package will contain all code related to the functioning of the server while api/handlers will have all the code related to implementing the end points. api/server/register_* will contain the methods for registering endpoints. Additionally, they will have the comments for generating the swagger spec file. See api/handlers/version.go for a small example handler, api/handlers/containers.go contains much more complex handlers. Signed-off-by: Jhon Honce [CI:DOCS]enabled more tests Signed-off-by: baude [CI:DOCS]libpod endpoints small refactor for libpod inclusion and began adding endpoints. Signed-off-by: baude Implement /build and /events * Include crypto libraries for future ssh work Signed-off-by: Jhon Honce [CI:DOCS]more image implementations convert from using for to query structs among other changes including new endpoints. Signed-off-by: baude [CI:DOCS]add bindings for golang Signed-off-by: baude [CI:DOCS]add volume endpoints for libpod create, inspect, ls, prune, and rm Signed-off-by: baude [CI:DOCS]apiv2 healthcheck enablement wire up container healthchecks for the api. Signed-off-by: baude [CI:DOCS]Add mount endpoints via the api, allow ability to mount a container and list container mounts. Signed-off-by: baude [CI:DOCS]Add search endpoint add search endpoint with golang bindings Signed-off-by: baude [CI:DOCS]more apiv2 development misc population of methods, etc Signed-off-by: baude rebase cleanup and epoch reset Signed-off-by: baude [CI:DOCS]add more network endpoints also, add some initial error handling and convenience functions for standard endpoints. Signed-off-by: baude [CI:DOCS]use helper funcs for bindings use the methods developed to make writing bindings less duplicative and easier to use. Signed-off-by: baude [CI:DOCS]add return info for prereview begin to add return info and status codes for errors so that we can review the apiv2 Signed-off-by: baude [CI:DOCS]first pass at adding swagger docs for api Signed-off-by: baude --- pkg/api/handlers/handler.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 pkg/api/handlers/handler.go (limited to 'pkg/api/handlers/handler.go') diff --git a/pkg/api/handlers/handler.go b/pkg/api/handlers/handler.go new file mode 100644 index 000000000..1ea7dc60a --- /dev/null +++ b/pkg/api/handlers/handler.go @@ -0,0 +1,45 @@ +package handlers + +import ( + "github.com/containers/libpod/libpod" + "github.com/gorilla/mux" + "github.com/gorilla/schema" + "github.com/pkg/errors" + "net/http" +) + +// Convenience routines to reduce boiler plate in handlers + +func getVar(r *http.Request, k string) string { + return mux.Vars(r)[k] +} + +func hasVar(r *http.Request, k string) bool { + _, found := mux.Vars(r)[k] + return found +} +func getName(r *http.Request) string { + return getVar(r, "name") +} + +func decodeQuery(r *http.Request, i interface{}) error { + decoder := r.Context().Value("decoder").(*schema.Decoder) + + if err := decoder.Decode(i, r.URL.Query()); err != nil { + return errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()) + } + return nil +} + +func getRuntime(r *http.Request) *libpod.Runtime { + return r.Context().Value("runtime").(*libpod.Runtime) +} + +func getHeader(r *http.Request, k string) string { + return r.Header.Get(k) +} + +func hasHeader(r *http.Request, k string) bool { + _, found := r.Header[k] + return found +} -- cgit v1.2.3-54-g00ecf From c3956b1974ce545446a443488497dfbc98dda1a8 Mon Sep 17 00:00:00 2001 From: baude Date: Fri, 10 Jan 2020 09:47:19 -0600 Subject: address review comments before merge Signed-off-by: baude --- libpod/container_internal.go | 12 ++++-------- pkg/api/handlers/containers_top.go | 2 +- pkg/api/handlers/events.go | 2 +- pkg/api/handlers/generic/containers_create.go | 2 +- pkg/api/handlers/generic/info.go | 4 ++-- pkg/api/handlers/generic/system.go | 4 ++-- pkg/api/handlers/generic/version.go | 4 ++-- pkg/api/handlers/handler.go | 3 ++- pkg/api/server/register_swarm.go | 2 +- 9 files changed, 16 insertions(+), 19 deletions(-) (limited to 'pkg/api/handlers/handler.go') diff --git a/libpod/container_internal.go b/libpod/container_internal.go index 1d118dcb0..46c83149a 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -1195,10 +1195,8 @@ func (c *Container) pause() error { } if err := c.ociRuntime.PauseContainer(c); err != nil { - // TODO disabling to pass dockerpy tests. there is some sort of problem and perhaps - //a race going on here. - logrus.Error(err) - //return err + // TODO when using docker-py there is some sort of race/incompatibility here + return err } logrus.Debugf("Paused container %s", c.ID()) @@ -1215,10 +1213,8 @@ func (c *Container) unpause() error { } if err := c.ociRuntime.UnpauseContainer(c); err != nil { - // TODO disabling to pass dockerpy tests. there is some sort of problem and perhaps - //a race going on here. - logrus.Error(err) - //return err + // TODO when using docker-py there is some sort of race/incompatibility here + return err } logrus.Debugf("Unpaused container %s", c.ID()) diff --git a/pkg/api/handlers/containers_top.go b/pkg/api/handlers/containers_top.go index 03081372e..bab559da1 100644 --- a/pkg/api/handlers/containers_top.go +++ b/pkg/api/handlers/containers_top.go @@ -1,12 +1,12 @@ package handlers import ( - "github.com/containers/libpod/pkg/api/handlers/utils" "net/http" "strings" "github.com/containers/libpod/libpod" "github.com/containers/libpod/libpod/define" + "github.com/containers/libpod/pkg/api/handlers/utils" "github.com/gorilla/mux" "github.com/gorilla/schema" "github.com/pkg/errors" diff --git a/pkg/api/handlers/events.go b/pkg/api/handlers/events.go index 267d552df..900efa3da 100644 --- a/pkg/api/handlers/events.go +++ b/pkg/api/handlers/events.go @@ -3,9 +3,9 @@ package handlers import ( "encoding/json" "fmt" - "github.com/containers/libpod/pkg/api/handlers/utils" "net/http" + "github.com/containers/libpod/pkg/api/handlers/utils" "github.com/pkg/errors" ) diff --git a/pkg/api/handlers/generic/containers_create.go b/pkg/api/handlers/generic/containers_create.go index 056f7e95c..ef5337abd 100644 --- a/pkg/api/handlers/generic/containers_create.go +++ b/pkg/api/handlers/generic/containers_create.go @@ -3,7 +3,6 @@ package generic import ( "encoding/json" "fmt" - "github.com/containers/libpod/pkg/api/handlers/utils" "net/http" "strings" @@ -12,6 +11,7 @@ import ( "github.com/containers/libpod/libpod/define" image2 "github.com/containers/libpod/libpod/image" "github.com/containers/libpod/pkg/api/handlers" + "github.com/containers/libpod/pkg/api/handlers/utils" "github.com/containers/libpod/pkg/namespaces" createconfig "github.com/containers/libpod/pkg/spec" "github.com/containers/storage" diff --git a/pkg/api/handlers/generic/info.go b/pkg/api/handlers/generic/info.go index 2bef8db4f..c9e79233d 100644 --- a/pkg/api/handlers/generic/info.go +++ b/pkg/api/handlers/generic/info.go @@ -2,8 +2,6 @@ package generic import ( "fmt" - "github.com/containers/libpod/pkg/api/handlers" - "github.com/containers/libpod/pkg/api/handlers/utils" "io/ioutil" "net/http" "os" @@ -14,6 +12,8 @@ import ( "github.com/containers/libpod/libpod" "github.com/containers/libpod/libpod/config" "github.com/containers/libpod/libpod/define" + "github.com/containers/libpod/pkg/api/handlers" + "github.com/containers/libpod/pkg/api/handlers/utils" "github.com/containers/libpod/pkg/rootless" "github.com/containers/libpod/pkg/sysinfo" docker "github.com/docker/docker/api/types" diff --git a/pkg/api/handlers/generic/system.go b/pkg/api/handlers/generic/system.go index 254990b95..edf1f8522 100644 --- a/pkg/api/handlers/generic/system.go +++ b/pkg/api/handlers/generic/system.go @@ -1,10 +1,10 @@ package generic import ( - "github.com/containers/libpod/pkg/api/handlers" - "github.com/containers/libpod/pkg/api/handlers/utils" "net/http" + "github.com/containers/libpod/pkg/api/handlers" + "github.com/containers/libpod/pkg/api/handlers/utils" docker "github.com/docker/docker/api/types" ) diff --git a/pkg/api/handlers/generic/version.go b/pkg/api/handlers/generic/version.go index 2c2283d10..39423914d 100644 --- a/pkg/api/handlers/generic/version.go +++ b/pkg/api/handlers/generic/version.go @@ -2,14 +2,14 @@ package generic import ( "fmt" - "github.com/containers/libpod/pkg/api/handlers" - "github.com/containers/libpod/pkg/api/handlers/utils" "net/http" goRuntime "runtime" "time" "github.com/containers/libpod/libpod" "github.com/containers/libpod/libpod/define" + "github.com/containers/libpod/pkg/api/handlers" + "github.com/containers/libpod/pkg/api/handlers/utils" docker "github.com/docker/docker/api/types" "github.com/pkg/errors" ) diff --git a/pkg/api/handlers/handler.go b/pkg/api/handlers/handler.go index 1ea7dc60a..2efeb1379 100644 --- a/pkg/api/handlers/handler.go +++ b/pkg/api/handlers/handler.go @@ -1,11 +1,12 @@ package handlers import ( + "net/http" + "github.com/containers/libpod/libpod" "github.com/gorilla/mux" "github.com/gorilla/schema" "github.com/pkg/errors" - "net/http" ) // Convenience routines to reduce boiler plate in handlers diff --git a/pkg/api/server/register_swarm.go b/pkg/api/server/register_swarm.go index 61c0b2d83..63d8acfde 100644 --- a/pkg/api/server/register_swarm.go +++ b/pkg/api/server/register_swarm.go @@ -2,9 +2,9 @@ package server import ( "errors" - "github.com/containers/libpod/pkg/api/handlers/utils" "net/http" + "github.com/containers/libpod/pkg/api/handlers/utils" "github.com/gorilla/mux" "github.com/sirupsen/logrus" ) -- cgit v1.2.3-54-g00ecf