Skip to content

Commit 84991a2

Browse files
authored
Merge branch 'main' into use-tar-hash-as-checksum
2 parents 3b71be6 + bd49878 commit 84991a2

3 files changed

Lines changed: 43 additions & 7 deletions

File tree

.github/workflows/common.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
build:
11-
runs-on: [self-hosted, macos, sequoia, ARM64]
11+
runs-on: [self-hosted, macos, tahoe, ARM64]
1212
timeout-minutes: 30
1313
steps:
1414
- uses: actions/setup-go@v5

pkg/build/buildopts.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,31 @@ func NewBuildOpts(ctx context.Context, basePath string, contextMap map[string][]
219219
// to ExcludePatterns(dockerignore) patterns
220220
addedGlobs := []string{}
221221
for _, node := range dockerfile.AST.Children {
222-
if node.Value == "COPY" || node.Value == "ADD" {
222+
if strings.EqualFold(node.Value, "COPY") || strings.EqualFold(node.Value, "ADD") {
223223
addedGlobs = append(addedGlobs, node.Next.Value)
224224
}
225+
226+
// Extract source paths from bind mount flags in RUN commands
227+
if strings.EqualFold(node.Value, "RUN") {
228+
cmd, err := instructions.ParseInstruction(node)
229+
if err != nil {
230+
continue
231+
} else if runCmd, ok := cmd.(*instructions.RunCommand); ok {
232+
runCmd.Expand(func(word string) (string, error) {
233+
// Single word expander to normalize source path
234+
source := strings.TrimPrefix(word, "/")
235+
normalized := filepath.Clean(source)
236+
return normalized, nil
237+
})
238+
mounts := instructions.GetMounts(runCmd)
239+
for _, mount := range mounts {
240+
// Only add source paths from bind mounts (not from other stages)
241+
if mount.Type == instructions.MountTypeBind && mount.Source != "" && mount.From == "" {
242+
addedGlobs = append(addedGlobs, mount.Source)
243+
}
244+
}
245+
}
246+
}
225247
}
226248

227249
fssyncProxy, err := fssync.NewFSSyncProxy(".", basePath, addedGlobs)

pkg/fssync/walk.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"strings"
2424

2525
"github.com/google/uuid"
26+
"github.com/moby/patternmatcher"
2627

2728
"github.com/apple/container-builder-shim/pkg/api"
2829
"github.com/apple/container-builder-shim/pkg/fileutils"
@@ -83,6 +84,10 @@ func (f *FS) Walk(ctx context.Context, target string, fn fs.WalkDirFunc) error {
8384
if err != nil {
8485
return err
8586
}
87+
excludeMatcher, err := patternmatcher.New(strings.Split(walkMeta.ExcludedPatterns, ","))
88+
if err != nil {
89+
return err
90+
}
8691

8792
id := uuid.NewString()
8893
demux := stream.NewDemuxWithContext(cancellableCtx, id, stream.FilterByBuildID(id), func(any) {})
@@ -119,7 +124,14 @@ func (f *FS) Walk(ctx context.Context, target string, fn fs.WalkDirFunc) error {
119124
switch walkMeta.Mode {
120125
case ModeTAR:
121126
receiver := fileutils.NewTarReceiver(f.fsPath, demux)
122-
checksum, err := receiver.Receive(ctx, fn)
127+
checksum, err := receiver.Receive(ctx, func(path string, d fs.DirEntry, err error) error {
128+
excluded, err := excludeMatcher.MatchesOrParentMatches(path)
129+
if excluded {
130+
return nil
131+
}
132+
133+
return fn(path, d, err)
134+
})
123135
if err != nil {
124136
return err
125137
}
@@ -145,16 +157,18 @@ type RawFileInfo struct {
145157
}
146158

147159
type WalkMetadata struct {
148-
IncludePatterns string
149-
FollowPaths string
150-
DirName string
151-
Mode TransferMode
160+
IncludePatterns string
161+
ExcludedPatterns string
162+
FollowPaths string
163+
DirName string
164+
Mode TransferMode
152165
}
153166

154167
func unmarshalWalkMetadata(ctx context.Context) (*WalkMetadata, error) {
155168
md := &WalkMetadata{}
156169
if m, ok := metadata.FromIncomingContext(ctx); ok {
157170
md.IncludePatterns = strings.Join(m["include-patterns"], ",")
171+
md.ExcludedPatterns = strings.Join(m["exclude-patterns"], ",")
158172
md.FollowPaths = strings.Join(m["followpaths"], ",")
159173
md.DirName = strings.Join(m["dir-name"], ",")
160174
modeStr := strings.Join(m["mode"], ",")

0 commit comments

Comments
 (0)