mirror of
https://github.com/containers/podman.git
synced 2025-06-25 03:52:15 +08:00
Merge pull request #17325 from flouthoc/clean-cache-api
system-reset: use `CleanCacheMount` to clear build cache
This commit is contained in:
@ -9,6 +9,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/containers/buildah/pkg/parse"
|
||||||
"github.com/containers/common/pkg/completion"
|
"github.com/containers/common/pkg/completion"
|
||||||
"github.com/containers/podman/v4/cmd/podman/registry"
|
"github.com/containers/podman/v4/cmd/podman/registry"
|
||||||
"github.com/containers/podman/v4/cmd/podman/validate"
|
"github.com/containers/podman/v4/cmd/podman/validate"
|
||||||
@ -88,6 +89,11 @@ func reset(cmd *cobra.Command, args []string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
|
// Clean build cache if any
|
||||||
|
err = parse.CleanCacheMount()
|
||||||
|
if err != nil {
|
||||||
|
logrus.Error(err)
|
||||||
|
}
|
||||||
// Shutdown all running engines, `reset` will hijack repository
|
// Shutdown all running engines, `reset` will hijack repository
|
||||||
registry.ContainerEngine().Shutdown(registry.Context())
|
registry.ContainerEngine().Shutdown(registry.Context())
|
||||||
registry.ImageEngine().Shutdown(registry.Context())
|
registry.ImageEngine().Shutdown(registry.Context())
|
||||||
|
4
go.mod
4
go.mod
@ -11,7 +11,7 @@ require (
|
|||||||
github.com/container-orchestrated-devices/container-device-interface v0.5.3
|
github.com/container-orchestrated-devices/container-device-interface v0.5.3
|
||||||
github.com/containernetworking/cni v1.1.2
|
github.com/containernetworking/cni v1.1.2
|
||||||
github.com/containernetworking/plugins v1.2.0
|
github.com/containernetworking/plugins v1.2.0
|
||||||
github.com/containers/buildah v1.29.0
|
github.com/containers/buildah v1.29.1-0.20230201192322-e56eb25575c7
|
||||||
github.com/containers/common v0.51.0
|
github.com/containers/common v0.51.0
|
||||||
github.com/containers/conmon v2.0.20+incompatible
|
github.com/containers/conmon v2.0.20+incompatible
|
||||||
github.com/containers/image/v5 v5.24.0
|
github.com/containers/image/v5 v5.24.0
|
||||||
@ -79,7 +79,7 @@ require (
|
|||||||
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
|
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
|
||||||
github.com/chzyer/readline v1.5.1 // indirect
|
github.com/chzyer/readline v1.5.1 // indirect
|
||||||
github.com/containerd/cgroups v1.0.4 // indirect
|
github.com/containerd/cgroups v1.0.4 // indirect
|
||||||
github.com/containerd/containerd v1.6.15 // indirect
|
github.com/containerd/containerd v1.6.16 // indirect
|
||||||
github.com/containerd/stargz-snapshotter/estargz v0.14.1 // indirect
|
github.com/containerd/stargz-snapshotter/estargz v0.14.1 // indirect
|
||||||
github.com/containers/libtrust v0.0.0-20230121012942-c1716e8a8d01 // indirect
|
github.com/containers/libtrust v0.0.0-20230121012942-c1716e8a8d01 // indirect
|
||||||
github.com/coreos/go-oidc/v3 v3.5.0 // indirect
|
github.com/coreos/go-oidc/v3 v3.5.0 // indirect
|
||||||
|
8
go.sum
8
go.sum
@ -202,8 +202,8 @@ github.com/containerd/containerd v1.5.0-rc.0/go.mod h1:V/IXoMqNGgBlabz3tHD2TWDoT
|
|||||||
github.com/containerd/containerd v1.5.1/go.mod h1:0DOxVqwDy2iZvrZp2JUx/E+hS0UNTVn7dJnIOwtYR4g=
|
github.com/containerd/containerd v1.5.1/go.mod h1:0DOxVqwDy2iZvrZp2JUx/E+hS0UNTVn7dJnIOwtYR4g=
|
||||||
github.com/containerd/containerd v1.5.7/go.mod h1:gyvv6+ugqY25TiXxcZC3L5yOeYgEw0QMhscqVp1AR9c=
|
github.com/containerd/containerd v1.5.7/go.mod h1:gyvv6+ugqY25TiXxcZC3L5yOeYgEw0QMhscqVp1AR9c=
|
||||||
github.com/containerd/containerd v1.5.9/go.mod h1:fvQqCfadDGga5HZyn3j4+dx56qj2I9YwBrlSdalvJYQ=
|
github.com/containerd/containerd v1.5.9/go.mod h1:fvQqCfadDGga5HZyn3j4+dx56qj2I9YwBrlSdalvJYQ=
|
||||||
github.com/containerd/containerd v1.6.15 h1:4wWexxzLNHNE46aIETc6ge4TofO550v+BlLoANrbses=
|
github.com/containerd/containerd v1.6.16 h1:0H5xH6ABsN7XTrxIAKxFpBkFCBtrZ/OSORhCpUnHjrc=
|
||||||
github.com/containerd/containerd v1.6.15/go.mod h1:U2NnBPIhzJDm59xF7xB2MMHnKtggpZ+phKg8o2TKj2c=
|
github.com/containerd/containerd v1.6.16/go.mod h1:1RdCUu95+gc2v9t3IL+zIlpClSmew7/0YS8O5eQZrOw=
|
||||||
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
|
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
|
||||||
github.com/containerd/continuity v0.0.0-20190815185530-f2a389ac0a02/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
|
github.com/containerd/continuity v0.0.0-20190815185530-f2a389ac0a02/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
|
||||||
github.com/containerd/continuity v0.0.0-20191127005431-f65d91d395eb/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
|
github.com/containerd/continuity v0.0.0-20191127005431-f65d91d395eb/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
|
||||||
@ -259,8 +259,8 @@ github.com/containernetworking/plugins v0.8.6/go.mod h1:qnw5mN19D8fIwkqW7oHHYDHV
|
|||||||
github.com/containernetworking/plugins v0.9.1/go.mod h1:xP/idU2ldlzN6m4p5LmGiwRDjeJr6FLK6vuiUwoH7P8=
|
github.com/containernetworking/plugins v0.9.1/go.mod h1:xP/idU2ldlzN6m4p5LmGiwRDjeJr6FLK6vuiUwoH7P8=
|
||||||
github.com/containernetworking/plugins v1.2.0 h1:SWgg3dQG1yzUo4d9iD8cwSVh1VqI+bP7mkPDoSfP9VU=
|
github.com/containernetworking/plugins v1.2.0 h1:SWgg3dQG1yzUo4d9iD8cwSVh1VqI+bP7mkPDoSfP9VU=
|
||||||
github.com/containernetworking/plugins v1.2.0/go.mod h1:/VjX4uHecW5vVimFa1wkG4s+r/s9qIfPdqlLF4TW8c4=
|
github.com/containernetworking/plugins v1.2.0/go.mod h1:/VjX4uHecW5vVimFa1wkG4s+r/s9qIfPdqlLF4TW8c4=
|
||||||
github.com/containers/buildah v1.29.0 h1:rA3S2SXJffrJjvY2kyxOsAaIseDY6Ib77FsD7n88Mj4=
|
github.com/containers/buildah v1.29.1-0.20230201192322-e56eb25575c7 h1:GmQhTfsGuYgGfuYWEF4Ed+rEvlSWRmxisLBL2J8rCb4=
|
||||||
github.com/containers/buildah v1.29.0/go.mod h1:mah+CGmpOjkBJJ5rhOP0M2ETnODhiuhtnXusfh0hc6Q=
|
github.com/containers/buildah v1.29.1-0.20230201192322-e56eb25575c7/go.mod h1:sFvOi+WMtMtrkxx1Dn8EhF5/ddXNyC1f5LAj4ZGzjAs=
|
||||||
github.com/containers/common v0.51.0 h1:Ax4YHNTG8cEPHZJcMYRoP7sfBgOISceeyOvmZzmSucg=
|
github.com/containers/common v0.51.0 h1:Ax4YHNTG8cEPHZJcMYRoP7sfBgOISceeyOvmZzmSucg=
|
||||||
github.com/containers/common v0.51.0/go.mod h1:3W2WIdalgQfrsX/T5tjX+6CxgT3ThJVN2G9sNuFjuCM=
|
github.com/containers/common v0.51.0/go.mod h1:3W2WIdalgQfrsX/T5tjX+6CxgT3ThJVN2G9sNuFjuCM=
|
||||||
github.com/containers/conmon v2.0.20+incompatible h1:YbCVSFSCqFjjVwHTPINGdMX1F6JXHGTUje2ZYobNrkg=
|
github.com/containers/conmon v2.0.20+incompatible h1:YbCVSFSCqFjjVwHTPINGdMX1F6JXHGTUje2ZYobNrkg=
|
||||||
|
4
test/e2e/build/cache/Dockerfilecacheread
vendored
Normal file
4
test/e2e/build/cache/Dockerfilecacheread
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
FROM alpine
|
||||||
|
RUN mkdir /test
|
||||||
|
# use option z if selinux is enabled
|
||||||
|
RUN --mount=type=cache,target=/test,z cat /test/world
|
4
test/e2e/build/cache/Dockerfilecachewrite
vendored
Normal file
4
test/e2e/build/cache/Dockerfilecachewrite
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
FROM alpine
|
||||||
|
RUN mkdir /test
|
||||||
|
# use option z if selinux is enabled
|
||||||
|
RUN --mount=type=cache,target=/test,z echo hello > /test/world
|
@ -874,4 +874,20 @@ RUN ls /dev/test1`, ALPINE)
|
|||||||
build.WaitWithDefaultTimeout()
|
build.WaitWithDefaultTimeout()
|
||||||
Expect(build).To(Exit(0))
|
Expect(build).To(Exit(0))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman system reset must clean host shared cache", func() {
|
||||||
|
SkipIfRemote("podman-remote does not have system reset -f")
|
||||||
|
podmanTest.AddImageToRWStore(ALPINE)
|
||||||
|
session := podmanTest.Podman([]string{"build", "--pull-never", "--file", "build/cache/Dockerfilecachewrite", "build/cache/"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session).Should(Exit(0))
|
||||||
|
|
||||||
|
session = podmanTest.Podman([]string{"system", "reset", "-f"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session).Should(Exit(0))
|
||||||
|
|
||||||
|
session = podmanTest.Podman([]string{"build", "--pull-never", "--file", "build/cache/Dockerfilecacheread", "build/cache/"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session).Should(Exit(1))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
2
vendor/github.com/containers/buildah/define/types.go
generated
vendored
2
vendor/github.com/containers/buildah/define/types.go
generated
vendored
@ -30,7 +30,7 @@ const (
|
|||||||
Package = "buildah"
|
Package = "buildah"
|
||||||
// Version for the Package. Bump version in contrib/rpm/buildah.spec
|
// Version for the Package. Bump version in contrib/rpm/buildah.spec
|
||||||
// too.
|
// too.
|
||||||
Version = "1.29.0"
|
Version = "1.30.0-dev"
|
||||||
|
|
||||||
// DefaultRuntime if containers.conf fails.
|
// DefaultRuntime if containers.conf fails.
|
||||||
DefaultRuntime = "runc"
|
DefaultRuntime = "runc"
|
||||||
|
7
vendor/github.com/containers/buildah/pkg/parse/parse.go
generated
vendored
7
vendor/github.com/containers/buildah/pkg/parse/parse.go
generated
vendored
@ -16,7 +16,6 @@ import (
|
|||||||
|
|
||||||
"github.com/containerd/containerd/platforms"
|
"github.com/containerd/containerd/platforms"
|
||||||
"github.com/containers/buildah/define"
|
"github.com/containers/buildah/define"
|
||||||
securejoin "github.com/cyphar/filepath-securejoin"
|
|
||||||
internalParse "github.com/containers/buildah/internal/parse"
|
internalParse "github.com/containers/buildah/internal/parse"
|
||||||
"github.com/containers/buildah/pkg/sshagent"
|
"github.com/containers/buildah/pkg/sshagent"
|
||||||
"github.com/containers/common/pkg/config"
|
"github.com/containers/common/pkg/config"
|
||||||
@ -26,6 +25,7 @@ import (
|
|||||||
"github.com/containers/storage/pkg/idtools"
|
"github.com/containers/storage/pkg/idtools"
|
||||||
"github.com/containers/storage/pkg/unshare"
|
"github.com/containers/storage/pkg/unshare"
|
||||||
storageTypes "github.com/containers/storage/types"
|
storageTypes "github.com/containers/storage/types"
|
||||||
|
securejoin "github.com/cyphar/filepath-securejoin"
|
||||||
units "github.com/docker/go-units"
|
units "github.com/docker/go-units"
|
||||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/openshift/imagebuilder"
|
"github.com/openshift/imagebuilder"
|
||||||
@ -67,6 +67,11 @@ func RepoNamesToNamedReferences(destList []string) ([]reference.Named, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CleanCacheMount gets the cache parent created by `--mount=type=cache` and removes it.
|
||||||
|
func CleanCacheMount() error {
|
||||||
|
return internalParse.CleanCacheMount()
|
||||||
|
}
|
||||||
|
|
||||||
// CommonBuildOptions parses the build options from the bud cli
|
// CommonBuildOptions parses the build options from the bud cli
|
||||||
func CommonBuildOptions(c *cobra.Command) (*define.CommonBuildOptions, error) {
|
func CommonBuildOptions(c *cobra.Command) (*define.CommonBuildOptions, error) {
|
||||||
return CommonBuildOptionsFromFlagSet(c.Flags(), c.Flag)
|
return CommonBuildOptionsFromFlagSet(c.Flags(), c.Flag)
|
||||||
|
4
vendor/modules.txt
vendored
4
vendor/modules.txt
vendored
@ -72,7 +72,7 @@ github.com/container-orchestrated-devices/container-device-interface/specs-go
|
|||||||
# github.com/containerd/cgroups v1.0.4
|
# github.com/containerd/cgroups v1.0.4
|
||||||
## explicit; go 1.17
|
## explicit; go 1.17
|
||||||
github.com/containerd/cgroups/stats/v1
|
github.com/containerd/cgroups/stats/v1
|
||||||
# github.com/containerd/containerd v1.6.15
|
# github.com/containerd/containerd v1.6.16
|
||||||
## explicit; go 1.17
|
## explicit; go 1.17
|
||||||
github.com/containerd/containerd/errdefs
|
github.com/containerd/containerd/errdefs
|
||||||
github.com/containerd/containerd/log
|
github.com/containerd/containerd/log
|
||||||
@ -98,7 +98,7 @@ github.com/containernetworking/cni/pkg/version
|
|||||||
# github.com/containernetworking/plugins v1.2.0
|
# github.com/containernetworking/plugins v1.2.0
|
||||||
## explicit; go 1.17
|
## explicit; go 1.17
|
||||||
github.com/containernetworking/plugins/pkg/ns
|
github.com/containernetworking/plugins/pkg/ns
|
||||||
# github.com/containers/buildah v1.29.0
|
# github.com/containers/buildah v1.29.1-0.20230201192322-e56eb25575c7
|
||||||
## explicit; go 1.17
|
## explicit; go 1.17
|
||||||
github.com/containers/buildah
|
github.com/containers/buildah
|
||||||
github.com/containers/buildah/bind
|
github.com/containers/buildah/bind
|
||||||
|
Reference in New Issue
Block a user