@@ -24,12 +24,14 @@ import (
2424 grpcmetadata "google.golang.org/grpc/metadata"
2525)
2626
27+ // Opt is option struct required for creating the builder
2728type Opt struct {
2829 SessionManager * session.Manager
2930 Root string
3031 Dist images.DistributionServices
3132}
3233
34+ // Builder can build using BuildKit backend
3335type Builder struct {
3436 controller * control.Controller
3537 reqBodyHandler * reqBodyHandler
@@ -38,6 +40,7 @@ type Builder struct {
3840 jobs map [string ]* buildJob
3941}
4042
43+ // New creates a new builder
4144func New (opt Opt ) (* Builder , error ) {
4245 reqHandler := newReqBodyHandler (tracing .DefaultTransport )
4346
@@ -53,6 +56,7 @@ func New(opt Opt) (*Builder, error) {
5356 return b , nil
5457}
5558
59+ // Cancel cancels a build using ID
5660func (b * Builder ) Cancel (ctx context.Context , id string ) error {
5761 b .mu .Lock ()
5862 if j , ok := b .jobs [id ]; ok && j .cancel != nil {
@@ -62,6 +66,7 @@ func (b *Builder) Cancel(ctx context.Context, id string) error {
6266 return nil
6367}
6468
69+ // DiskUsage returns a report about space used by build cache
6570func (b * Builder ) DiskUsage (ctx context.Context ) ([]* types.BuildCache , error ) {
6671 duResp , err := b .controller .DiskUsage (ctx , & controlapi.DiskUsageRequest {})
6772 if err != nil {
@@ -86,6 +91,7 @@ func (b *Builder) DiskUsage(ctx context.Context) ([]*types.BuildCache, error) {
8691 return items , nil
8792}
8893
94+ // Prune clears all reclaimable build cache
8995func (b * Builder ) Prune (ctx context.Context ) (int64 , error ) {
9096 ch := make (chan * controlapi.UsageRecord )
9197
@@ -114,6 +120,7 @@ func (b *Builder) Prune(ctx context.Context) (int64, error) {
114120 return size , nil
115121}
116122
123+ // Build executes a build request
117124func (b * Builder ) Build (ctx context.Context , opt backend.BuildConfig ) (* builder.Result , error ) {
118125 var rc = opt .Source
119126
@@ -181,10 +188,8 @@ func (b *Builder) Build(ctx context.Context, opt backend.BuildConfig) (*builder.
181188 frontendAttrs ["context" ] = url
182189 }
183190
184- var cacheFrom []string
185- for _ , v := range opt .Options .CacheFrom {
186- cacheFrom = append (cacheFrom , v )
187- }
191+ cacheFrom := append ([]string {}, opt .Options .CacheFrom ... )
192+
188193 frontendAttrs ["cache-from" ] = strings .Join (cacheFrom , "," )
189194
190195 for k , v := range opt .Options .BuildArgs {
0 commit comments