From 2d022248dba2e03c0fc5270afc34cea0fd0d5131 Mon Sep 17 00:00:00 2001 From: Prarup Gurung Date: Mon, 22 Aug 2022 16:32:24 +0545 Subject: [PATCH] Used cache bucket for short term caching --- .drone.star | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/.drone.star b/.drone.star index 9998d676380..18300c1e867 100644 --- a/.drone.star +++ b/.drone.star @@ -767,10 +767,7 @@ def main(ctx): pipelines = pipelines + deploys + pipelinesDependsOn( [ - purgeBuildArtifactCache(ctx, "yarn"), - purgeBuildArtifactCache(ctx, "playwright"), - purgeBuildArtifactCache(ctx, "tests-yarn"), - purgeBuildArtifactCache(ctx, "web-dist"), + purgeBuildArtifactCache(ctx), ], pipelines, ) @@ -2932,7 +2929,7 @@ def skipIfUnchanged(ctx, type): return [] -def genericCache(name, action, mounts, cache_key): +def genericCache(name, action, mounts, cache_path): rebuild = "false" restore = "false" if action == "rebuild": @@ -2958,16 +2955,18 @@ def genericCache(name, action, mounts, cache_key): "secret_key": { "from_secret": "cache_s3_secret_key", }, - "filename": "%s.tar" % (cache_key), + "filename": "%s.tar" % (name), + "path": cache_path, + "fallback_path": cache_path, }, } return step -def genericCachePurge(ctx, name, cache_key): +def genericCachePurge(flush_path): return { "kind": "pipeline", "type": "docker", - "name": "purge_%s" % (name), + "name": "purge_build_artifact_cache", "platform": { "os": "linux", "arch": "amd64", @@ -2983,12 +2982,12 @@ def genericCachePurge(ctx, name, cache_key): "endpoint": { "from_secret": "cache_s3_endpoint", }, - "flush": True, - "flush_age": "14", "secret_key": { "from_secret": "cache_s3_secret_key", }, - "filename": "%s.tar" % (cache_key), + "flush": True, + "flush_age": 1, + "flush_path": flush_path, }, }, ], @@ -3006,12 +3005,14 @@ def genericCachePurge(ctx, name, cache_key): } def genericBuildArtifactCache(ctx, name, action, path): - name = "%s_build_artifact_cache" % (name) - cache_key = "%s/%s/%s" % (ctx.repo.slug, ctx.build.commit + "-${DRONE_BUILD_NUMBER}", name) if action == "rebuild" or action == "restore": - return genericCache(name, action, [path], cache_key) + cache_path = "%s/%s/%s" % ("cache", ctx.repo.slug, ctx.build.commit + "-${DRONE_BUILD_NUMBER}") + name = "%s_build_artifact_cache" % (name) + return genericCache(name, action, [path], cache_path) + if action == "purge": - return genericCachePurge(ctx, name, cache_key) + flush_path = "%s/%s" % ("cache", ctx.repo.slug) + return genericCachePurge(flush_path) return [] def restoreBuildArtifactCache(ctx, name, path): @@ -3020,8 +3021,8 @@ def restoreBuildArtifactCache(ctx, name, path): def rebuildBuildArtifactCache(ctx, name, path): return [genericBuildArtifactCache(ctx, name, "rebuild", path)] -def purgeBuildArtifactCache(ctx, name): - return genericBuildArtifactCache(ctx, name, "purge", []) +def purgeBuildArtifactCache(ctx): + return genericBuildArtifactCache(ctx, "", "purge", []) def pipelineSanityChecks(ctx, pipelines): """pipelineSanityChecks helps the CI developers to find errors before running it