Skip to content

Commit 157b0b3

Browse files
committed
builder: lint fixes
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
1 parent 1f09adb commit 157b0b3

File tree

14 files changed

+58
-45
lines changed

14 files changed

+58
-45
lines changed

api/server/backend/build/backend.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ func (b *Backend) PruneCache(ctx context.Context) (*types.BuildCachePruneReport,
118118
return &types.BuildCachePruneReport{SpaceReclaimed: fsCacheSize + uint64(buildCacheSize)}, nil
119119
}
120120

121+
// Cancel cancels the build by ID
121122
func (b *Backend) Cancel(ctx context.Context, id string) error {
122123
return b.buildkit.Cancel(ctx, id)
123124
}

api/server/router/system/system_routes.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ func (s *systemRouter) getDiskUsage(ctx context.Context, w http.ResponseWriter,
7676
eg.Go(func() error {
7777
var err error
7878
du, err = s.backend.SystemDiskUsage(ctx)
79-
if err != nil {
80-
return err
81-
}
82-
return nil
79+
return err
8380
})
8481

8582
var builderSize int64 // legacy

api/types/client.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,10 @@ type ImageBuildOptions struct {
189189
type BuilderVersion string
190190

191191
const (
192-
BuilderV1 BuilderVersion = "1"
193-
BuilderBuildKit = "2"
192+
// BuilderV1 is the first generation builder in docker daemon
193+
BuilderV1 BuilderVersion = "1"
194+
// BuilderBuildKit is builder based on moby/buildkit project
195+
BuilderBuildKit = "2"
194196
)
195197

196198
// ImageBuildResponse holds information

builder/builder-next/adapters/containerimage/pull.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import (
4343

4444
const preferLocal = true // FIXME: make this optional from the op
4545

46+
// SourceOpt is options for creating the image source
4647
type SourceOpt struct {
4748
SessionManager *session.Manager
4849
ContentStore content.Store
@@ -58,6 +59,7 @@ type imageSource struct {
5859
g flightcontrol.Group
5960
}
6061

62+
// NewSource creates a new image source
6163
func NewSource(opt SourceOpt) (source.Source, error) {
6264
is := &imageSource{
6365
SourceOpt: opt,

builder/builder-next/adapters/snapshot/layer.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ func (s *snapshotter) EnsureLayer(ctx context.Context, key string) ([]layer.Diff
6969
}
7070
}
7171
diffID, size, err = s.reg.ChecksumForGraphID(id, parent, "", tarSplitPath)
72-
if err != nil {
73-
return err
74-
}
75-
return nil
72+
return err
7673
})
7774

7875
if err := eg.Wait(); err != nil {

builder/builder-next/adapters/snapshot/snapshot.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var keyCommitted = []byte("committed")
2323
var keyChainID = []byte("chainid")
2424
var keySize = []byte("size")
2525

26+
// Opt defines options for creating the snapshotter
2627
type Opt struct {
2728
GraphDriver graphdriver.Driver
2829
LayerStore layer.Store
@@ -50,6 +51,7 @@ type snapshotter struct {
5051

5152
var _ snapshot.SnapshotterBase = &snapshotter{}
5253

54+
// NewSnapshotter creates a new snapshotter
5355
func NewSnapshotter(opt Opt) (snapshot.SnapshotterBase, error) {
5456
dbPath := filepath.Join(opt.Root, "snapshots.db")
5557
db, err := bolt.Open(dbPath, 0600, nil)
@@ -196,7 +198,7 @@ func (s *snapshotter) Stat(ctx context.Context, key string) (snapshots.Info, err
196198
inf.Parent = p.ChainID().String()
197199
}
198200
inf.Kind = snapshots.KindCommitted
199-
inf.Name = string(key)
201+
inf.Name = key
200202
return inf, nil
201203
}
202204

@@ -215,7 +217,7 @@ func (s *snapshotter) Stat(ctx context.Context, key string) (snapshots.Info, err
215217
if b == nil && l == nil {
216218
return errors.Errorf("snapshot %s not found", id) // TODO: typed
217219
}
218-
inf.Name = string(key)
220+
inf.Name = key
219221
if b != nil {
220222
v := b.Get(keyParent)
221223
if v != nil {
@@ -322,7 +324,7 @@ func (s *snapshotter) Remove(ctx context.Context, key string) error {
322324
}
323325

324326
func (s *snapshotter) Commit(ctx context.Context, name, key string, opts ...snapshots.Opt) error {
325-
if err := s.db.Update(func(tx *bolt.Tx) error {
327+
return s.db.Update(func(tx *bolt.Tx) error {
326328
b, err := tx.CreateBucketIfNotExists([]byte(name))
327329
if err != nil {
328330
return err
@@ -331,10 +333,7 @@ func (s *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
331333
return err
332334
}
333335
return nil
334-
}); err != nil {
335-
return err
336-
}
337-
return nil
336+
})
338337
}
339338

340339
func (s *snapshotter) View(ctx context.Context, key, parent string, opts ...snapshots.Opt) (snapshot.Mountable, error) {
@@ -421,7 +420,7 @@ func (s *snapshotter) Usage(ctx context.Context, key string) (us snapshots.Usage
421420
}); err != nil {
422421
return usage, err
423422
}
424-
usage.Size = int64(diffSize)
423+
usage.Size = diffSize
425424
return usage, nil
426425
}
427426

builder/builder-next/builder.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ import (
2424
grpcmetadata "google.golang.org/grpc/metadata"
2525
)
2626

27+
// Opt is option struct required for creating the builder
2728
type Opt struct {
2829
SessionManager *session.Manager
2930
Root string
3031
Dist images.DistributionServices
3132
}
3233

34+
// Builder can build using BuildKit backend
3335
type 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
4144
func 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
5660
func (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
6570
func (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
8995
func (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
117124
func (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 {

builder/builder-next/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func newController(rt http.RoundTripper, opt Opt) (*control.Controller, error) {
117117
frontends["dockerfile.v0"] = dockerfile.NewDockerfileFrontend()
118118
frontends["gateway.v0"] = gateway.NewGatewayFrontend()
119119

120-
wopt := mobyworker.WorkerOpt{
120+
wopt := mobyworker.Opt{
121121
ID: "moby",
122122
SessionManager: opt.SessionManager,
123123
MetadataStore: md,

builder/builder-next/exporter/export.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ const (
1919
exporterImageConfig = "containerimage.config"
2020
)
2121

22+
// Differ can make a moby layer from a snapshot
2223
type Differ interface {
2324
EnsureLayer(ctx context.Context, key string) ([]layer.DiffID, error)
2425
}
2526

27+
// Opt defines a struct for creating new exporter
2628
type Opt struct {
2729
ImageStore image.Store
2830
ReferenceStore reference.Store
@@ -33,6 +35,7 @@ type imageExporter struct {
3335
opt Opt
3436
}
3537

38+
// New creates a new moby imagestore exporter
3639
func New(opt Opt) (exporter.Exporter, error) {
3740
im := &imageExporter{opt: opt}
3841
return im, nil

builder/builder-next/exporter/writer.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ func patchImageConfig(dt []byte, dps []digest.Digest, history []ocispec.History)
4949

5050
var rootFS ocispec.RootFS
5151
rootFS.Type = "layers"
52-
for _, dp := range dps {
53-
rootFS.DiffIDs = append(rootFS.DiffIDs, dp)
54-
}
52+
rootFS.DiffIDs = append(rootFS.DiffIDs, dps...)
53+
5554
dt, err := json.Marshal(rootFS)
5655
if err != nil {
5756
return nil, errors.Wrap(err, "failed to marshal rootfs")
@@ -87,7 +86,7 @@ func normalizeLayersAndHistory(diffs []digest.Digest, history []ocispec.History,
8786
var historyLayers int
8887
for _, h := range history {
8988
if !h.EmptyLayer {
90-
historyLayers += 1
89+
historyLayers++
9190
}
9291
}
9392
if historyLayers > len(diffs) {

0 commit comments

Comments
 (0)