2017-08-25 20:08:18 +00:00
|
|
|
package dockerfile
|
|
|
|
|
|
|
|
import (
|
2018-01-16 22:30:10 +00:00
|
|
|
"context"
|
|
|
|
|
2017-08-25 20:08:18 +00:00
|
|
|
"github.com/moby/buildkit/frontend"
|
2017-12-13 23:46:52 +00:00
|
|
|
"github.com/moby/buildkit/frontend/dockerfile/builder"
|
2018-04-13 21:13:48 +00:00
|
|
|
solver "github.com/moby/buildkit/solver-next"
|
2017-08-25 20:08:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func NewDockerfileFrontend() frontend.Frontend {
|
|
|
|
return &dfFrontend{}
|
|
|
|
}
|
|
|
|
|
2017-09-22 17:30:30 +00:00
|
|
|
type dfFrontend struct{}
|
|
|
|
|
2018-04-13 21:13:48 +00:00
|
|
|
func (f *dfFrontend) Solve(ctx context.Context, llbBridge frontend.FrontendLLBBridge, opts map[string]string) (retRef solver.CachedResult, exporterAttr map[string][]byte, retErr error) {
|
2017-11-07 00:25:46 +00:00
|
|
|
|
2017-12-13 23:46:52 +00:00
|
|
|
c, err := llbBridgeToGatewayClient(ctx, llbBridge, opts)
|
2017-08-25 20:08:18 +00:00
|
|
|
if err != nil {
|
2017-09-11 05:35:07 +00:00
|
|
|
return nil, nil, err
|
2017-08-25 20:08:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
2017-12-13 23:46:52 +00:00
|
|
|
for _, r := range c.refs {
|
2017-12-14 01:29:03 +00:00
|
|
|
if r != nil && (c.final != r || retErr != nil) {
|
2017-12-13 23:46:52 +00:00
|
|
|
r.Release(context.TODO())
|
|
|
|
}
|
2017-08-25 20:08:18 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2017-12-14 05:17:50 +00:00
|
|
|
if err := builder.Build(ctx, c); err != nil {
|
2017-09-11 05:35:07 +00:00
|
|
|
return nil, nil, err
|
2017-08-25 20:08:18 +00:00
|
|
|
}
|
2017-09-11 05:35:07 +00:00
|
|
|
|
2018-04-13 21:13:48 +00:00
|
|
|
if c.final == nil || c.final.CachedResult == nil {
|
|
|
|
return nil, c.exporterAttr, nil
|
2017-08-25 20:08:18 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 21:13:48 +00:00
|
|
|
return c.final, c.exporterAttr, nil
|
2017-11-07 00:25:46 +00:00
|
|
|
}
|