-
Notifications
You must be signed in to change notification settings - Fork 9
/
shellscript.go
55 lines (45 loc) · 1.89 KB
/
shellscript.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
48
49
50
51
52
53
54
55
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package shellscript
import (
"context"
"io/fs"
"path/filepath"
"namespacelabs.dev/foundation/internal/fnerrors"
"namespacelabs.dev/foundation/internal/parsing/integration/api"
"namespacelabs.dev/foundation/schema"
"namespacelabs.dev/foundation/std/pkggraph"
)
func Register() {
api.RegisterIntegration[*schema.ShellScriptIntegration, *schema.ShellScriptIntegration](impl{})
}
type impl struct {
api.DefaultBinaryTestIntegration[*schema.ShellScriptIntegration]
}
func (impl) ApplyToServer(ctx context.Context, env *schema.Environment, pl pkggraph.PackageLoader, pkg *pkggraph.Package, data *schema.ShellScriptIntegration) error {
return fnerrors.UserError(pkg.Location, "shellscript integration is not supported on the server")
}
func (impl) CreateBinary(ctx context.Context, env *schema.Environment, pl pkggraph.PackageLoader, loc pkggraph.Location, data *schema.ShellScriptIntegration) (*schema.Binary, error) {
if data.Entrypoint == "" {
return nil, fnerrors.UserError(loc, "missing required field `entrypoint`")
}
if _, err := fs.Stat(loc.Module.ReadOnlyFS(), filepath.Join(loc.Rel(), data.Entrypoint)); err != nil {
return nil, fnerrors.Wrapf(loc, err, "could not find %q file, please verify that the specified script path is correct", data.Entrypoint)
}
required := []string{"bash", "curl"}
required = append(required, data.RequiredPackages...)
return &schema.Binary{
BuildPlan: &schema.LayeredImageBuildPlan{
LayerBuildPlan: []*schema.ImageBuildPlan{{
AlpineBuild: &schema.ImageBuildPlan_AlpineBuild{Package: required},
}, {
SnapshotFiles: []string{data.Entrypoint},
}},
},
Config: &schema.BinaryConfig{
WorkingDir: "/",
Command: []string{data.Entrypoint},
},
}, nil
}