From 807b20346e65bd8d494391cb765c5c9377b120d1 Mon Sep 17 00:00:00 2001 From: zabio3 Date: Wed, 29 Jan 2020 21:32:55 +0900 Subject: [PATCH] support specifying a non-latest tag using --import-cache type=local https://github.com/moby/buildkit/issues/1242 Signed-off-by: Tomohiro Kusumoto --- README.md | 1 + client/solve.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d566e57b..14dd1a83 100644 --- a/README.md +++ b/README.md @@ -357,6 +357,7 @@ The directory layout conforms to OCI Image Spec v1.0. - `ref=docker.io/user/image:tag`: reference for `registry` cache importer - `src=path/to/input-dir`: directory for `local` cache importer - `digest=sha256:deadbeef`: digest of the manifest list to import for `local` cache importer. +- `tag=customtag`: custom tag of image for `local` cache importer. Defaults to the digest of "latest" tag in `index.json` ### Consistent hashing diff --git a/client/solve.go b/client/solve.go index 3be5bc36..854aee2d 100644 --- a/client/solve.go +++ b/client/solve.go @@ -423,13 +423,13 @@ func parseCacheOptions(opt SolveOpt) (*cacheOptions, error) { continue } for _, m := range idx.Manifests { - if m.Annotations[ocispec.AnnotationRefName] == "latest" { + if (m.Annotations[ocispec.AnnotationRefName] == "latest" && attrs["tag"] == "") || (attrs["tag"] != "" && m.Annotations[ocispec.AnnotationRefName] == attrs["tag"]) { attrs["digest"] = string(m.Digest) break } } if attrs["digest"] == "" { - return nil, errors.New("local cache importer requires either explicit digest or \"latest\" tag on index.json") + return nil, errors.New("local cache importer requires either explicit digest, \"latest\" tag or custom tag on index.json") } } contentStores["local:"+csDir] = cs