summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorAditya R <arajan@redhat.com>2022-08-09 09:10:55 +0530
committerAditya R <arajan@redhat.com>2022-08-09 09:10:58 +0530
commit59cb410fe29d18d2e908762d80f3caf1cd5a41a4 (patch)
treef14728908cc5638ff5b7d50d838a3c38b496778d /pkg
parent7bd886480066ceb097ab5ab101738d6b4fca718f (diff)
downloadpodman-59cb410fe29d18d2e908762d80f3caf1cd5a41a4.tar.gz
podman-59cb410fe29d18d2e908762d80f3caf1cd5a41a4.tar.bz2
podman-59cb410fe29d18d2e908762d80f3caf1cd5a41a4.zip
build: implement --cache-to,--cache-from and --cache-ttl
[NO NEW TESTS NEEDED] [NO TESTS NEEDED] Signed-off-by: Aditya R <arajan@redhat.com>
Diffstat (limited to 'pkg')
-rw-r--r--pkg/api/handlers/compat/images_build.go31
-rw-r--r--pkg/bindings/images/build.go9
2 files changed, 40 insertions, 0 deletions
diff --git a/pkg/api/handlers/compat/images_build.go b/pkg/api/handlers/compat/images_build.go
index 15cfc824e..a00f0b089 100644
--- a/pkg/api/handlers/compat/images_build.go
+++ b/pkg/api/handlers/compat/images_build.go
@@ -17,6 +17,7 @@ import (
"github.com/containers/buildah"
buildahDefine "github.com/containers/buildah/define"
"github.com/containers/buildah/pkg/parse"
+ "github.com/containers/image/v5/docker/reference"
"github.com/containers/image/v5/types"
"github.com/containers/podman/v4/libpod"
"github.com/containers/podman/v4/pkg/api/handlers/utils"
@@ -78,6 +79,8 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
AppArmor string `schema:"apparmor"`
BuildArgs string `schema:"buildargs"`
CacheFrom string `schema:"cachefrom"`
+ CacheTo string `schema:"cacheto"`
+ CacheTTL string `schema:"cachettl"`
CgroupParent string `schema:"cgroupparent"`
Compression uint64 `schema:"compression"`
ConfigureNetwork string `schema:"networkmode"`
@@ -386,6 +389,31 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
}
}
+ var cacheFrom reference.Named
+ if _, found := r.URL.Query()["cachefrom"]; found {
+ cacheFrom, err = parse.RepoNameToNamedReference(query.CacheFrom)
+ if err != nil {
+ utils.BadRequest(w, "cacheFrom", query.CacheFrom, err)
+ return
+ }
+ }
+ var cacheTo reference.Named
+ if _, found := r.URL.Query()["cacheto"]; found {
+ cacheTo, err = parse.RepoNameToNamedReference(query.CacheTo)
+ if err != nil {
+ utils.BadRequest(w, "cacheto", query.CacheTo, err)
+ return
+ }
+ }
+ var cacheTTL time.Duration
+ if _, found := r.URL.Query()["cachettl"]; found {
+ cacheTTL, err = time.ParseDuration(query.CacheTTL)
+ if err != nil {
+ utils.BadRequest(w, "cachettl", query.CacheTTL, err)
+ return
+ }
+ }
+
var buildArgs = map[string]string{}
if _, found := r.URL.Query()["buildargs"]; found {
if err := json.Unmarshal([]byte(query.BuildArgs), &buildArgs); err != nil {
@@ -578,6 +606,9 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
AdditionalTags: additionalTags,
Annotations: annotations,
CPPFlags: cppflags,
+ CacheFrom: cacheFrom,
+ CacheTo: cacheTo,
+ CacheTTL: cacheTTL,
Args: buildArgs,
AllPlatforms: query.AllPlatforms,
CommonBuildOpts: &buildah.CommonBuildOptions{
diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go
index 6883585e2..2615bc516 100644
--- a/pkg/bindings/images/build.go
+++ b/pkg/bindings/images/build.go
@@ -224,6 +224,15 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO
if len(options.Manifest) > 0 {
params.Set("manifest", options.Manifest)
}
+ if options.CacheFrom != nil {
+ params.Set("cachefrom", options.CacheFrom.String())
+ }
+ if options.CacheTo != nil {
+ params.Set("cacheto", options.CacheTo.String())
+ }
+ if int64(options.CacheTTL) != 0 {
+ params.Set("cachettl", options.CacheTTL.String())
+ }
if memSwap := options.CommonBuildOpts.MemorySwap; memSwap > 0 {
params.Set("memswap", strconv.Itoa(int(memSwap)))
}