-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
48 lines (41 loc) · 1.28 KB
/
main.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
// Simple frontend that concatenates combines pre-configures Dockerfiles with
// the one provided by the build context.
package main
import (
"context"
"os"
"github.com/EricHripko/buildkit-fdk/pkg/dtp"
dockerfile "github.com/moby/buildkit/frontend/dockerfile/builder"
"github.com/moby/buildkit/frontend/gateway/client"
"github.com/moby/buildkit/frontend/gateway/grpcclient"
"github.com/moby/buildkit/util/appcontext"
"github.com/sirupsen/logrus"
)
func build(ctx context.Context, c client.Client) (*client.Result, error) {
// Read vendored Dockerfiles
header, err := os.ReadFile("header.Dockerfile")
if err != nil {
return nil, err
}
footer, err := os.ReadFile("footer.Dockerfile")
if err != nil {
return nil, err
}
// Concatenate user-supplied Dockerfile with vendored ones
transform := func(dockerfile []byte) ([]byte, error) {
dockerfile = append(header, dockerfile...)
dockerfile = append(dockerfile, footer...)
return dockerfile, nil
}
if err := dtp.InjectDockerfileTransform(transform, c); err != nil {
return nil, err
}
// Pass control to the upstream Dockerfile frontend
return dockerfile.Build(ctx, c)
}
func main() {
if err := grpcclient.RunFromEnvironment(appcontext.Context(), build); err != nil {
logrus.Errorf("fatal error: %+v", err)
panic(err)
}
}