Skip to content

Commit c43754f

Browse files
committed
feat(Cache): environment-configurable URLs (leanprover-community#33605)
Makes the URLs used by Mathlib's cache (`lake exe cache`) configurable via environment variables. The download URL is configured through `MATHLIB_CACHE_GET_URL` and the upload URL is configured through `MATHLIB_CACHE_PUT_URL`.
1 parent 8520ad2 commit c43754f

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

Cache/Init.lean

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/-
2+
Copyright (c) 2023 Arthur Paulino. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Arthur Paulino
5+
-/
6+
7+
namespace Cache.Requests
8+
9+
open System (FilePath)
10+
11+
-- FRO cache may be flaky: https://leanprover.zulipchat.com/#narrow/channel/113488-general/topic/The.20cache.20doesn't.20work/near/411058849
12+
-- This is defined in a separate file because it is used in the definition of `URL` and `UPLOAD_URL`
13+
-- and Lean does not allow one `initialize` to use another `initialize` defined in the same file
14+
initialize useFROCache : Bool ← do
15+
let froCache ← IO.getEnv "USE_FRO_CACHE"
16+
return froCache == some "1" || froCache == some "true"

Cache/Requests.lean

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@ Authors: Arthur Paulino
66

77
import Batteries.Data.String.Matcher
88
import Cache.Hashing
9+
import Cache.Init
910

1011
namespace Cache.Requests
1112

1213
open System (FilePath)
1314

14-
-- FRO cache may be flaky: https://leanprover.zulipchat.com/#narrow/channel/113488-general/topic/The.20cache.20doesn't.20work/near/411058849
15-
initialize useFROCache : Bool ← do
16-
let froCache ← IO.getEnv "USE_FRO_CACHE"
17-
return froCache == some "1" || froCache == some "true"
18-
1915
/--
2016
Structure to hold repository information with priority ordering
2117
-/
@@ -244,11 +240,14 @@ def getRemoteRepo (mathlibDepPath : FilePath) : IO RepoInfo := do
244240
return {repo := repo, useFirst := false}
245241

246242
/-- Public URL for mathlib cache -/
247-
def URL : String :=
248-
if useFROCache then
249-
"https://mathlib4.lean-cache.cloud"
250-
else
251-
"https://lakecache.blob.core.windows.net/mathlib4"
243+
initialize URL : String ← do
244+
let url? ← IO.getEnv "MATHLIB_CACHE_GET_URL"
245+
let defaultUrl :=
246+
if useFROCache then
247+
"https://mathlib4.lean-cache.cloud"
248+
else
249+
"https://lakecache.blob.core.windows.net/mathlib4"
250+
return url?.getD defaultUrl
252251

253252
/-- Retrieves the azure token from the environment -/
254253
def getToken : IO String := do
@@ -508,11 +507,14 @@ end Get
508507
section Put
509508

510509
/-- FRO cache S3 URL -/
511-
def UPLOAD_URL : String :=
512-
if useFROCache then
513-
"https://a09a7664adc082e00f294ac190827820.r2.cloudflarestorage.com/mathlib4"
514-
else
515-
URL
510+
initialize UPLOAD_URL : String ← do
511+
let url? ← IO.getEnv "MATHLIB_CACHE_PUT_URL"
512+
let defaultUrl :=
513+
if useFROCache then
514+
"https://a09a7664adc082e00f294ac190827820.r2.cloudflarestorage.com/mathlib4"
515+
else
516+
"https://lakecache.blob.core.windows.net/mathlib4"
517+
return url?.getD defaultUrl
516518

517519
/-- Formats the config file for `curl`, containing the list of files to be uploaded -/
518520
def mkPutConfigContent (repo : String) (fileNames : Array String) (token : String) : IO String := do

0 commit comments

Comments
 (0)