Skip to content

Commit 1823368

Browse files
[wanda] Add context_owner spec option and include in cache digest (#481)
Add context_owner field to the wanda Spec, allowing .wanda.yaml files to specify a "uid:gid" override for all files in the build context tar. Wire it through resolveBuildInput to set the tarStream owner, and include it in buildInputCore so changing context_owner invalidates the cache. Topic: add-context-owner-spec Relative: add-context-owner-tar Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: andrew <andrew@anyscale.com> Signed-off-by: andrew <andrew@anyscale.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 94f6a2f commit 1823368

4 files changed

Lines changed: 20 additions & 0 deletions

File tree

wanda/build_input.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ type buildInputCore struct {
7676

7777
Platform string `json:",omitempty"` // "amd64" (empty string) or GOARCH
7878
OS string `json:",omitempty"` // "linux" (empty string) or GOOS
79+
80+
ContextOwner string `json:",omitempty"` // "uid:gid" override
7981
}
8082

8183
func (i *buildInput) makeCore(dockerfile string, lookup lookupFunc) (*buildInputCore, error) {

wanda/forge.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,14 @@ func (f *Forge) ExtractArtifacts(spec *Spec, imageTag string) error {
300300
func (f *Forge) resolveBuildInput(spec *Spec) (*buildInput, *buildInputCore, error) {
301301
ts := newTarStream()
302302

303+
if spec.ContextOwner != "" {
304+
owner, err := parseContextOwner(spec.ContextOwner)
305+
if err != nil {
306+
return nil, nil, err
307+
}
308+
ts.owner = owner
309+
}
310+
303311
files, err := listSrcFiles(f.workDir, spec.Srcs, spec.Dockerfile)
304312
if err != nil {
305313
return nil, nil, fmt.Errorf("list src files: %w", err)
@@ -321,6 +329,7 @@ func (f *Forge) resolveBuildInput(spec *Spec) (*buildInput, *buildInputCore, err
321329
return nil, nil, fmt.Errorf("make build input core: %w", err)
322330
}
323331
inputCore.Epoch = f.config.Epoch
332+
inputCore.ContextOwner = spec.ContextOwner
324333

325334
return in, inputCore, nil
326335
}

wanda/spec.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ type Spec struct {
3131

3232
// Artifacts defines files and directories to extract from the built image.
3333
Artifacts []*Artifact `yaml:"artifacts,omitempty"`
34+
35+
// ContextOwner overrides the uid:gid for all files and directories
36+
// in the build context tar. Format: "uid:gid" (e.g. "2000:100").
37+
ContextOwner string `yaml:"context_owner,omitempty"`
3438
}
3539

3640
func parseSpecFile(f string) (*Spec, error) {
@@ -146,6 +150,7 @@ func (s *Spec) expandVar(lookup lookupFunc) *Spec {
146150
result.BuildHintArgs = stringsExpandVar(s.BuildHintArgs, lookup)
147151
result.DisableCaching = s.DisableCaching
148152
result.Artifacts = artifactsExpandVar(s.Artifacts, lookup)
153+
result.ContextOwner = expandVar(s.ContextOwner, lookup)
149154

150155
return result
151156
}

wanda/spec_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,16 @@ func TestSpecExpand(t *testing.T) {
8888
BuildHintArgs: []string{
8989
"REMOTE_CACHE_URL=$REMOTE_CACHE_URL",
9090
},
91+
ContextOwner: "$OWNER_UID:$OWNER_GID",
9192
}
9293

9394
envs := map[string]string{
9495
"NAME": "hello",
9596
"UBUNTU_VERSION": "22.04",
9697
"RAYCI_BUILDID": "abc123",
9798
"REMOTE_CACHE_URL": "http://localhost:5000",
99+
"OWNER_UID": "1000",
100+
"OWNER_GID": "1000",
98101
}
99102

100103
expanded := spec.expandVar(func(k string) (string, bool) {
@@ -114,6 +117,7 @@ func TestSpecExpand(t *testing.T) {
114117
BuildHintArgs: []string{
115118
"REMOTE_CACHE_URL=http://localhost:5000",
116119
},
120+
ContextOwner: "1000:1000",
117121
}
118122

119123
if !reflect.DeepEqual(expanded, want) {

0 commit comments

Comments
 (0)