From 910d5c44fc9fb809bcaa84c717999848ae9c54a6 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 2 Aug 2022 09:49:29 +0200 Subject: [PATCH] api: add BuildCache.Parents for API >= v1.42 This field was added to replace the deprecated "Parent" field. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit e0db8207f3b84d030a71f41db70fc7fbf0535b9f) Signed-off-by: Sebastiaan van Stijn --- api/server/router/system/system_routes.go | 2 ++ api/swagger.yaml | 10 ++++++++++ api/types/types.go | 4 +++- builder/builder-next/builder.go | 1 + docs/api/version-history.md | 2 ++ 5 files changed, 18 insertions(+), 1 deletion(-) diff --git a/api/server/router/system/system_routes.go b/api/server/router/system/system_routes.go index 661cf06a3a..51b682b95d 100644 --- a/api/server/router/system/system_routes.go +++ b/api/server/router/system/system_routes.go @@ -174,6 +174,8 @@ func (s *systemRouter) getDiskUsage(ctx context.Context, w http.ResponseWriter, if versions.LessThan(version, "1.42") { for _, b := range buildCache { builderSize += b.Size + // Parents field was added in API 1.42 to replace the Parent field. + b.Parents = nil } } if versions.GreaterThanOrEqualTo(version, "1.42") { diff --git a/api/swagger.yaml b/api/swagger.yaml index 162bb6af97..b620cf7e4b 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -2263,6 +2263,14 @@ definitions: type: "string" x-nullable: true example: "" + Parents: + description: | + List of parent build cache record IDs. + type: "array" + items: + type: "string" + x-nullable: true + example: ["hw53o5aio51xtltp5xjp8v7fx"] Type: type: "string" description: | @@ -9046,6 +9054,7 @@ paths: BuildCache: - ID: "hw53o5aio51xtltp5xjp8v7fx" + Parents: [] Type: "regular" Description: "pulled from docker.io/library/debian@sha256:234cb88d3020898631af0ccbbcca9a66ae7306ecd30c9720690858c1b007d2a0" InUse: false @@ -9056,6 +9065,7 @@ paths: UsageCount: 26 - ID: "ndlpt0hhvkqcdfkputsk4cq9c" + Parents: ["ndlpt0hhvkqcdfkputsk4cq9c"] Type: "regular" Description: "mount / from exec /bin/sh -c echo 'Binary::apt::APT::Keep-Downloaded-Packages \"true\";' > /etc/apt/apt.conf.d/keep-cache" InUse: false diff --git a/api/types/types.go b/api/types/types.go index fa8b0ff5b3..036405299e 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -780,8 +780,10 @@ type BuildCache struct { ID string // Parent is the ID of the parent build cache record. // - // Deprecated: deprecated in API v1.42 and up, as it was deprecated in BuildKit. + // Deprecated: deprecated in API v1.42 and up, as it was deprecated in BuildKit; use Parents instead. Parent string `json:"Parent,omitempty"` + // Parents is the list of parent build cache record IDs. + Parents []string `json:" Parents,omitempty"` // Type is the cache record type. Type string // Description is a description of the build-step that produced the build cache. diff --git a/builder/builder-next/builder.go b/builder/builder-next/builder.go index 15fdb9fc40..a88e8b5751 100644 --- a/builder/builder-next/builder.go +++ b/builder/builder-next/builder.go @@ -130,6 +130,7 @@ func (b *Builder) DiskUsage(ctx context.Context) ([]*types.BuildCache, error) { items = append(items, &types.BuildCache{ ID: r.ID, Parent: r.Parent, //nolint:staticcheck // ignore SA1019 (Parent field is deprecated) + Parents: r.Parents, Type: r.RecordType, Description: r.Description, InUse: r.InUse, diff --git a/docs/api/version-history.md b/docs/api/version-history.md index 5701aa7a18..3b6938f0e2 100644 --- a/docs/api/version-history.md +++ b/docs/api/version-history.md @@ -83,6 +83,8 @@ keywords: "API, Docker, rcli, REST, documentation" with information about the created volume. * The `BuildCache.Parent` field, as returned by `GET /system/df` is deprecated and is now omitted. API versions before v1.42 continue to include this field. +* `GET /system/df` now includes a new `Parents` field, for "build-cache" records, + which contains a list of parent IDs for the build-cache record. * Volume information returned by `GET /volumes/{name}`, `GET /volumes` and `GET /system/df` can now contain a `ClusterVolume` if the volume is a cluster volume (requires the daemon to be a Swarm manager).