forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexporter.go
45 lines (35 loc) · 974 Bytes
/
exporter.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
package builder
import (
"context"
"github.com/moby/buildkit/exporter"
)
type wrapperImageExporter struct {
exporter.Exporter
postExportFunc func(context.Context, map[string]string) error
}
func (w *wrapperImageExporter) Resolve(ctx context.Context, meta map[string]string) (exporter.ExporterInstance, error) {
i, err := w.Exporter.Resolve(ctx, meta)
if err != nil {
return nil, err
}
return &wrapperExporterInstance{
ExporterInstance: i,
postExportFunc: w.postExportFunc,
}, nil
}
type wrapperExporterInstance struct {
exporter.ExporterInstance
postExportFunc func(context.Context, map[string]string) error
}
func (eei *wrapperExporterInstance) Export(ctx context.Context, src exporter.Source) (map[string]string, error) {
res, err := eei.ExporterInstance.Export(ctx, src)
if err != nil {
return nil, err
}
if eei.postExportFunc != nil {
if err := eei.postExportFunc(ctx, res); err != nil {
return nil, err
}
}
return res, nil
}