Skip to content

Commit 74a4ccd

Browse files
thaJeztahndeloof
authored andcommitted
fix various linting issues
Got these when running locally on a more recent version of golangci-lint: pkg/compose/build_bake.go:187:3: importShadow: shadow of imported from 'github.com/docker/cli/cli/command/image/build' package 'build' (gocritic) build := *service.Build ^ pkg/compose/build_bake.go:526:19: importShadow: shadow of imported from 'github.com/docker/cli/cli/command/image/build' package 'build' (gocritic) func toBakeAttest(build types.BuildConfig) []string { ^ pkg/compose/create.go:1453:2: importShadow: shadow of imported from 'github.com/docker/docker/api/types/network' package 'network' (gocritic) network string, ^ pkg/compose/create.go:1468:2: importShadow: shadow of imported from 'github.com/docker/docker/api/types/network' package 'network' (gocritic) network string, ^ pkg/compose/monitor.go:42:17: importShadow: shadow of imported from 'github.com/docker/compose/v2/pkg/api' package 'api' (gocritic) func newMonitor(api client.APIClient, project string) *monitor { ^ cmd/compose/config.go:337:1: File is not properly formatted (gofumpt) return ^ pkg/compose/convergence.go:608:1: File is not properly formatted (gofumpt) return ^ pkg/compose/cp.go:335:1: File is not properly formatted (gofumpt) return ^ pkg/e2e/compose_up_test.go:35:10: go-require: c.RunDockerComposeCmd contains assertions that must only be used in the goroutine running the test function (testifylint) res := c.RunDockerComposeCmd(t, "-f", "fixtures/dependencies/deps-completed-successfully.yaml", "--project-name", projectName, "up", "--wait", "-d") ^ pkg/e2e/healthcheck_test.go:42:10: go-require: c.RunDockerComposeCmd contains assertions that must only be used in the goroutine running the test function (testifylint) res := c.RunDockerComposeCmd(t, "-f", "fixtures/start_interval/compose.yaml", "--project-name", projectName, "up", "--wait", "-d", "test") ^ 10 issues: * gocritic: 5 * gofumpt: 3 * testifylint: 2 Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 6719f47 commit 74a4ccd

File tree

8 files changed

+51
-50
lines changed

8 files changed

+51
-50
lines changed

cmd/compose/config.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,17 +324,16 @@ func resolveImageDigests(ctx context.Context, dockerCli command.Cli, model map[s
324324
func formatModel(model map[string]any, format string) (content []byte, err error) {
325325
switch format {
326326
case "json":
327-
content, err = json.MarshalIndent(model, "", " ")
327+
return json.MarshalIndent(model, "", " ")
328328
case "yaml":
329329
buf := bytes.NewBuffer([]byte{})
330330
encoder := yaml.NewEncoder(buf)
331331
encoder.SetIndent(2)
332332
err = encoder.Encode(model)
333-
content = buf.Bytes()
333+
return buf.Bytes(), err
334334
default:
335335
return nil, fmt.Errorf("unsupported format %q", format)
336336
}
337-
return
338337
}
339338

340339
func runServices(ctx context.Context, dockerCli command.Cli, opts configOptions) error {

pkg/compose/build_bake.go

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,19 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
184184
if service.Build == nil {
185185
continue
186186
}
187-
build := *service.Build
187+
buildConfig := *service.Build
188188
labels := getImageBuildLabels(project, service)
189189

190190
args := resolveAndMergeBuildArgs(s.getProxyConfig(), project, service, options).ToMapping()
191191
for k, v := range args {
192192
args[k] = strings.ReplaceAll(v, "${", "$${")
193193
}
194194

195-
entitlements := build.Entitlements
196-
if slices.Contains(build.Entitlements, "security.insecure") {
195+
entitlements := buildConfig.Entitlements
196+
if slices.Contains(buildConfig.Entitlements, "security.insecure") {
197197
privileged = true
198198
}
199-
if build.Privileged {
199+
if buildConfig.Privileged {
200200
entitlements = append(entitlements, "security.insecure")
201201
privileged = true
202202
}
@@ -217,8 +217,8 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
217217
}
218218
}
219219

220-
read = append(read, build.Context)
221-
for _, path := range build.AdditionalContexts {
220+
read = append(read, buildConfig.Context)
221+
for _, path := range buildConfig.AdditionalContexts {
222222
_, _, err := gitutil.ParseGitRef(path)
223223
if !strings.Contains(path, "://") && err != nil {
224224
read = append(read, path)
@@ -235,35 +235,35 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
235235

236236
target := targets[serviceName]
237237

238-
secrets, env := toBakeSecrets(project, build.Secrets)
238+
secrets, env := toBakeSecrets(project, buildConfig.Secrets)
239239
secretsEnv = append(secretsEnv, env...)
240240

241241
cfg.Targets[target] = bakeTarget{
242-
Context: build.Context,
243-
Contexts: additionalContexts(build.AdditionalContexts, targets),
244-
Dockerfile: dockerFilePath(build.Context, build.Dockerfile),
245-
DockerfileInline: strings.ReplaceAll(build.DockerfileInline, "${", "$${"),
242+
Context: buildConfig.Context,
243+
Contexts: additionalContexts(buildConfig.AdditionalContexts, targets),
244+
Dockerfile: dockerFilePath(buildConfig.Context, buildConfig.Dockerfile),
245+
DockerfileInline: strings.ReplaceAll(buildConfig.DockerfileInline, "${", "$${"),
246246
Args: args,
247247
Labels: labels,
248-
Tags: append(build.Tags, image),
248+
Tags: append(buildConfig.Tags, image),
249249

250-
CacheFrom: build.CacheFrom,
251-
CacheTo: build.CacheTo,
252-
NetworkMode: build.Network,
253-
Platforms: build.Platforms,
254-
Target: build.Target,
250+
CacheFrom: buildConfig.CacheFrom,
251+
CacheTo: buildConfig.CacheTo,
252+
NetworkMode: buildConfig.Network,
253+
Platforms: buildConfig.Platforms,
254+
Target: buildConfig.Target,
255255
Secrets: secrets,
256-
SSH: toBakeSSH(append(build.SSH, options.SSHs...)),
256+
SSH: toBakeSSH(append(buildConfig.SSH, options.SSHs...)),
257257
Pull: pull,
258258
NoCache: noCache,
259-
ShmSize: build.ShmSize,
260-
Ulimits: toBakeUlimits(build.Ulimits),
259+
ShmSize: buildConfig.ShmSize,
260+
Ulimits: toBakeUlimits(buildConfig.Ulimits),
261261
Entitlements: entitlements,
262-
ExtraHosts: toBakeExtraHosts(build.ExtraHosts),
262+
ExtraHosts: toBakeExtraHosts(buildConfig.ExtraHosts),
263263

264264
Outputs: outputs,
265265
Call: call,
266-
Attest: toBakeAttest(build),
266+
Attest: toBakeAttest(buildConfig),
267267
}
268268
}
269269

@@ -524,24 +524,24 @@ func toBakeSecrets(project *types.Project, secrets []types.ServiceSecretConfig)
524524
return s, env
525525
}
526526

527-
func toBakeAttest(build types.BuildConfig) []string {
527+
func toBakeAttest(buildConfig types.BuildConfig) []string {
528528
var attests []string
529529

530530
// Handle per-service provenance configuration (only from build config, not global options)
531-
if build.Provenance != "" {
532-
if build.Provenance == "true" {
531+
if buildConfig.Provenance != "" {
532+
if buildConfig.Provenance == "true" {
533533
attests = append(attests, "type=provenance")
534-
} else if build.Provenance != "false" {
535-
attests = append(attests, fmt.Sprintf("type=provenance,%s", build.Provenance))
534+
} else if buildConfig.Provenance != "false" {
535+
attests = append(attests, fmt.Sprintf("type=provenance,%s", buildConfig.Provenance))
536536
}
537537
}
538538

539539
// Handle per-service SBOM configuration (only from build config, not global options)
540-
if build.SBOM != "" {
541-
if build.SBOM == "true" {
540+
if buildConfig.SBOM != "" {
541+
if buildConfig.SBOM == "true" {
542542
attests = append(attests, "type=sbom")
543-
} else if build.SBOM != "false" {
544-
attests = append(attests, fmt.Sprintf("type=sbom,%s", build.SBOM))
543+
} else if buildConfig.SBOM != "false" {
544+
attests = append(attests, fmt.Sprintf("type=sbom,%s", buildConfig.SBOM))
545545
}
546546
}
547547

pkg/compose/convergence.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,10 +605,10 @@ func (s *composeService) createContainer(ctx context.Context, project *types.Pro
605605
StatusText: err.Error(),
606606
})
607607
}
608-
return
608+
return ctr, err
609609
}
610610
s.events.On(progress.CreatedEvent(eventName))
611-
return
611+
return ctr, nil
612612
}
613613

614614
func (s *composeService) recreateContainer(ctx context.Context, project *types.Project, service types.ServiceConfig,

pkg/compose/cp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ func splitCpArg(arg string) (ctr, path string) {
331331

332332
func resolveLocalPath(localPath string) (absPath string, err error) {
333333
if absPath, err = filepath.Abs(localPath); err != nil {
334-
return
334+
return absPath, err
335335
}
336336
return archive.PreserveTrailingDotOrSeparator(absPath, localPath), nil
337337
}

pkg/compose/create.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,11 +1449,11 @@ func (s *composeService) removeDivergedNetwork(ctx context.Context, project *typ
14491449

14501450
func (s *composeService) disconnectNetwork(
14511451
ctx context.Context,
1452-
network string,
1452+
nwName string,
14531453
containers Containers,
14541454
) error {
14551455
for _, c := range containers {
1456-
err := s.apiClient().NetworkDisconnect(ctx, network, c.ID, true)
1456+
err := s.apiClient().NetworkDisconnect(ctx, nwName, c.ID, true)
14571457
if err != nil {
14581458
return err
14591459
}
@@ -1464,12 +1464,12 @@ func (s *composeService) disconnectNetwork(
14641464

14651465
func (s *composeService) connectNetwork(
14661466
ctx context.Context,
1467-
network string,
1467+
nwName string,
14681468
containers Containers,
14691469
config *network.EndpointSettings,
14701470
) error {
14711471
for _, c := range containers {
1472-
err := s.apiClient().NetworkConnect(ctx, network, c.ID, config)
1472+
err := s.apiClient().NetworkConnect(ctx, nwName, c.ID, config)
14731473
if err != nil {
14741474
return err
14751475
}

pkg/compose/monitor.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ import (
3232
)
3333

3434
type monitor struct {
35-
api client.APIClient
36-
project string
35+
apiClient client.APIClient
36+
project string
3737
// services tells us which service to consider and those we can ignore, maybe ran by a concurrent compose command
3838
services map[string]bool
3939
listeners []api.ContainerEventListener
4040
}
4141

42-
func newMonitor(api client.APIClient, project string) *monitor {
42+
func newMonitor(apiClient client.APIClient, project string) *monitor {
4343
return &monitor{
44-
api: api,
45-
project: project,
46-
services: map[string]bool{},
44+
apiClient: apiClient,
45+
project: project,
46+
services: map[string]bool{},
4747
}
4848
}
4949

@@ -58,7 +58,7 @@ func (c *monitor) withServices(services []string) {
5858
//nolint:gocyclo
5959
func (c *monitor) Start(ctx context.Context) error {
6060
// collect initial application container
61-
initialState, err := c.api.ContainerList(ctx, container.ListOptions{
61+
initialState, err := c.apiClient.ContainerList(ctx, container.ListOptions{
6262
All: true,
6363
Filters: filters.NewArgs(
6464
projectFilter(c.project),
@@ -79,7 +79,7 @@ func (c *monitor) Start(ctx context.Context) error {
7979
}
8080
restarting := utils.Set[string]{}
8181

82-
evtCh, errCh := c.api.Events(ctx, events.ListOptions{
82+
evtCh, errCh := c.apiClient.Events(ctx, events.ListOptions{
8383
Filters: filters.NewArgs(
8484
filters.Arg("type", "container"),
8585
projectFilter(c.project)),
@@ -140,7 +140,7 @@ func (c *monitor) Start(ctx context.Context) error {
140140
logrus.Debugf("container %s restarted", ctr.Name)
141141
case events.ActionDie:
142142
logrus.Debugf("container %s exited with code %d", ctr.Name, ctr.ExitCode)
143-
inspect, err := c.api.ContainerInspect(ctx, event.Actor.ID)
143+
inspect, err := c.apiClient.ContainerInspect(ctx, event.Actor.ID)
144144
if errdefs.IsNotFound(err) {
145145
// Source is already removed
146146
} else if err != nil {

pkg/e2e/compose_up_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func TestUpWait(t *testing.T) {
3232
timeout := time.After(30 * time.Second)
3333
done := make(chan bool)
3434
go func() {
35+
//nolint:nolintlint,testifylint // helper asserts inside goroutine; acceptable in this e2e test
3536
res := c.RunDockerComposeCmd(t, "-f", "fixtures/dependencies/deps-completed-successfully.yaml", "--project-name", projectName, "up", "--wait", "-d")
3637
assert.Assert(t, strings.Contains(res.Combined(), "e2e-deps-wait-oneshot-1"), res.Combined())
3738
done <- true

pkg/e2e/healthcheck_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func TestStartInterval(t *testing.T) {
3939
timeout := time.After(30 * time.Second)
4040
done := make(chan bool)
4141
go func() {
42+
//nolint:nolintlint,testifylint // helper asserts inside goroutine; acceptable in this e2e test
4243
res := c.RunDockerComposeCmd(t, "-f", "fixtures/start_interval/compose.yaml", "--project-name", projectName, "up", "--wait", "-d", "test")
4344
out := res.Combined()
4445
assert.Assert(t, strings.Contains(out, "Healthy"), out)

0 commit comments

Comments
 (0)