2017-08-25 20:08:18 +00:00
|
|
|
package dockerfile
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/moby/buildkit/cache"
|
|
|
|
"github.com/moby/buildkit/frontend"
|
2017-12-13 23:46:52 +00:00
|
|
|
"github.com/moby/buildkit/frontend/dockerfile/builder"
|
2017-08-25 20:08:18 +00:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
func NewDockerfileFrontend() frontend.Frontend {
|
|
|
|
return &dfFrontend{}
|
|
|
|
}
|
|
|
|
|
2017-09-22 17:30:30 +00:00
|
|
|
type dfFrontend struct{}
|
|
|
|
|
2017-10-03 06:33:25 +00:00
|
|
|
func (f *dfFrontend) Solve(ctx context.Context, llbBridge frontend.FrontendLLBBridge, opts map[string]string) (retRef cache.ImmutableRef, 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
|
|
|
|
2017-12-13 23:46:52 +00:00
|
|
|
if c.final == nil {
|
|
|
|
return nil, nil, errors.Errorf("invalid empty return") // shouldn't happen
|
2017-08-25 20:08:18 +00:00
|
|
|
}
|
|
|
|
|
2017-12-14 01:29:03 +00:00
|
|
|
return c.final.ImmutableRef, c.exporterAttr, nil
|
2017-11-07 00:25:46 +00:00
|
|
|
}
|