github.com/rish1988/moby@v25.0.2+incompatible/builder/builder-next/worker/gc.go (about) 1 package worker 2 3 import ( 4 "math" 5 "time" 6 7 "github.com/moby/buildkit/client" 8 ) 9 10 const defaultCap int64 = 2e9 // 2GB 11 12 // tempCachePercent represents the percentage ratio of the cache size in bytes to temporarily keep for a short period of time (couple of days) 13 // over the total cache size in bytes. Because there is no perfect value, a mathematically pleasing one was chosen. 14 // The value is approximately 13.8 15 const tempCachePercent = math.E * math.Pi * math.Phi 16 17 // DefaultGCPolicy returns a default builder GC policy 18 func DefaultGCPolicy(p string, defaultKeepBytes int64) []client.PruneInfo { 19 keep := defaultKeepBytes 20 if defaultKeepBytes == 0 { 21 keep = detectDefaultGCCap(p) 22 } 23 24 tempCacheKeepBytes := int64(math.Round(float64(keep) / 100. * float64(tempCachePercent))) 25 const minTempCacheKeepBytes = 512 * 1e6 // 512MB 26 if tempCacheKeepBytes < minTempCacheKeepBytes { 27 tempCacheKeepBytes = minTempCacheKeepBytes 28 } 29 30 return []client.PruneInfo{ 31 // if build cache uses more than 512MB delete the most easily reproducible data after it has not been used for 2 days 32 { 33 Filter: []string{"type==source.local,type==exec.cachemount,type==source.git.checkout"}, 34 KeepDuration: 48 * time.Hour, 35 KeepBytes: tempCacheKeepBytes, 36 }, 37 // remove any data not used for 60 days 38 { 39 KeepDuration: 60 * 24 * time.Hour, 40 KeepBytes: keep, 41 }, 42 // keep the unshared build cache under cap 43 { 44 KeepBytes: keep, 45 }, 46 // if previous policies were insufficient start deleting internal data to keep build cache under cap 47 { 48 All: true, 49 KeepBytes: keep, 50 }, 51 } 52 }