diff options
Diffstat (limited to 'pkg')
30 files changed, 186 insertions, 77 deletions
diff --git a/pkg/api/Makefile b/pkg/api/Makefile index 6b24bfd83..6da5fb57e 100644 --- a/pkg/api/Makefile +++ b/pkg/api/Makefile @@ -5,6 +5,9 @@ SWAGGER_OUT ?= swagger.yaml validate: ${SWAGGER_OUT} swagger validate ${SWAGGER_OUT} +serve: ${SWAGGER_OUT} + swagger serve -F redoc -p=8080 swagger.yaml + .PHONY: ${SWAGGER_OUT} ${SWAGGER_OUT}: # generate doesn't remove file on error diff --git a/pkg/api/handlers/compat/containers_start.go b/pkg/api/handlers/compat/containers_start.go index 391aa752d..f1ed1b2b8 100644 --- a/pkg/api/handlers/compat/containers_start.go +++ b/pkg/api/handlers/compat/containers_start.go @@ -42,7 +42,7 @@ func StartContainer(w http.ResponseWriter, r *http.Request) { utils.WriteResponse(w, http.StatusNotModified, nil) return } - if err := con.Start(r.Context(), len(con.PodID()) > 0); err != nil { + if err := con.Start(r.Context(), true); err != nil { utils.InternalServerError(w, err) return } diff --git a/pkg/api/handlers/compat/images_build.go b/pkg/api/handlers/compat/images_build.go index ab92434b1..700881926 100644 --- a/pkg/api/handlers/compat/images_build.go +++ b/pkg/api/handlers/compat/images_build.go @@ -15,6 +15,7 @@ import ( "github.com/containers/buildah" buildahDefine "github.com/containers/buildah/define" + "github.com/containers/buildah/pkg/parse" "github.com/containers/buildah/util" "github.com/containers/image/v5/types" "github.com/containers/podman/v3/libpod" @@ -445,6 +446,17 @@ func BuildImage(w http.ResponseWriter, r *http.Request) { }, } + if len(query.Platform) > 0 { + variant := "" + buildOptions.OS, buildOptions.Architecture, variant, err = parse.Platform(query.Platform) + if err != nil { + utils.BadRequest(w, "platform", query.Platform, err) + return + } + buildOptions.SystemContext.OSChoice = buildOptions.OS + buildOptions.SystemContext.ArchitectureChoice = buildOptions.Architecture + buildOptions.SystemContext.VariantChoice = variant + } if _, found := r.URL.Query()["timestamp"]; found { ts := time.Unix(query.Timestamp, 0) buildOptions.Timestamp = &ts diff --git a/pkg/api/handlers/compat/volumes.go b/pkg/api/handlers/compat/volumes.go index 42ece643b..d86fc1e19 100644 --- a/pkg/api/handlers/compat/volumes.go +++ b/pkg/api/handlers/compat/volumes.go @@ -266,7 +266,7 @@ func PruneVolumes(w http.ResponseWriter, r *http.Request) { } f := (url.Values)(*filterMap) - filterFuncs, err := filters.GenerateVolumeFilters(f) + filterFuncs, err := filters.GeneratePruneVolumeFilters(f) if err != nil { utils.Error(w, "Something when wrong.", http.StatusInternalServerError, errors.Wrapf(err, "failed to parse filters for %s", f.Encode())) return diff --git a/pkg/api/handlers/libpod/swagger.go b/pkg/api/handlers/libpod/swagger.go index 2631f19ac..9450a70d9 100644 --- a/pkg/api/handlers/libpod/swagger.go +++ b/pkg/api/handlers/libpod/swagger.go @@ -25,7 +25,7 @@ type swagInspectPodResponse struct { // swagger:response InspectManifest type swagInspectManifestResponse struct { // in:body - Body manifest.List + Body manifest.Schema2List } // Kill Pod diff --git a/pkg/api/handlers/libpod/system.go b/pkg/api/handlers/libpod/system.go index 02457eb8f..2b4cef1bb 100644 --- a/pkg/api/handlers/libpod/system.go +++ b/pkg/api/handlers/libpod/system.go @@ -72,6 +72,7 @@ func DiskUsage(w http.ResponseWriter, r *http.Request) { response, err := ic.SystemDf(r.Context(), options) if err != nil { utils.InternalServerError(w, err) + return } utils.WriteResponse(w, http.StatusOK, response) } diff --git a/pkg/api/handlers/libpod/volumes.go b/pkg/api/handlers/libpod/volumes.go index 442b53d1e..68aec30d5 100644 --- a/pkg/api/handlers/libpod/volumes.go +++ b/pkg/api/handlers/libpod/volumes.go @@ -150,7 +150,7 @@ func pruneVolumesHelper(r *http.Request) ([]*reports.PruneReport, error) { } f := (url.Values)(*filterMap) - filterFuncs, err := filters.GenerateVolumeFilters(f) + filterFuncs, err := filters.GeneratePruneVolumeFilters(f) if err != nil { return nil, err } diff --git a/pkg/api/server/register_containers.go b/pkg/api/server/register_containers.go index 3bf3e4e11..536c4707a 100644 --- a/pkg/api/server/register_containers.go +++ b/pkg/api/server/register_containers.go @@ -774,7 +774,7 @@ func (s *APIServer) registerContainersHandlers(r *mux.Router) error { // 500: // $ref: "#/responses/InternalError" r.HandleFunc(VersionedPath("/libpod/containers/prune"), s.APIHandler(compat.PruneContainers)).Methods(http.MethodPost) - // swagger:operation GET /libpod/containers/showmounted libpod ShowMountedContainersLibpod + // swagger:operation GET /libpod/containers/showmounted libpod ContainerShowMountedLibpod // --- // tags: // - containers @@ -1194,11 +1194,22 @@ func (s *APIServer) registerContainersHandlers(r *mux.Router) error { // - removing // - stopping // description: "Conditions to wait for. If no condition provided the 'exited' condition is assumed." + // - in: query + // name: interval + // type: string + // default: "250ms" + // description: Time Interval to wait before polling for completion. // produces: // - application/json + // - text/plain // responses: // 200: - // $ref: "#/responses/ContainerWaitResponse" + // description: Status code + // schema: + // type: integer + // format: int32 + // examples: + // text/plain: 137 // 404: // $ref: "#/responses/NoSuchContainer" // 500: @@ -1468,8 +1479,8 @@ func (s *APIServer) registerContainersHandlers(r *mux.Router) error { // 500: // $ref: "#/responses/InternalError" r.HandleFunc(VersionedPath("/libpod/containers/{name}/restore"), s.APIHandler(libpod.Restore)).Methods(http.MethodPost) - // swagger:operation GET /containers/{name}/changes libpod ContainerChangesLibpod - // swagger:operation GET /libpod/containers/{name}/changes compat ContainerChanges + // swagger:operation GET /containers/{name}/changes compat ContainerChanges + // swagger:operation GET /libpod/containers/{name}/changes libpod ContainerChangesLibpod // --- // tags: // - containers diff --git a/pkg/api/server/register_generate.go b/pkg/api/server/register_generate.go index 208bf668c..e10c7029c 100644 --- a/pkg/api/server/register_generate.go +++ b/pkg/api/server/register_generate.go @@ -8,7 +8,7 @@ import ( ) func (s *APIServer) registerGenerateHandlers(r *mux.Router) error { - // swagger:operation GET /libpod/generate/{name:.*}/systemd libpod GenerateSystemdLibpod + // swagger:operation GET /libpod/generate/{name}/systemd libpod GenerateSystemdLibpod // --- // tags: // - containers @@ -17,7 +17,7 @@ func (s *APIServer) registerGenerateHandlers(r *mux.Router) error { // description: Generate Systemd Units based on a pod or container. // parameters: // - in: path - // name: name:.* + // name: name // type: string // required: true // description: Name or ID of the container or pod. diff --git a/pkg/api/server/register_healthcheck.go b/pkg/api/server/register_healthcheck.go index e2fd5ac68..7d8541a51 100644 --- a/pkg/api/server/register_healthcheck.go +++ b/pkg/api/server/register_healthcheck.go @@ -8,7 +8,7 @@ import ( ) func (s *APIServer) registerHealthCheckHandlers(r *mux.Router) error { - // swagger:operation GET /libpod/containers/{name:.*}/healthcheck libpod ContainerHealthcheckLibpod + // swagger:operation GET /libpod/containers/{name}/healthcheck libpod ContainerHealthcheckLibpod // --- // tags: // - containers @@ -16,7 +16,7 @@ func (s *APIServer) registerHealthCheckHandlers(r *mux.Router) error { // description: Execute the defined healthcheck and return information about the results // parameters: // - in: path - // name: name:.* + // name: name // type: string // required: true // description: the name or ID of the container diff --git a/pkg/api/server/register_images.go b/pkg/api/server/register_images.go index de8d50cc9..b32c0df20 100644 --- a/pkg/api/server/register_images.go +++ b/pkg/api/server/register_images.go @@ -188,7 +188,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { r.Handle(VersionedPath("/images/search"), s.APIHandler(compat.SearchImages)).Methods(http.MethodGet) // Added non version path to URI to support docker non versioned paths r.Handle("/images/search", s.APIHandler(compat.SearchImages)).Methods(http.MethodGet) - // swagger:operation DELETE /images/{name:.*} compat ImageDelete + // swagger:operation DELETE /images/{name} compat ImageDelete // --- // tags: // - images (compat) @@ -196,7 +196,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // description: Delete an image from local storage // parameters: // - in: path - // name: name:.* + // name: name // type: string // required: true // description: name or ID of image to delete @@ -222,7 +222,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { r.Handle(VersionedPath("/images/{name:.*}"), s.APIHandler(compat.RemoveImage)).Methods(http.MethodDelete) // Added non version path to URI to support docker non versioned paths r.Handle("/images/{name:.*}", s.APIHandler(compat.RemoveImage)).Methods(http.MethodDelete) - // swagger:operation POST /images/{name:.*}/push compat ImagePush + // swagger:operation POST /images/{name}/push compat ImagePush // --- // tags: // - images (compat) @@ -230,7 +230,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // description: Push an image to a container registry // parameters: // - in: path - // name: name:.* + // name: name // type: string // required: true // description: Name of image to push. @@ -269,7 +269,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { r.Handle(VersionedPath("/images/{name:.*}/push"), s.APIHandler(compat.PushImage)).Methods(http.MethodPost) // Added non version path to URI to support docker non versioned paths r.Handle("/images/{name:.*}/push", s.APIHandler(compat.PushImage)).Methods(http.MethodPost) - // swagger:operation GET /images/{name:.*}/get compat ImageGet + // swagger:operation GET /images/{name}/get compat ImageGet // --- // tags: // - images (compat) @@ -277,7 +277,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // description: Export an image in tarball format // parameters: // - in: path - // name: name:.* + // name: name // type: string // required: true // description: the name or ID of the container @@ -319,7 +319,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { r.Handle(VersionedPath("/images/get"), s.APIHandler(compat.ExportImages)).Methods(http.MethodGet) // Added non version path to URI to support docker non versioned paths r.Handle("/images/get", s.APIHandler(compat.ExportImages)).Methods(http.MethodGet) - // swagger:operation GET /images/{name:.*}/history compat ImageHistory + // swagger:operation GET /images/{name}/history compat ImageHistory // --- // tags: // - images (compat) @@ -327,7 +327,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // description: Return parent layers of an image. // parameters: // - in: path - // name: name:.* + // name: name // type: string // required: true // description: the name or ID of the container @@ -343,7 +343,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { r.Handle(VersionedPath("/images/{name:.*}/history"), s.APIHandler(compat.HistoryImage)).Methods(http.MethodGet) // Added non version path to URI to support docker non versioned paths r.Handle("/images/{name:.*}/history", s.APIHandler(compat.HistoryImage)).Methods(http.MethodGet) - // swagger:operation GET /images/{name:.*}/json compat ImageInspect + // swagger:operation GET /images/{name}/json compat ImageInspect // --- // tags: // - images (compat) @@ -351,7 +351,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // description: Return low-level information about an image. // parameters: // - in: path - // name: name:.* + // name: name // type: string // required: true // description: the name or ID of the container @@ -367,7 +367,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { r.Handle(VersionedPath("/images/{name:.*}/json"), s.APIHandler(compat.GetImage)).Methods(http.MethodGet) // Added non version path to URI to support docker non versioned paths r.Handle("/images/{name:.*}/json", s.APIHandler(compat.GetImage)).Methods(http.MethodGet) - // swagger:operation POST /images/{name:.*}/tag compat ImageTag + // swagger:operation POST /images/{name}/tag compat ImageTag // --- // tags: // - images (compat) @@ -375,7 +375,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // description: Tag an image so that it becomes part of a repository. // parameters: // - in: path - // name: name:.* + // name: name // type: string // required: true // description: the name or ID of the container @@ -667,7 +667,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { libpod endpoints */ - // swagger:operation POST /libpod/images/{name:.*}/push libpod ImagePushLibpod + // swagger:operation POST /libpod/images/{name}/push libpod ImagePushLibpod // --- // tags: // - images @@ -675,7 +675,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // description: Push an image to a container registry // parameters: // - in: path - // name: name:.* + // name: name // type: string // required: true // description: Name of image to push. @@ -705,7 +705,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // 500: // $ref: '#/responses/InternalError' r.Handle(VersionedPath("/libpod/images/{name:.*}/push"), s.APIHandler(libpod.PushImage)).Methods(http.MethodPost) - // swagger:operation GET /libpod/images/{name:.*}/exists libpod ImageExistsLibpod + // swagger:operation GET /libpod/images/{name}/exists libpod ImageExistsLibpod // --- // tags: // - images @@ -713,7 +713,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // description: Check if image exists in local store // parameters: // - in: path - // name: name:.* + // name: name // type: string // required: true // description: the name or ID of the container @@ -727,7 +727,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // 500: // $ref: '#/responses/InternalError' r.Handle(VersionedPath("/libpod/images/{name:.*}/exists"), s.APIHandler(libpod.ImageExists)).Methods(http.MethodGet) - // swagger:operation GET /libpod/images/{name:.*}/tree libpod ImageTreeLibpod + // swagger:operation GET /libpod/images/{name}/tree libpod ImageTreeLibpod // --- // tags: // - images @@ -735,7 +735,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // description: Retrieve the image tree for the provided image name or ID // parameters: // - in: path - // name: name:.* + // name: name // type: string // required: true // description: the name or ID of the container @@ -753,7 +753,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // 500: // $ref: '#/responses/InternalError' r.Handle(VersionedPath("/libpod/images/{name:.*}/tree"), s.APIHandler(libpod.ImageTree)).Methods(http.MethodGet) - // swagger:operation GET /libpod/images/{name:.*}/history libpod ImageHistoryLibpod + // swagger:operation GET /libpod/images/{name}/history libpod ImageHistoryLibpod // --- // tags: // - images @@ -761,7 +761,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // description: Return parent layers of an image. // parameters: // - in: path - // name: name:.* + // name: name // type: string // required: true // description: the name or ID of the container @@ -906,7 +906,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // 500: // $ref: '#/responses/InternalError' r.Handle(VersionedPath("/libpod/images/remove"), s.APIHandler(libpod.ImagesBatchRemove)).Methods(http.MethodDelete) - // swagger:operation DELETE /libpod/images/{name:.*} libpod ImageDeleteLibpod + // swagger:operation DELETE /libpod/images/{name} libpod ImageDeleteLibpod // --- // tags: // - images @@ -914,7 +914,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // description: Remove an image from the local storage. // parameters: // - in: path - // name: name:.* + // name: name // type: string // required: true // description: name or ID of image to remove @@ -1042,7 +1042,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // 500: // $ref: '#/responses/InternalError' r.Handle(VersionedPath("/libpod/images/search"), s.APIHandler(compat.SearchImages)).Methods(http.MethodGet) - // swagger:operation GET /libpod/images/{name:.*}/get libpod ImageGetLibpod + // swagger:operation GET /libpod/images/{name}/get libpod ImageGetLibpod // --- // tags: // - images @@ -1050,7 +1050,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // description: Export an image // parameters: // - in: path - // name: name:.* + // name: name // type: string // required: true // description: the name or ID of the container @@ -1109,7 +1109,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // 500: // $ref: '#/responses/InternalError' r.Handle(VersionedPath("/libpod/images/export"), s.APIHandler(libpod.ExportImages)).Methods(http.MethodGet) - // swagger:operation GET /libpod/images/{name:.*}/json libpod ImageInspectLibpod + // swagger:operation GET /libpod/images/{name}/json libpod ImageInspectLibpod // --- // tags: // - images @@ -1117,7 +1117,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // description: Obtain low-level information about an image // parameters: // - in: path - // name: name:.* + // name: name // type: string // required: true // description: the name or ID of the container @@ -1131,7 +1131,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // 500: // $ref: '#/responses/InternalError' r.Handle(VersionedPath("/libpod/images/{name:.*}/json"), s.APIHandler(libpod.GetImage)).Methods(http.MethodGet) - // swagger:operation POST /libpod/images/{name:.*}/tag libpod ImageTagLibpod + // swagger:operation POST /libpod/images/{name}/tag libpod ImageTagLibpod // --- // tags: // - images @@ -1139,7 +1139,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // description: Tag an image so that it becomes part of a repository. // parameters: // - in: path - // name: name:.* + // name: name // type: string // required: true // description: the name or ID of the container @@ -1217,7 +1217,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // 500: // $ref: '#/responses/InternalError' r.Handle(VersionedPath("/libpod/commit"), s.APIHandler(libpod.CommitContainer)).Methods(http.MethodPost) - // swagger:operation POST /libpod/images/{name:.*}/untag libpod ImageUntagLibpod + // swagger:operation POST /libpod/images/{name}/untag libpod ImageUntagLibpod // --- // tags: // - images @@ -1225,7 +1225,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // description: Untag an image. If not repo and tag are specified, all tags are removed from the image. // parameters: // - in: path - // name: name:.* + // name: name // type: string // required: true // description: the name or ID of the container diff --git a/pkg/api/server/register_manifest.go b/pkg/api/server/register_manifest.go index 0417462a6..010d8a79e 100644 --- a/pkg/api/server/register_manifest.go +++ b/pkg/api/server/register_manifest.go @@ -59,7 +59,7 @@ func (s *APIServer) registerManifestHandlers(r *mux.Router) error { // 500: // $ref: '#/responses/InternalError' r.Handle(VersionedPath("/libpod/manifests/{name}/exists"), s.APIHandler(libpod.ExistsManifest)).Methods(http.MethodGet) - // swagger:operation GET /libpod/manifests/{name:.*}/json manifests ManifestInspectLibpod + // swagger:operation GET /libpod/manifests/{name}/json manifests ManifestInspectLibpod // --- // summary: Inspect // description: Display a manifest list @@ -67,7 +67,7 @@ func (s *APIServer) registerManifestHandlers(r *mux.Router) error { // - application/json // parameters: // - in: path - // name: name:.* + // name: name // type: string // required: true // description: the name or ID of the manifest @@ -79,14 +79,15 @@ func (s *APIServer) registerManifestHandlers(r *mux.Router) error { // 500: // $ref: "#/responses/InternalError" r.Handle(VersionedPath("/libpod/manifests/{name:.*}/json"), s.APIHandler(libpod.ManifestInspect)).Methods(http.MethodGet) - // swagger:operation POST /libpod/manifests/{name:.*}/add manifests ManifestAddLibpod + // swagger:operation POST /libpod/manifests/{name}/add manifests ManifestAddLibpod // --- + // summary: Add image // description: Add an image to a manifest list // produces: // - application/json // parameters: // - in: path - // name: name:.* + // name: name // type: string // required: true // description: the name or ID of the manifest @@ -106,7 +107,7 @@ func (s *APIServer) registerManifestHandlers(r *mux.Router) error { // 500: // $ref: "#/responses/InternalError" r.Handle(VersionedPath("/libpod/manifests/{name:.*}/add"), s.APIHandler(libpod.ManifestAdd)).Methods(http.MethodPost) - // swagger:operation DELETE /libpod/manifests/{name:.*} manifests ManifestDeleteLibpod + // swagger:operation DELETE /libpod/manifests/{name} manifests ManifestDeleteLibpod // --- // summary: Remove // description: Remove an image from a manifest list @@ -114,7 +115,7 @@ func (s *APIServer) registerManifestHandlers(r *mux.Router) error { // - application/json // parameters: // - in: path - // name: name:.* + // name: name // type: string // required: true // description: the image associated with the manifest diff --git a/pkg/api/server/register_play.go b/pkg/api/server/register_play.go index b9d3349be..d21029db5 100644 --- a/pkg/api/server/register_play.go +++ b/pkg/api/server/register_play.go @@ -8,7 +8,7 @@ import ( ) func (s *APIServer) registerPlayHandlers(r *mux.Router) error { - // swagger:operation POST /libpod/play/kube libpod KubePlayLibpod + // swagger:operation POST /libpod/play/kube libpod PlayKubeLibpod // --- // tags: // - containers diff --git a/pkg/api/server/register_pods.go b/pkg/api/server/register_pods.go index 226cbce11..5944b98fd 100644 --- a/pkg/api/server/register_pods.go +++ b/pkg/api/server/register_pods.go @@ -305,7 +305,7 @@ func (s *APIServer) registerPodsHandlers(r *mux.Router) error { // 500: // $ref: "#/responses/InternalError" r.Handle(VersionedPath("/libpod/pods/{name}/top"), s.APIHandler(libpod.PodTop)).Methods(http.MethodGet) - // swagger:operation GET /libpod/pods/stats pods PodStatsLibpod + // swagger:operation GET /libpod/pods/stats pods PodStatsAllLibpod // --- // tags: // - pods diff --git a/pkg/bindings/containers/types.go b/pkg/bindings/containers/types.go index f63e35bf1..0d22c32f8 100644 --- a/pkg/bindings/containers/types.go +++ b/pkg/bindings/containers/types.go @@ -154,6 +154,7 @@ type RestartOptions struct { // StartOptions are optional options for starting containers type StartOptions struct { DetachKeys *string + Recursive *bool } //go:generate go run ../generator/generator.go StatsOptions diff --git a/pkg/bindings/containers/types_start_options.go b/pkg/bindings/containers/types_start_options.go index f8ba29623..d419c755c 100644 --- a/pkg/bindings/containers/types_start_options.go +++ b/pkg/bindings/containers/types_start_options.go @@ -35,3 +35,19 @@ func (o *StartOptions) GetDetachKeys() string { } return *o.DetachKeys } + +// WithRecursive +func (o *StartOptions) WithRecursive(value bool) *StartOptions { + v := &value + o.Recursive = v + return o +} + +// GetRecursive +func (o *StartOptions) GetRecursive() bool { + var recursive bool + if o.Recursive == nil { + return recursive + } + return *o.Recursive +} diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go index c47a16551..34d6cee05 100644 --- a/pkg/bindings/images/build.go +++ b/pkg/bindings/images/build.go @@ -12,6 +12,7 @@ import ( "os" "path/filepath" "regexp" + "runtime" "strconv" "strings" @@ -190,6 +191,10 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO platform = "linux" } platform += "/" + options.Architecture + } else { + if len(platform) > 0 { + platform += "/" + runtime.GOARCH + } } if len(platform) > 0 { params.Set("platform", platform) diff --git a/pkg/cgroups/cgroups.go b/pkg/cgroups/cgroups.go index 608e1647a..aefb5183b 100644 --- a/pkg/cgroups/cgroups.go +++ b/pkg/cgroups/cgroups.go @@ -265,7 +265,7 @@ func readFileAsUint64(path string) (uint64, error) { if v == "max" { return math.MaxUint64, nil } - ret, err := strconv.ParseUint(v, 10, 0) + ret, err := strconv.ParseUint(v, 10, 64) if err != nil { return ret, errors.Wrapf(err, "parse %s from %s", v, path) } diff --git a/pkg/cgroups/cpu.go b/pkg/cgroups/cpu.go index 05223c2e1..23539757d 100644 --- a/pkg/cgroups/cpu.go +++ b/pkg/cgroups/cpu.go @@ -40,7 +40,7 @@ func readAcctList(ctr *CgroupControl, name string) ([]uint64, error) { if s == "" { break } - v, err := strconv.ParseUint(s, 10, 0) + v, err := strconv.ParseUint(s, 10, 64) if err != nil { return nil, errors.Wrapf(err, "parsing %s", s) } @@ -80,14 +80,14 @@ func (c *cpuHandler) Stat(ctr *CgroupControl, m *Metrics) error { return err } if val, found := values["usage_usec"]; found { - usage.Total, err = strconv.ParseUint(cleanString(val[0]), 10, 0) + usage.Total, err = strconv.ParseUint(cleanString(val[0]), 10, 64) if err != nil { return err } usage.Kernel *= 1000 } if val, found := values["system_usec"]; found { - usage.Kernel, err = strconv.ParseUint(cleanString(val[0]), 10, 0) + usage.Kernel, err = strconv.ParseUint(cleanString(val[0]), 10, 64) if err != nil { return err } @@ -149,7 +149,7 @@ func GetSystemCPUUsage() (uint64, error) { } if val, found := values["usage_usec"]; found { - v, err := strconv.ParseUint(cleanString(val[0]), 10, 0) + v, err := strconv.ParseUint(cleanString(val[0]), 10, 64) if err != nil { return 0, err } diff --git a/pkg/domain/entities/engine_container.go b/pkg/domain/entities/engine_container.go index bcab617af..f695d32fd 100644 --- a/pkg/domain/entities/engine_container.go +++ b/pkg/domain/entities/engine_container.go @@ -88,7 +88,7 @@ type ContainerEngine interface { SecretRm(ctx context.Context, nameOrID []string, opts SecretRmOptions) ([]*SecretRmReport, error) Shutdown(ctx context.Context) SystemDf(ctx context.Context, options SystemDfOptions) (*SystemDfReport, error) - Unshare(ctx context.Context, args []string) error + Unshare(ctx context.Context, args []string, options SystemUnshareOptions) error Version(ctx context.Context) (*SystemVersionReport, error) VolumeCreate(ctx context.Context, opts VolumeCreateOptions) (*IDOrNameResponse, error) VolumeExists(ctx context.Context, namesOrID string) (*BoolReport, error) diff --git a/pkg/domain/entities/system.go b/pkg/domain/entities/system.go index 1a671d59e..31a6185dc 100644 --- a/pkg/domain/entities/system.go +++ b/pkg/domain/entities/system.go @@ -98,6 +98,11 @@ type SystemVersionReport struct { Server *define.Version `json:",omitempty"` } +// SystemUnshareOptions describes the options for the unshare command +type SystemUnshareOptions struct { + RootlessCNI bool +} + type ComponentVersion struct { types.Version } diff --git a/pkg/domain/filters/volumes.go b/pkg/domain/filters/volumes.go index 9b2fc5280..9a08adf82 100644 --- a/pkg/domain/filters/volumes.go +++ b/pkg/domain/filters/volumes.go @@ -75,7 +75,25 @@ func GenerateVolumeFilters(filters url.Values) ([]libpod.VolumeFilter, error) { return dangling }) default: - return nil, errors.Errorf("%q is in an invalid volume filter", filter) + return nil, errors.Errorf("%q is an invalid volume filter", filter) + } + } + } + return vf, nil +} + +func GeneratePruneVolumeFilters(filters url.Values) ([]libpod.VolumeFilter, error) { + var vf []libpod.VolumeFilter + for filter, v := range filters { + for _, val := range v { + switch filter { + case "label": + filter := val + vf = append(vf, func(v *libpod.Volume) bool { + return util.MatchLabelFilters([]string{filter}, v.Labels()) + }) + default: + return nil, errors.Errorf("%q is an invalid volume filter", filter) } } } diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go index 24261e5ed..6f8845f10 100644 --- a/pkg/domain/infra/abi/containers.go +++ b/pkg/domain/infra/abi/containers.go @@ -585,7 +585,7 @@ func (ic *ContainerEngine) ContainerAttach(ctx context.Context, nameOrID string, } // If the container is in a pod, also set to recursively start dependencies - err = terminal.StartAttachCtr(ctx, ctr, options.Stdout, options.Stderr, options.Stdin, options.DetachKeys, options.SigProxy, false, ctr.PodID() != "") + err = terminal.StartAttachCtr(ctx, ctr, options.Stdout, options.Stderr, options.Stdin, options.DetachKeys, options.SigProxy, false) if err != nil && errors.Cause(err) != define.ErrDetach { return errors.Wrapf(err, "error attaching to container %s", ctr.ID()) } @@ -708,7 +708,7 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri ctrRunning := ctrState == define.ContainerStateRunning if options.Attach { - err = terminal.StartAttachCtr(ctx, ctr, options.Stdout, options.Stderr, options.Stdin, options.DetachKeys, options.SigProxy, !ctrRunning, ctr.PodID() != "") + err = terminal.StartAttachCtr(ctx, ctr, options.Stdout, options.Stderr, options.Stdin, options.DetachKeys, options.SigProxy, !ctrRunning) if errors.Cause(err) == define.ErrDetach { // User manually detached // Exit cleanly immediately @@ -784,7 +784,7 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri RawInput: rawInput, ExitCode: 125, } - if err := ctr.Start(ctx, ctr.PodID() != ""); err != nil { + if err := ctr.Start(ctx, true); err != nil { // if lastError != nil { // fmt.Fprintln(os.Stderr, lastError) // } @@ -845,10 +845,6 @@ func (ic *ContainerEngine) ContainerRun(ctx context.Context, opts entities.Conta } } - var joinPod bool - if len(ctr.PodID()) > 0 { - joinPod = true - } report := entities.ContainerRunReport{Id: ctr.ID()} if logrus.GetLevel() == logrus.DebugLevel { @@ -859,7 +855,7 @@ func (ic *ContainerEngine) ContainerRun(ctx context.Context, opts entities.Conta } if opts.Detach { // if the container was created as part of a pod, also start its dependencies, if any. - if err := ctr.Start(ctx, joinPod); err != nil { + if err := ctr.Start(ctx, true); err != nil { // This means the command did not exist report.ExitCode = define.ExitCode(err) return &report, err @@ -869,7 +865,7 @@ func (ic *ContainerEngine) ContainerRun(ctx context.Context, opts entities.Conta } // if the container was created as part of a pod, also start its dependencies, if any. - if err := terminal.StartAttachCtr(ctx, ctr, opts.OutputStream, opts.ErrorStream, opts.InputStream, opts.DetachKeys, opts.SigProxy, true, joinPod); err != nil { + if err := terminal.StartAttachCtr(ctx, ctr, opts.OutputStream, opts.ErrorStream, opts.InputStream, opts.DetachKeys, opts.SigProxy, true); err != nil { // We've manually detached from the container // Do not perform cleanup, or wait for container exit code // Just exit immediately diff --git a/pkg/domain/infra/abi/system.go b/pkg/domain/infra/abi/system.go index a3e753384..f87f9e370 100644 --- a/pkg/domain/infra/abi/system.go +++ b/pkg/domain/infra/abi/system.go @@ -390,13 +390,25 @@ func unshareEnv(graphroot, runroot string) []string { fmt.Sprintf("CONTAINERS_RUNROOT=%s", runroot)) } -func (ic *ContainerEngine) Unshare(ctx context.Context, args []string) error { - cmd := exec.Command(args[0], args[1:]...) - cmd.Env = unshareEnv(ic.Libpod.StorageConfig().GraphRoot, ic.Libpod.StorageConfig().RunRoot) - cmd.Stdin = os.Stdin - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - return cmd.Run() +func (ic *ContainerEngine) Unshare(ctx context.Context, args []string, options entities.SystemUnshareOptions) error { + unshare := func() error { + cmd := exec.Command(args[0], args[1:]...) + cmd.Env = unshareEnv(ic.Libpod.StorageConfig().GraphRoot, ic.Libpod.StorageConfig().RunRoot) + cmd.Stdin = os.Stdin + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + return cmd.Run() + } + + if options.RootlessCNI { + rootlesscni, err := ic.Libpod.GetRootlessCNINetNs(true) + if err != nil { + return err + } + defer rootlesscni.Cleanup(ic.Libpod) + return rootlesscni.Do(unshare) + } + return unshare() } func (ic ContainerEngine) Version(ctx context.Context) (*entities.SystemVersionReport, error) { diff --git a/pkg/domain/infra/abi/terminal/terminal_linux.go b/pkg/domain/infra/abi/terminal/terminal_linux.go index 7a0c2907c..ab71f8f6f 100644 --- a/pkg/domain/infra/abi/terminal/terminal_linux.go +++ b/pkg/domain/infra/abi/terminal/terminal_linux.go @@ -39,7 +39,7 @@ func ExecAttachCtr(ctx context.Context, ctr *libpod.Container, execConfig *libpo // StartAttachCtr starts and (if required) attaches to a container // if you change the signature of this function from os.File to io.Writer, it will trigger a downstream // error. we may need to just lint disable this one. -func StartAttachCtr(ctx context.Context, ctr *libpod.Container, stdout, stderr, stdin *os.File, detachKeys string, sigProxy bool, startContainer bool, recursive bool) error { //nolint-interfacer +func StartAttachCtr(ctx context.Context, ctr *libpod.Container, stdout, stderr, stdin *os.File, detachKeys string, sigProxy bool, startContainer bool) error { //nolint-interfacer resize := make(chan define.TerminalSize) haveTerminal := terminal.IsTerminal(int(os.Stdin.Fd())) @@ -88,7 +88,7 @@ func StartAttachCtr(ctx context.Context, ctr *libpod.Container, stdout, stderr, return ctr.Attach(streams, detachKeys, resize) } - attachChan, err := ctr.StartAndAttach(ctx, streams, detachKeys, resize, recursive) + attachChan, err := ctr.StartAndAttach(ctx, streams, detachKeys, resize, true) if err != nil { return err } diff --git a/pkg/domain/infra/tunnel/containers.go b/pkg/domain/infra/tunnel/containers.go index a0f65f11f..4545d266b 100644 --- a/pkg/domain/infra/tunnel/containers.go +++ b/pkg/domain/infra/tunnel/containers.go @@ -629,7 +629,7 @@ func (ic *ContainerEngine) ContainerRun(ctx context.Context, opts entities.Conta if opts.Detach { // Detach and return early - err := containers.Start(ic.ClientCtx, con.ID, nil) + err := containers.Start(ic.ClientCtx, con.ID, new(containers.StartOptions).WithRecursive(true)) if err != nil { report.ExitCode = define.ExitCode(err) } diff --git a/pkg/domain/infra/tunnel/system.go b/pkg/domain/infra/tunnel/system.go index d2c5063c9..7400d3771 100644 --- a/pkg/domain/infra/tunnel/system.go +++ b/pkg/domain/infra/tunnel/system.go @@ -28,7 +28,7 @@ func (ic *ContainerEngine) SystemDf(ctx context.Context, options entities.System return system.DiskUsage(ic.ClientCtx, nil) } -func (ic *ContainerEngine) Unshare(ctx context.Context, args []string) error { +func (ic *ContainerEngine) Unshare(ctx context.Context, args []string, options entities.SystemUnshareOptions) error { return errors.New("unshare is not supported on remote clients") } diff --git a/pkg/specgen/generate/container_create.go b/pkg/specgen/generate/container_create.go index 1d724ffb0..ef9975021 100644 --- a/pkg/specgen/generate/container_create.go +++ b/pkg/specgen/generate/container_create.go @@ -364,6 +364,17 @@ func createContainerOptions(ctx context.Context, rt *libpod.Runtime, s *specgen. if len(s.Secrets) != 0 { options = append(options, libpod.WithSecrets(s.Secrets)) } + if len(s.DependencyContainers) > 0 { + deps := make([]*libpod.Container, 0, len(s.DependencyContainers)) + for _, ctr := range s.DependencyContainers { + depCtr, err := rt.LookupContainer(ctr) + if err != nil { + return nil, errors.Wrapf(err, "%q is not a valid container, cannot be used as a dependency", ctr) + } + deps = append(deps, depCtr) + } + options = append(options, libpod.WithDependencyCtrs(deps)) + } return options, nil } diff --git a/pkg/specgen/generate/namespaces.go b/pkg/specgen/generate/namespaces.go index 845dfdad7..b52e8d100 100644 --- a/pkg/specgen/generate/namespaces.go +++ b/pkg/specgen/generate/namespaces.go @@ -157,6 +157,16 @@ func namespaceOptions(ctx context.Context, s *specgen.SpecGenerator, rt *libpod. case specgen.KeepID: if rootless.IsRootless() { toReturn = append(toReturn, libpod.WithAddCurrentUserPasswdEntry()) + + // If user is not overridden, set user in the container + // to user running Podman. + if s.User == "" { + _, uid, gid, err := util.GetKeepIDMapping() + if err != nil { + return nil, err + } + toReturn = append(toReturn, libpod.WithUser(fmt.Sprintf("%d:%d", uid, gid))) + } } else { // keep-id as root doesn't need a user namespace s.UserNS.NSMode = specgen.Host diff --git a/pkg/specgen/specgen.go b/pkg/specgen/specgen.go index c10dc5ef5..28111f96d 100644 --- a/pkg/specgen/specgen.go +++ b/pkg/specgen/specgen.go @@ -160,10 +160,17 @@ type ContainerBasicConfig struct { // to 0, 1, 2) that will be passed to the executed process. The total FDs // passed will be 3 + PreserveFDs. // set tags as `json:"-"` for not supported remote + // Optional. PreserveFDs uint `json:"-"` // Timezone is the timezone inside the container. // Local means it has the same timezone as the host machine + // Optional. Timezone string `json:"timezone,omitempty"` + // DependencyContainers is an array of containers this container + // depends on. Dependency containers must be started before this + // container. Dependencies can be specified by name or full/partial ID. + // Optional. + DependencyContainers []string `json:"dependencyContainers,omitempty"` } // ContainerStorageConfig contains information on the storage configuration of a |