Skip to content

Commit eefe68a

Browse files
committed
api/types: move build cache types to api/types/build
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent c04dec1 commit eefe68a

10 files changed

Lines changed: 58 additions & 39 deletions

File tree

api/server/backend/build/backend.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/distribution/reference"
99
"github.com/docker/docker/api/types"
1010
"github.com/docker/docker/api/types/backend"
11+
"github.com/docker/docker/api/types/build"
1112
"github.com/docker/docker/api/types/events"
1213
"github.com/docker/docker/builder"
1314
buildkit "github.com/docker/docker/builder/builder-next"
@@ -97,7 +98,7 @@ func (b *Backend) Build(ctx context.Context, config backend.BuildConfig) (string
9798
}
9899

99100
// PruneCache removes all cached build sources
100-
func (b *Backend) PruneCache(ctx context.Context, opts types.BuildCachePruneOptions) (*types.BuildCachePruneReport, error) {
101+
func (b *Backend) PruneCache(ctx context.Context, opts build.CachePruneOptions) (*build.CachePruneReport, error) {
101102
buildCacheSize, cacheIDs, err := b.buildkit.Prune(ctx, opts)
102103
if err != nil {
103104
return nil, errors.Wrap(err, "failed to prune build cache")
@@ -107,7 +108,7 @@ func (b *Backend) PruneCache(ctx context.Context, opts types.BuildCachePruneOpti
107108
"reclaimed": strconv.FormatInt(buildCacheSize, 10),
108109
},
109110
})
110-
return &types.BuildCachePruneReport{SpaceReclaimed: uint64(buildCacheSize), CachesDeleted: cacheIDs}, nil
111+
return &build.CachePruneReport{SpaceReclaimed: uint64(buildCacheSize), CachesDeleted: cacheIDs}, nil
111112
}
112113

113114
// Cancel cancels the build by ID

api/server/router/build/backend.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package build // import "github.com/docker/docker/api/server/router/build"
33
import (
44
"context"
55

6-
"github.com/docker/docker/api/types"
76
"github.com/docker/docker/api/types/backend"
7+
"github.com/docker/docker/api/types/build"
88
)
99

1010
// Backend abstracts an image builder whose only purpose is to build an image referenced by an imageID.
@@ -13,8 +13,8 @@ type Backend interface {
1313
// TODO: make this return a reference instead of string
1414
Build(context.Context, backend.BuildConfig) (string, error)
1515

16-
// Prune build cache
17-
PruneCache(context.Context, types.BuildCachePruneOptions) (*types.BuildCachePruneReport, error)
16+
// PruneCache prunes the build cache.
17+
PruneCache(context.Context, build.CachePruneOptions) (*build.CachePruneReport, error)
1818
Cancel(context.Context, string) error
1919
}
2020

api/server/router/build/build_routes.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/docker/docker/api/server/httputils"
2020
"github.com/docker/docker/api/types"
2121
"github.com/docker/docker/api/types/backend"
22+
"github.com/docker/docker/api/types/build"
2223
"github.com/docker/docker/api/types/container"
2324
"github.com/docker/docker/api/types/filters"
2425
"github.com/docker/docker/api/types/registry"
@@ -179,7 +180,7 @@ func (br *buildRouter) postPrune(ctx context.Context, w http.ResponseWriter, r *
179180
return err
180181
}
181182

182-
opts := types.BuildCachePruneOptions{
183+
opts := build.CachePruneOptions{
183184
All: httputils.BoolValue(r, "all"),
184185
Filters: fltrs,
185186
}

api/types/build/cache.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package build
22

3-
import "time"
3+
import (
4+
"time"
5+
6+
"github.com/docker/docker/api/types/filters"
7+
)
48

59
// CacheRecord contains information about a build cache record.
610
type CacheRecord struct {
@@ -28,3 +32,21 @@ type CacheRecord struct {
2832
LastUsedAt *time.Time
2933
UsageCount int
3034
}
35+
36+
// CachePruneOptions hold parameters to prune the build cache.
37+
type CachePruneOptions struct {
38+
All bool
39+
ReservedSpace int64
40+
MaxUsedSpace int64
41+
MinFreeSpace int64
42+
Filters filters.Args
43+
44+
KeepStorage int64 // Deprecated: deprecated in API 1.48.
45+
}
46+
47+
// CachePruneReport contains the response for Engine API:
48+
// POST "/build/prune"
49+
type CachePruneReport struct {
50+
CachesDeleted []string
51+
SpaceReclaimed uint64
52+
}

api/types/types.go

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,10 @@ type DiskUsage struct {
9090
Images []*image.Summary
9191
Containers []*container.Summary
9292
Volumes []*volume.Volume
93-
BuildCache []*BuildCache
93+
BuildCache []*build.CacheRecord
9494
BuilderSize int64 `json:",omitempty"` // Deprecated: deprecated in API 1.38, and no longer used since API 1.40.
9595
}
9696

97-
// BuildCachePruneReport contains the response for Engine API:
98-
// POST "/build/prune"
99-
type BuildCachePruneReport struct {
100-
CachesDeleted []string
101-
SpaceReclaimed uint64
102-
}
103-
10497
// SecretCreateResponse contains the information returned to a client
10598
// on the creation of a new secret.
10699
type SecretCreateResponse struct {
@@ -138,19 +131,3 @@ type PushResult struct {
138131
type BuildResult struct {
139132
ID string
140133
}
141-
142-
// BuildCache contains information about a build cache record.
143-
//
144-
// Deprecated: deprecated in API 1.49. Use [build.CacheRecord] instead.
145-
type BuildCache = build.CacheRecord
146-
147-
// BuildCachePruneOptions hold parameters to prune the build cache
148-
type BuildCachePruneOptions struct {
149-
All bool
150-
ReservedSpace int64
151-
MaxUsedSpace int64
152-
MinFreeSpace int64
153-
Filters filters.Args
154-
155-
KeepStorage int64 // Deprecated: deprecated in API 1.48.
156-
}

api/types/types_deprecated.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package types
33
import (
44
"context"
55

6+
"github.com/docker/docker/api/types/build"
67
"github.com/docker/docker/api/types/common"
78
"github.com/docker/docker/api/types/container"
89
"github.com/docker/docker/api/types/image"
@@ -113,3 +114,19 @@ type ImageInspect = image.InspectResponse
113114
//
114115
// Deprecated: moved to [github.com/docker/docker/api/types/registry.RequestAuthConfig].
115116
type RequestPrivilegeFunc func(context.Context) (string, error)
117+
118+
// BuildCache contains information about a build cache record.
119+
//
120+
// Deprecated: deprecated in API 1.49. Use [build.CacheRecord] instead.
121+
type BuildCache = build.CacheRecord
122+
123+
// BuildCachePruneOptions hold parameters to prune the build cache
124+
//
125+
// Deprecated: use [build.CachePruneOptions].
126+
type BuildCachePruneOptions = build.CachePruneOptions
127+
128+
// BuildCachePruneReport contains the response for Engine API:
129+
// POST "/build/prune"
130+
//
131+
// Deprecated: use [build.CachePruneReport].
132+
type BuildCachePruneReport = build.CachePruneReport

builder/builder-next/builder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func (b *Builder) DiskUsage(ctx context.Context) ([]*build.CacheRecord, error) {
187187
}
188188

189189
// Prune clears all reclaimable build cache.
190-
func (b *Builder) Prune(ctx context.Context, opts types.BuildCachePruneOptions) (int64, []string, error) {
190+
func (b *Builder) Prune(ctx context.Context, opts build.CachePruneOptions) (int64, []string, error) {
191191
ch := make(chan *controlapi.UsageRecord)
192192

193193
eg, ctx := errgroup.WithContext(ctx)
@@ -641,7 +641,7 @@ func toBuildkitUlimits(inp []*container.Ulimit) (string, error) {
641641
return strings.Join(ulimits, ","), nil
642642
}
643643

644-
func toBuildkitPruneInfo(opts types.BuildCachePruneOptions) (client.PruneInfo, error) {
644+
func toBuildkitPruneInfo(opts build.CachePruneOptions) (client.PruneInfo, error) {
645645
var until time.Duration
646646
untilValues := opts.Filters.Get("until") // canonical
647647
unusedForValues := opts.Filters.Get("unused-for") // deprecated synonym for "until" filter

builder/builder-next/controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/containerd/containerd/v2/plugins/content/local"
1717
"github.com/containerd/log"
1818
"github.com/containerd/platforms"
19-
"github.com/docker/docker/api/types"
19+
"github.com/docker/docker/api/types/build"
2020
"github.com/docker/docker/api/types/filters"
2121
"github.com/docker/docker/builder/builder-next/adapters/containerimage"
2222
"github.com/docker/docker/builder/builder-next/adapters/localinlinecache"
@@ -467,7 +467,7 @@ func getGCPolicy(conf config.BuilderConfig, root string) ([]client.PruneInfo, er
467467
return nil, err
468468
}
469469

470-
gcPolicy[i], err = toBuildkitPruneInfo(types.BuildCachePruneOptions{
470+
gcPolicy[i], err = toBuildkitPruneInfo(build.CachePruneOptions{
471471
All: p.All,
472472
ReservedSpace: reservedSpace,
473473
MaxUsedSpace: maxUsedSpace,

client/build_prune.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import (
66
"net/url"
77
"strconv"
88

9-
"github.com/docker/docker/api/types"
9+
"github.com/docker/docker/api/types/build"
1010
"github.com/docker/docker/api/types/filters"
1111
"github.com/pkg/errors"
1212
)
1313

1414
// BuildCachePrune requests the daemon to delete unused cache data
15-
func (cli *Client) BuildCachePrune(ctx context.Context, opts types.BuildCachePruneOptions) (*types.BuildCachePruneReport, error) {
15+
func (cli *Client) BuildCachePrune(ctx context.Context, opts build.CachePruneOptions) (*build.CachePruneReport, error) {
1616
if err := cli.NewVersionError(ctx, "1.31", "build prune"); err != nil {
1717
return nil, err
1818
}
@@ -47,7 +47,7 @@ func (cli *Client) BuildCachePrune(ctx context.Context, opts types.BuildCachePru
4747
return nil, err
4848
}
4949

50-
report := types.BuildCachePruneReport{}
50+
report := build.CachePruneReport{}
5151
if err := json.NewDecoder(resp.Body).Decode(&report); err != nil {
5252
return nil, errors.Wrap(err, "error retrieving disk usage")
5353
}

client/client_interfaces.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88

99
"github.com/docker/docker/api/types"
10+
"github.com/docker/docker/api/types/build"
1011
"github.com/docker/docker/api/types/container"
1112
"github.com/docker/docker/api/types/events"
1213
"github.com/docker/docker/api/types/filters"
@@ -110,7 +111,7 @@ type DistributionAPIClient interface {
110111
// ImageAPIClient defines API client methods for the images
111112
type ImageAPIClient interface {
112113
ImageBuild(ctx context.Context, context io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error)
113-
BuildCachePrune(ctx context.Context, opts types.BuildCachePruneOptions) (*types.BuildCachePruneReport, error)
114+
BuildCachePrune(ctx context.Context, opts build.CachePruneOptions) (*build.CachePruneReport, error)
114115
BuildCancel(ctx context.Context, id string) error
115116
ImageCreate(ctx context.Context, parentReference string, options image.CreateOptions) (io.ReadCloser, error)
116117
ImageImport(ctx context.Context, source image.ImportSource, ref string, options image.ImportOptions) (io.ReadCloser, error)

0 commit comments

Comments
 (0)