From ff7118ebfdedda8ef93af38f4eda722f2f613bef Mon Sep 17 00:00:00 2001 From: Saw-jan Date: Thu, 2 Mar 2023 12:06:37 +0545 Subject: [PATCH] archive go/bin content and push it as cache fix cache source --- .drone.star | 25 +++++++++++++++++++++--- tests/config/drone/check_go_bin_cache.sh | 3 ++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.drone.star b/.drone.star index 8d90438d4e..1dff7fe562 100644 --- a/.drone.star +++ b/.drone.star @@ -43,6 +43,8 @@ dirs = { "zip": "/drone/src/zip", "webZip": "/drone/src/zip/web.tar.gz", "webPnpmZip": "/drone/src/zip/pnpm-store.tar.gz", + "gobinTar": "go-bin.tar.gz", + "gobinTarPath": "/drone/src/go-bin.tar.gz", "ocisConfig": "tests/config/drone/ocis-config.json", "ocis": "/srv/app/tmp/ocis", "ocisRevaDataRoot": "/srv/app/tmp/ocis/owncloud/data", @@ -400,7 +402,7 @@ def checkGoBinCache(): }, }, "commands": [ - "bash -x %s/tests/config/drone/check_go_bin_cache.sh %s" % (dirs["base"], dirs["base"]), + "bash -x %s/tests/config/drone/check_go_bin_cache.sh %s %s" % (dirs["base"], dirs["base"], dirs["gobinTar"]), ], }] @@ -414,6 +416,14 @@ def cacheGoBin(): ], "volumes": [stepVolumeGo], }, + { + "name": "archive-go-bin", + "image": OC_UBUNTU, + "commands": [ + "tar -czvf %s -C /go/bin ." % dirs["gobinTarPath"], + ], + "volumes": [stepVolumeGo], + }, { "name": "cache-go-bin", "image": MINIO_MC, @@ -424,7 +434,7 @@ def cacheGoBin(): "BINGO_HASH=$(cat %s/.bingo_hash)" % dirs["base"], # cache using the minio client to the public bucket (long term bucket) "mc alias set s3 $MC_HOST $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY", - "mc cp -r /go/bin s3/$CACHE_BUCKET/ocis/go-bin/$BINGO_HASH", + "mc cp -r %s s3/$CACHE_BUCKET/ocis/go-bin/$BINGO_HASH" % (dirs["gobinTarPath"]), ], "volumes": [stepVolumeGo], }, @@ -439,7 +449,16 @@ def restoreGoBinCache(): "commands": [ "BINGO_HASH=$(cat %s/.bingo/* | sha256sum | cut -d ' ' -f 1)" % dirs["base"], "mc alias set s3 $MC_HOST $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY", - "mc cp -r -a s3/$CACHE_BUCKET/ocis/go-bin/$BINGO_HASH/bin /go", + "mc cp -r -a s3/$CACHE_BUCKET/ocis/go-bin/$BINGO_HASH/%s %s" % (dirs["gobinTar"], dirs["base"]), + ], + "volumes": [stepVolumeGo], + }, + { + "name": "extract-go-bin-cache", + "image": OC_UBUNTU, + "commands": [ + "mkdir -p /go/bin", + "tar -xvf %s -C /go/bin" % dirs["gobinTarPath"], "chmod +x /go/bin/*", ], "volumes": [stepVolumeGo], diff --git a/tests/config/drone/check_go_bin_cache.sh b/tests/config/drone/check_go_bin_cache.sh index 6d542d6ff1..099a779429 100644 --- a/tests/config/drone/check_go_bin_cache.sh +++ b/tests/config/drone/check_go_bin_cache.sh @@ -2,6 +2,7 @@ # # $1 - root path where .bingo resides +# $2 - name of the cache item # ROOT_PATH="$1" @@ -13,7 +14,7 @@ BINGO_DIR="$ROOT_PATH/.bingo" # generate hash of a .bingo folder BINGO_HASH=$(cat "$BINGO_DIR"/* | sha256sum | cut -d ' ' -f 1) -URL="$CACHE_ENDPOINT/$CACHE_BUCKET/ocis/go-bin/$BINGO_HASH/bin/golangci-lint" +URL="$CACHE_ENDPOINT/$CACHE_BUCKET/ocis/go-bin/$BINGO_HASH/$2" if curl --output /dev/null --silent --head --fail "$URL"; then echo "[INFO] Go bin cache with has '$BINGO_HASH' exists." # https://discourse.drone.io/t/how-to-exit-a-pipeline-early-without-failing/3951