Skip to content

Commit

Permalink
Don't share the options map
Browse files Browse the repository at this point in the history
Without this I get an exception when building multiple images in a
compose run.

```
fatal error: concurrent map writes

goroutine 16 [running]:
github.com/docker/compose/v2/pkg/compose.(*composeService).build.func1({0x2cba4e0, 0xc00019b2c0}, {0xc000233150?, 0xd?})
        github.com/docker/compose/v2/pkg/compose/build.go:95 +0x652
github.com/docker/compose/v2/pkg/compose.(*graphTraversal).run.func1()
        github.com/docker/compose/v2/pkg/compose/dependencies.go:127 +0x63
golang.org/x/sync/errgroup.(*Group).Go.func1()
        golang.org/x/[email protected]/errgroup/errgroup.go:75 +0x64
created by golang.org/x/sync/errgroup.(*Group).Go
        golang.org/x/[email protected]/errgroup/errgroup.go:72 +0xa5
...
```

I'm not sure why the map is currently shared, but with this patch
applied my docker-compose build run works.

Signed-off-by: Edward Muller <[email protected]>
  • Loading branch information
freeformz authored and glours committed Jan 9, 2023
1 parent fbbc0de commit 73ebbff
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions pkg/compose/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func (s *composeService) Build(ctx context.Context, project *types.Project, opti
}

func (s *composeService) build(ctx context.Context, project *types.Project, options api.BuildOptions) error {
opts := map[string]build.Options{}
args := flatten(options.Args.Resolve(envResolver(project.Environment)))

return InDependencyOrder(ctx, project, func(ctx context.Context, name string) error {
Expand Down Expand Up @@ -92,7 +91,7 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
Attrs: map[string]string{},
}}
}
opts[imageName] = buildOptions
opts := map[string]build.Options{imageName: buildOptions}
_, err = s.doBuild(ctx, project, opts, options.Progress)
return err
}, func(traversal *graphTraversal) {
Expand Down

0 comments on commit 73ebbff

Please sign in to comment.