Skip to content

Commit 3a11bbb

Browse files
authored
Merge pull request #31 from Yolean/buildkit-caching-per-image
Unique buildkit cache URLs per output image
2 parents 0885441 + 0db691f commit 3a11bbb

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

bin/y-build

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ BUILDCTL_OPTS="$@"
1212
DEFAULT_REGISTRY=builds-registry.ystack.svc.cluster.local
1313
[ -z "$BUILDS_REGISTRY" ] && BUILDS_REGISTRY=$DEFAULT_REGISTRY
1414
[ -z "$PUSH_REGISTRY" ] && PUSH_REGISTRY=$DEFAULT_REGISTRY
15-
[ -z "$BUILDKIT_CACHE" ] && BUILDKIT_CACHE="type=registry,ref=$BUILDS_REGISTRY/ystack:buildcache"
16-
[ -z "$IMPORT_CACHE" ] && IMPORT_CACHE="--import-cache=$BUILDKIT_CACHE"
17-
[ -z "$EXPORT_CACHE" ] && EXPORT_CACHE="--export-cache=$BUILDKIT_CACHE"
18-
[ "$IMPORT_CACHE" = "false" ] && IMPORT_CACHE=""
19-
[ "$EXPORT_CACHE" = "false" ] && EXPORT_CACHE=""
2015
[ -z "$BUILDKIT_HOST" ] && BUILDKIT_HOST=tcp://buildkitd.ystack.svc.cluster.local:8547
2116

2217
if [ "$(curl -s --connect-timeout 3 http://$BUILDS_REGISTRY/v2/)" != "{}" ]
@@ -65,6 +60,13 @@ if [[ ! -z "$GIT_COMMIT" ]]; then
6560
fi
6661
fi
6762

63+
REGISTRY_CACHE_DEFAULT=$(echo $IMAGE | sed "s|[^/]*|$BUILDS_REGISTRY/ystack-buildcache|" | sed "s/:$BUILD_TAG//")
64+
[ -z "$BUILDKIT_CACHE" ] && BUILDKIT_CACHE="type=registry,ref=$REGISTRY_CACHE_DEFAULT"
65+
[ -z "$IMPORT_CACHE" ] && IMPORT_CACHE="--import-cache=$BUILDKIT_CACHE"
66+
[ -z "$EXPORT_CACHE" ] && EXPORT_CACHE="--export-cache=$BUILDKIT_CACHE,mode=max"
67+
[ "$IMPORT_CACHE" = "false" ] && IMPORT_CACHE=""
68+
[ "$EXPORT_CACHE" = "false" ] && EXPORT_CACHE=""
69+
6870
echo "Build command:"
6971
set -x
7072
y-buildctl \

0 commit comments

Comments
 (0)