-
Notifications
You must be signed in to change notification settings - Fork 22
/
signer.go
66 lines (55 loc) · 1.4 KB
/
signer.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
56
57
58
59
60
61
62
63
64
65
66
package fixtures
import (
"context"
"encoding/json"
"github.com/Azure/dalec"
"github.com/moby/buildkit/client/llb"
"github.com/moby/buildkit/exporter/containerimage/exptypes"
"github.com/moby/buildkit/frontend/dockerui"
gwclient "github.com/moby/buildkit/frontend/gateway/client"
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
)
func PhonySigner(ctx context.Context, gwc gwclient.Client) (*gwclient.Result, error) {
dc, err := dockerui.NewClient(gwc)
if err != nil {
return nil, err
}
bctx, err := dc.MainContext(ctx)
if err != nil {
return nil, err
}
st := llb.Image("golang:1.21", llb.WithMetaResolver(gwc)).
Run(
llb.Args([]string{"go", "build", "-o=/build/out", "./test/fixtures/signer"}),
llb.AddEnv("CGO_ENABLED", "0"),
goModCache,
goBuildCache,
llb.Dir("/build/src"),
llb.AddMount("/build/src", *bctx, llb.Readonly),
).
AddMount("/build/out", llb.Scratch())
cfg := dalec.DockerImageSpec{
Config: dalec.DockerImageConfig{
ImageConfig: ocispecs.ImageConfig{
Entrypoint: []string{"/signer"},
},
},
}
injectFrontendLabels(&cfg)
dt, err := json.Marshal(cfg)
if err != nil {
return nil, err
}
def, err := st.Marshal(ctx)
if err != nil {
return nil, err
}
res, err := gwc.Solve(ctx, gwclient.SolveRequest{
Definition: def.ToPB(),
})
if err != nil {
return nil, err
}
res.AddMeta(exptypes.ExporterImageConfigKey, dt)
return res, nil
}