-
Notifications
You must be signed in to change notification settings - Fork 1
/
helper.go
47 lines (42 loc) · 1.14 KB
/
helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package frontend
import (
"context"
"errors"
"os"
"strings"
"github.com/EricHripko/pack.yaml/pkg/packer2llb"
"github.com/EricHripko/buildkit-fdk/pkg/cib"
"github.com/moby/buildkit/frontend/gateway/client"
fsutil "github.com/tonistiigi/fsutil/types"
)
// Returned when no command was found in the produced image.
var errNoCommand = errors.New("frontend: no command found")
// Looks in the known install directory and attempts to automatically detect
// the command for the image.
func findCommand(ctx context.Context, ref client.Reference) (command string, err error) {
prefix := packer2llb.DirInstall[1:]
err = cib.WalkRecursive(ctx, ref, func(file *fsutil.Stat) error {
// Must be in install location
if !strings.HasPrefix(file.Path, prefix) {
return nil
}
// Must not be a directory
if os.FileMode(file.Mode).IsDir() {
return nil
}
// Must be executable
if file.Mode&0100 == 0 {
return nil
}
// Multiple commands found
if command != "" {
return errors.New("frontend: multiple commands found (" + command + ")")
}
command = "/" + file.Path
return nil
})
if command == "" {
err = errNoCommand
}
return
}