Skip to content

Commit 7963926

Browse files
authored
fix(host-cleanup): don't prune backend build cache
Signed-off-by: Alexandr Zaytsev <alexandr.zaytsev@flant.com>
1 parent 26ccd15 commit 7963926

11 files changed

+16
-120
lines changed

Diff for: pkg/container_backend/buildah_backend.go

-4
Original file line numberDiff line numberDiff line change
@@ -1101,10 +1101,6 @@ func (backend *BuildahBackend) PostManifest(ctx context.Context, ref string, opt
11011101

11021102
func (backend *BuildahBackend) ClaimTargetPlatforms(ctx context.Context, targetPlatforms []string) {}
11031103

1104-
func (backend *BuildahBackend) PruneBuildCache(_ context.Context, _ prune.Options) (prune.Report, error) {
1105-
return prune.Report{}, ErrUnsupportedFeature
1106-
}
1107-
11081104
func (backend *BuildahBackend) PruneContainers(_ context.Context, _ prune.Options) (prune.Report, error) {
11091105
return prune.Report{}, ErrUnsupportedFeature
11101106
}

Diff for: pkg/container_backend/docker_server_backend.go

-8
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,6 @@ func (backend *DockerServerBackend) PostManifest(ctx context.Context, ref string
391391
return docker.CreateImage(ctx, ref, docker.CreateImageOptions{Labels: opts.Labels})
392392
}
393393

394-
func (backend *DockerServerBackend) PruneBuildCache(ctx context.Context, options prune.Options) (prune.Report, error) {
395-
report, err := docker.BuildCachePrune(ctx, docker.BuildCachePruneOptions(options))
396-
if err != nil {
397-
return prune.Report{}, fmt.Errorf("unable to prune docker build cache: %w", err)
398-
}
399-
return prune.Report(report), nil
400-
}
401-
402394
func (backend *DockerServerBackend) PruneContainers(ctx context.Context, options prune.Options) (prune.Report, error) {
403395
report, err := docker.ContainersPrune(ctx, docker.ContainersPruneOptions(options))
404396
if err != nil {

Diff for: pkg/container_backend/interface.go

-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ type ContainerBackend interface {
100100

101101
ClaimTargetPlatforms(ctx context.Context, targetPlatforms []string)
102102

103-
// PruneBuildCache removes all unused cache
104-
PruneBuildCache(ctx context.Context, options prune.Options) (prune.Report, error)
105103
// PruneContainers removes all stopped containers
106104
PruneContainers(ctx context.Context, options prune.Options) (prune.Report, error)
107105
// PruneImages removes all dangling images

Diff for: pkg/container_backend/perf_check_container_backend.go

-8
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,6 @@ func (runtime *PerfCheckContainerBackend) ClaimTargetPlatforms(ctx context.Conte
198198
Do(func() { runtime.ContainerBackend.ClaimTargetPlatforms(ctx, targetPlatforms) })
199199
}
200200

201-
func (runtime *PerfCheckContainerBackend) PruneBuildCache(ctx context.Context, options prune.Options) (report prune.Report, err error) {
202-
logboek.Context(ctx).Default().LogProcess("ContainerBackend.PruneBuildCache %v", options).
203-
Do(func() {
204-
report, err = runtime.ContainerBackend.PruneBuildCache(ctx, options)
205-
})
206-
return
207-
}
208-
209201
func (runtime *PerfCheckContainerBackend) PruneContainers(ctx context.Context, options prune.Options) (report prune.Report, err error) {
210202
logboek.Context(ctx).Default().LogProcess("ContainerBackend.PruneContainers %v", options).
211203
Do(func() {

Diff for: pkg/docker/build_cache.go

-25
This file was deleted.

Diff for: pkg/docker/container.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"github.com/docker/docker/api/types/filters"
1010
"github.com/docker/docker/client"
1111
"golang.org/x/net/context"
12+
13+
"github.com/werf/werf/v2/pkg/container_backend/prune"
1214
)
1315

1416
func Containers(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error) {
@@ -47,8 +49,8 @@ func ContainerRemove(ctx context.Context, ref string, options types.ContainerRem
4749
}
4850

4951
type (
50-
ContainersPruneOptions BuildCachePruneOptions
51-
ContainersPruneReport BuildCachePruneReport
52+
ContainersPruneOptions prune.Options
53+
ContainersPruneReport prune.Report
5254
)
5355

5456
func ContainersPrune(ctx context.Context, _ ContainersPruneOptions) (ContainersPruneReport, error) {

Diff for: pkg/docker/image.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"golang.org/x/net/context"
2222

2323
"github.com/werf/logboek"
24+
"github.com/werf/werf/v2/pkg/container_backend/prune"
2425
)
2526

2627
type CreateImageOptions struct {
@@ -69,8 +70,8 @@ func ImageInspect(ctx context.Context, ref string) (*types.ImageInspect, error)
6970
}
7071

7172
type (
72-
ImagesPruneOptions BuildCachePruneOptions
73-
ImagesPruneReport BuildCachePruneReport
73+
ImagesPruneOptions prune.Options
74+
ImagesPruneReport prune.Report
7475
)
7576

7677
func ImagesPrune(ctx context.Context, _ ImagesPruneOptions) (ImagesPruneReport, error) {

Diff for: pkg/docker/volume.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ package docker
33
import (
44
"github.com/docker/docker/api/types/filters"
55
"golang.org/x/net/context"
6+
7+
"github.com/werf/werf/v2/pkg/container_backend/prune"
68
)
79

810
func VolumeRm(ctx context.Context, volumeName string, force bool) error {
911
return apiCli(ctx).VolumeRemove(ctx, volumeName, force)
1012
}
1113

1214
type (
13-
VolumesPruneOptions BuildCachePruneOptions
14-
VolumesPruneReport BuildCachePruneReport
15+
VolumesPruneOptions prune.Options
16+
VolumesPruneReport prune.Report
1517
)
1618

1719
func VolumesPrune(ctx context.Context, _ VolumesPruneOptions) (VolumesPruneReport, error) {

Diff for: pkg/host_cleaning/local_backend_cleaner.go

+5-35
Original file line numberDiff line numberDiff line change
@@ -342,25 +342,7 @@ func (cleaner *LocalBackendCleaner) RunGC(ctx context.Context, options RunGCOpti
342342

343343
vuBefore := vu
344344

345-
// Step 1. Prune unused build cache
346-
err = logboek.Context(ctx).LogBlock("Prune unused build cache").DoError(func() error {
347-
reportBuildCache, err := cleaner.pruneBuildCache(ctx, options)
348-
if handleError(ctx, err) != nil {
349-
return err
350-
}
351-
352-
vu.UsedBytes -= reportBuildCache.SpaceReclaimed
353-
354-
logboek.Context(ctx).LogF("Freed space: %s\n", utils.RedF("%s", humanize.Bytes(reportBuildCache.SpaceReclaimed)))
355-
logDeletedItems(ctx, reportBuildCache.ItemsDeleted)
356-
357-
return nil
358-
})
359-
if err != nil {
360-
return fmt.Errorf("unable to prune unused build cache: %w", err)
361-
}
362-
363-
// Step 2. Prune stopped containers
345+
// Step 1. Prune stopped containers
364346
err = logboek.Context(ctx).LogBlock("Prune stopped containers").DoError(func() error {
365347
reportContainers, err := cleaner.pruneContainers(ctx, options)
366348
if handleError(ctx, err) != nil {
@@ -378,7 +360,7 @@ func (cleaner *LocalBackendCleaner) RunGC(ctx context.Context, options RunGCOpti
378360
return fmt.Errorf("unable to prune stopped containers: %w", err)
379361
}
380362

381-
// Step 3. Prune unused anonymous volumes
363+
// Step 2. Prune unused anonymous volumes
382364
err = logboek.Context(ctx).LogBlock("Prune unused anonymous volumes").DoError(func() error {
383365
reportVolumes, err := cleaner.pruneVolumes(ctx, options)
384366
if handleError(ctx, err) != nil {
@@ -396,7 +378,7 @@ func (cleaner *LocalBackendCleaner) RunGC(ctx context.Context, options RunGCOpti
396378
return fmt.Errorf("unable to prune unused anonymous volumes: %w", err)
397379
}
398380

399-
// Step 4. Prune dangling images
381+
// Step 3. Prune dangling images
400382
err = logboek.Context(ctx).LogBlock("Prune dangling images").DoError(func() error {
401383
reportImages, err := cleaner.pruneImages(ctx, options)
402384
if handleError(ctx, err) != nil {
@@ -425,7 +407,7 @@ func (cleaner *LocalBackendCleaner) RunGC(ctx context.Context, options RunGCOpti
425407
return nil
426408
}
427409

428-
// Step 5. Remove werf containers
410+
// Step 4. Remove werf containers
429411
err = logboek.Context(ctx).LogBlock("Cleanup werf containers").DoError(func() error {
430412
reportWerfContainers, err := cleaner.safeCleanupWerfContainers(ctx, options, vu)
431413
if err != nil {
@@ -443,7 +425,7 @@ func (cleaner *LocalBackendCleaner) RunGC(ctx context.Context, options RunGCOpti
443425
return fmt.Errorf("unable to remove werf containers: %w", err)
444426
}
445427

446-
// Step 6. Remove werf images
428+
// Step 5. Remove werf images
447429
err = logboek.Context(ctx).LogBlock("Cleanup werf images").DoError(func() error {
448430
reportWerfImages, err := cleaner.safeCleanupWerfImages(ctx, options, vu, targetVolumeUsagePercentage)
449431
if err != nil {
@@ -482,18 +464,6 @@ func (cleaner *LocalBackendCleaner) RunGC(ctx context.Context, options RunGCOpti
482464
return nil
483465
}
484466

485-
// pruneBuildCache removes all unused cache
486-
func (cleaner *LocalBackendCleaner) pruneBuildCache(ctx context.Context, options RunGCOptions) (cleanupReport, error) {
487-
if options.DryRun {
488-
// NOTE: Buildah does not give us a way to precalculate pruned size.
489-
// NOTE: Docker does not give us a way to precalculate pruned size.
490-
return newCleanupReport(), errOptionDryRunNotSupported
491-
}
492-
493-
report, err := cleaner.backend.PruneBuildCache(ctx, prune.Options{})
494-
return mapPruneReportToCleanupReport(report), err
495-
}
496-
497467
// pruneContainers removes all stopped containers
498468
func (cleaner *LocalBackendCleaner) pruneContainers(ctx context.Context, options RunGCOptions) (cleanupReport, error) {
499469
if options.DryRun {

Diff for: pkg/host_cleaning/local_backend_cleaner_test.go

-17
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,6 @@ var _ = Describe("LocalBackendCleaner", func() {
9696
})
9797
})
9898

99-
Describe("pruneBuildCache", func() {
100-
It("should return err if opts.DryRun=true", func() {
101-
_, err := cleaner.pruneBuildCache(ctx, RunGCOptions{
102-
DryRun: true,
103-
})
104-
Expect(errors.Is(err, errOptionDryRunNotSupported)).To(BeTrue())
105-
})
106-
It("should call backend.PruneBuildCache() if opts.DryRun=false", func() {
107-
backend.EXPECT().PruneBuildCache(ctx, prune.Options{}).Return(prune.Report{}, nil)
108-
109-
report, err := cleaner.pruneBuildCache(ctx, RunGCOptions{})
110-
Expect(err).To(Succeed())
111-
Expect(report).To(Equal(newCleanupReport()))
112-
})
113-
})
114-
11599
Describe("pruneContainers", func() {
116100
It("should return err if opts.DryRun=true", func() {
117101
_, err := cleaner.pruneContainers(ctx, RunGCOptions{
@@ -341,7 +325,6 @@ var _ = Describe("LocalBackendCleaner", func() {
341325
// keep orders of backend calls
342326
gomock.InOrder(
343327
// use backend native GC pruning
344-
backend.EXPECT().PruneBuildCache(ctx, prune.Options{}).Return(prune.Report{}, nil),
345328
backend.EXPECT().PruneContainers(ctx, prune.Options{}).Return(prune.Report{}, nil),
346329
backend.EXPECT().PruneVolumes(ctx, prune.Options{}).Return(prune.Report{}, nil),
347330
backend.EXPECT().PruneImages(ctx, prune.Options{}).Return(prune.Report{}, nil),

Diff for: test/mock/container_backend.go

-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)