Skip to content

Commit 4f8c0e1

Browse files
authored
rsc: Create configurable no-op rsc runner (#1523)
* rsc: Create configurable no-op rsc runner * cleanup * address comments * add doc comment * more doc functions * fix alpine build * Revert "fix alpine build" This reverts commit e704d01.
1 parent ab7a94e commit 4f8c0e1

File tree

4 files changed

+131
-11
lines changed

4 files changed

+131
-11
lines changed

.wakemanifest

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ share/wake/lib/system/path.wake
3434
share/wake/lib/system/plan_scorer.wake
3535
share/wake/lib/system/plan.wake
3636
share/wake/lib/system/runner.wake
37+
share/wake/lib/system/remote_cache_api.wake
38+
share/wake/lib/system/remote_cache.wake
3739
share/wake/lib/system/sources.wake
3840
src/compat/compat.wake
3941
src/dst/dst.wake
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright 2024 SiFive, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You should have received a copy of LICENSE.Apache2 along with
6+
# this software. If not, you may obtain a copy at
7+
#
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
package wake
17+
18+
# rscRunner: Creates a remote cache runner for a given api config
19+
#
20+
# ```
21+
# rscRunner (RemoteCacheApi "local" 1234 "auth") = (Runner ...)
22+
# ```
23+
export target rscRunner (rscApi: RemoteCacheApi): Runner =
24+
mkRemoteCacheRunner rscApi (\_ Pass "") "/workspace" fuseRunner
25+
26+
# mkRemoteCacheRunner: Creates a remote cache runner from an underlying runner
27+
#
28+
# - `rscApi`: the remote cache to connect to
29+
# - `hashFn`: a runner provided hash, used to invalate jobs that match by key but not by something
30+
# known only to the runner
31+
# - `wakeroot`: Absolute path to the root of the wake project
32+
# - `baseRunner`: The runner that should be used for a cache miss
33+
# ```
34+
# mkRemoteCacheRunner (RemoteCacheApi ...) (\_ Pass "") "" baseRunner = (Runner ...)
35+
# ```
36+
export def mkRemoteCacheRunner (_rscApi: RemoteCacheApi) (_hashFn: Result RunnerInput Error => Result String Error) (_wakeroot: String) ((Runner name score baseDoIt): Runner): Runner =
37+
def badlaunch job error = prim "job_fail_launch"
38+
39+
def doit job runnerInput = match runnerInput
40+
Fail e ->
41+
def _ = badlaunch job e
42+
43+
Fail e
44+
Pass input ->
45+
# TODO: Search the cache for the job
46+
47+
# Run the job to get the results
48+
require Pass output = baseDoIt job (Pass input)
49+
50+
# TODO: Insert the job into the cache
51+
52+
Pass output
53+
54+
Runner "remote-cache: {name}" score doit
55+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright 2024 SiFive, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You should have received a copy of LICENSE.Apache2 along with
6+
# this software. If not, you may obtain a copy at
7+
#
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
package wake
17+
18+
# Configuration details required to connect to the remote shared cache.
19+
export tuple RemoteCacheApi =
20+
# The domain or ip address of the cache
21+
export Domain: String
22+
# The port serving the cache
23+
export Port: Integer
24+
# The api key required for authenicated routes. Not required for all requests
25+
export Authorization: Option String
26+
27+
# makeRemoteCacheApi: Parses config string into RemoteCacheApi
28+
#
29+
# ```
30+
# makeRemoteCacheApi "local:1234:myauth" = Pass (RemoteCacheApi "local" 1234 (Some "myauth"))
31+
# makeRemoteCacheApi "local:1234:" = Pass (RemoteCacheApi "local" 1234 None)
32+
# makeRemoteCacheApi "local:1234" = Fail (...)
33+
# makeRemoteCacheApi "local" = Fail (...)
34+
# makeRemoteCacheApi "local:asdf:myauth" = Fail (...)
35+
# ```
36+
export def makeRemoteCacheApi (config: String): Result RemoteCacheApi Error =
37+
require (domain, portStr, authStr, Nil) =
38+
config
39+
| tokenize `:`
40+
else
41+
failWithError
42+
"Remote cache config was set with incorrect format. Saw: '{config}'. Expected 'domain:port:auth' (auth may be omitted)"
43+
44+
require Some (port) =
45+
portStr
46+
| int
47+
else failWithError "Remote cache config was set with non-integer port. Saw: {portStr}"
48+
49+
def auth = if authStr ==* "" then None else Some authStr
50+
51+
RemoteCacheApi domain port auth
52+
| Pass
53+
54+
# TODO: methods such as "downloadFile" and "postJob" should be implemented here.
55+

share/wake/lib/system/runner.wake

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,25 @@ export def fuseRunner: Runner =
148148
| makeJSONRunner
149149

150150
export def defaultRunner: Runner =
151-
require Some _ = getenv "WAKE_LOCAL_JOB_CACHE"
152-
else fuseRunner
153-
154-
# The fuseRunner does not actully mount over / and instead uses the
155-
# the host root as the sandbox root. This means that wakeroot will
156-
# change from depending on where wake is being run from. As a hack
157-
# to work around this we abuse the fact that the fuseRunner only
158-
# works in relative paths to make different runs consistent. Ideally
159-
# you'd have a more complex sandbox that kept the wakeroot at a
160-
# consistent place across runs.
161-
mkJobCacheRunner (\_ Pass "") "/workspace" fuseRunner
151+
require Some config = getenv "WAKE_REMOTE_CACHE"
152+
else
153+
require Some _ = getenv "WAKE_LOCAL_JOB_CACHE"
154+
else fuseRunner
155+
156+
# The fuseRunner does not actully mount over / and instead uses the
157+
# the host root as the sandbox root. This means that wakeroot will
158+
# change from depending on where wake is being run from. As a hack
159+
# to work around this we abuse the fact that the fuseRunner only
160+
# works in relative paths to make different runs consistent. Ideally
161+
# you'd have a more complex sandbox that kept the wakeroot at a
162+
# consistent place across runs.
163+
mkJobCacheRunner (\_ Pass "") "/workspace" fuseRunner
164+
165+
def remoteCacheApi = match (makeRemoteCacheApi config)
166+
Pass x -> x
167+
Fail (Error why _) -> panic why
168+
169+
rscRunner remoteCacheApi
162170

163171
# A plan describing how to construct a JSONRunner
164172
# RawScript: the path to the script to run jobs with

0 commit comments

Comments
 (0)