Skip to content

Commit

Permalink
Add capabilities for copy include/exclude patterns
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Lehmann <[email protected]>
  • Loading branch information
aaronlehmann committed Apr 26, 2021
1 parent 2bab787 commit 7b8b97c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
17 changes: 17 additions & 0 deletions client/llb/fileop.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ type subAction interface {
toProtoAction(context.Context, string, pb.InputIndex) (pb.IsFileAction, error)
}

type capAdder interface {
addCaps(*FileOp)
}

type FileAction struct {
state *State
prev *FileAction
Expand Down Expand Up @@ -500,6 +504,15 @@ func (a *fileActionCopy) sourcePath(ctx context.Context) (string, error) {
return p, nil
}

func (a *fileActionCopy) addCaps(f *FileOp) {
if len(a.info.IncludePatterns) != 0 {
addCap(&f.constraints, pb.CapFileCopyIncludePatterns)
}
if len(a.info.ExcludePatterns) != 0 {
addCap(&f.constraints, pb.CapFileCopyExcludePatterns)
}
}

type CreatedTime time.Time

func WithCreatedTime(t time.Time) CreatedTime {
Expand Down Expand Up @@ -686,6 +699,10 @@ func (f *FileOp) Marshal(ctx context.Context, c *Constraints) (digest.Digest, []
pop.Inputs = state.inputs

for i, st := range state.actions {
if adder, isCapAdder := st.action.(capAdder); isCapAdder {
adder.addCaps(f)
}

output := pb.OutputIndex(-1)
if i+1 == len(state.actions) {
output = 0
Expand Down
18 changes: 16 additions & 2 deletions solver/pb/caps.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ const (

CapExecMetaSecurityDeviceWhitelistV1 apicaps.CapID = "exec.meta.security.devices.v1"

CapFileBase apicaps.CapID = "file.base"
CapFileRmWildcard apicaps.CapID = "file.rm.wildcard"
CapFileBase apicaps.CapID = "file.base"
CapFileRmWildcard apicaps.CapID = "file.rm.wildcard"
CapFileCopyIncludePatterns apicaps.CapID = "file.copy.includepatterns"
CapFileCopyExcludePatterns apicaps.CapID = "file.copy.excludepatterns"

CapConstraints apicaps.CapID = "constraints"
CapPlatform apicaps.CapID = "platform"
Expand Down Expand Up @@ -288,6 +290,18 @@ func init() {
Status: apicaps.CapStatusExperimental,
})

Caps.Init(apicaps.Cap{
ID: CapFileCopyIncludePatterns,
Enabled: true,
Status: apicaps.CapStatusExperimental,
})

Caps.Init(apicaps.Cap{
ID: CapFileCopyExcludePatterns,
Enabled: true,
Status: apicaps.CapStatusExperimental,
})

Caps.Init(apicaps.Cap{
ID: CapConstraints,
Enabled: true,
Expand Down

0 comments on commit 7b8b97c

Please sign in to comment.