Repository: docker/compose-cli
Pull request #1647 (2021-05-06 07:45:07)

Avoid using for variable in go func, as this creates race conditions
Signed-off-by: Guillaume Tardif <guillaume.tardif@gmail.com>

**What I did**
Update VSCode and saw this nice warning for a quite common race issue : 

![Screenshot 2021-05-06 at 09 28 58](https://user-images.githubusercontent.com/437958/117260676-9c212780-ae4f-11eb-9ddb-2fe0d97aef46.png)


**Related issue**
<!-- If this is a bug fix, make sure your description includes "fixes #xxxx", or "closes #xxxx" -->

<!-- optional tests
You can add a / mention to run tests executed by default only on main branch :
* `test-kube` to run Kube E2E tests
* `test-aci` to run ACI E2E tests
* `test-ecs` to run ECS E2E tests
* `test-windows` to run tests & E2E tests on windows
-->

**(not mandatory) A picture of a cute animal, if possible in relation with what you did**



Patch:
diff --git a/aci/context.go b/aci/context.go
index 2ce1b6c1..7f9cdb4c 100644
--- a/aci/context.go
+++ b/aci/context.go
@@ -99,10 +99,7 @@ func (helper contextCreateACIHelper) createContextData(ctx context.Context, opts
 		}
 	}
 
-	location := opts.Location
-	if opts.Location == "" {
-		location = *group.Location
-	}
+	location := *group.Location
 
 	description := fmt.Sprintf("%s@%s", *group.Name, location)
 	if opts.Description != "" {
diff --git a/cli/cmd/context/create_aci.go b/cli/cmd/context/create_aci.go
index 775fd810..3efaee52 100644
--- a/cli/cmd/context/create_aci.go
+++ b/cli/cmd/context/create_aci.go
@@ -49,8 +49,8 @@ func createAciCommand() *cobra.Command {
 	}
 
 	addDescriptionFlag(cmd, &opts.Description)
-	cmd.Flags().StringVar(&opts.Location, "location", "", "Location")
-	cmd.Flags().StringVar(&opts.SubscriptionID, "subscription-id", "", "Subscription id")
+	cmd.Flags().StringVar(&opts.Location, "location", "eastus", "Location")
+	cmd.Flags().StringVar(&opts.SubscriptionID, "subscription-id", "", "Location")
 	cmd.Flags().StringVar(&opts.ResourceGroup, "resource-group", "", "Resource group")
 
 	return cmd
diff --git a/go.mod b/go.mod
index 79c96e5f..d73235c1 100644
--- a/go.mod
+++ b/go.mod
@@ -17,7 +17,7 @@ require (
 	github.com/awslabs/goformation/v4 v4.15.6
 	github.com/buger/goterm v1.0.0
 	github.com/cnabio/cnab-to-oci v0.3.1-beta1
-	github.com/compose-spec/compose-go v0.0.0-20210505145624-6dcd3d18b38b
+	github.com/compose-spec/compose-go v0.0.0-20210503135708-e8ee37c1478c
 	github.com/containerd/console v1.0.1
 	github.com/containerd/containerd v1.4.3
 	github.com/containerd/continuity v0.0.0-20200928162600-f2cc35102c2a // indirect
diff --git a/go.sum b/go.sum
index 491e1cb7..b23692ea 100644
--- a/go.sum
+++ b/go.sum
@@ -308,8 +308,8 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX
 github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
 github.com/codahale/hdrhistogram v0.0.0-20160425231609-f8ad88b59a58/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
 github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
-github.com/compose-spec/compose-go v0.0.0-20210505145624-6dcd3d18b38b h1:0MPA42m4n8VGsCld8hWmeRYeblPrgRDbiXPvRnjWoLY=
-github.com/compose-spec/compose-go v0.0.0-20210505145624-6dcd3d18b38b/go.mod h1:6eIT9U2OgdHmkRD6szmqatCrWWEEUSwl/j2iJYH4jLo=
+github.com/compose-spec/compose-go v0.0.0-20210503135708-e8ee37c1478c h1:XDrhClIbE/zCDU4KWCYSYmceYZj5EBn3DMhQ7hVvyUs=
+github.com/compose-spec/compose-go v0.0.0-20210503135708-e8ee37c1478c/go.mod h1:6eIT9U2OgdHmkRD6szmqatCrWWEEUSwl/j2iJYH4jLo=
 github.com/containerd/cgroups v0.0.0-20190919134610-bf292b21730f/go.mod h1:OApqhQ4XNSNC13gXIwDjhOQxjWa/NxkwZXJ1EvqT0ko=
 github.com/containerd/cgroups v0.0.0-20200531161412-0dbf7f05ba59/go.mod h1:pA0z1pT8KYB3TCXK/ocprsh7MAkoW8bZVzPdih9snmM=
 github.com/containerd/cgroups v0.0.0-20200710171044-318312a37340 h1:9atoWyI9RtXFwf7UDbme/6M8Ud0rFrx+Q3ZWgSnsxtw=
diff --git a/local/compose/convergence.go b/local/compose/convergence.go
index d394ad62..a46ff065 100644
--- a/local/compose/convergence.go
+++ b/local/compose/convergence.go
@@ -147,6 +147,7 @@ func getContainerProgressName(container moby.Container) string {
 func (s *composeService) waitDependencies(ctx context.Context, project *types.Project, service types.ServiceConfig) error {
 	eg, _ := errgroup.WithContext(ctx)
 	for dep, config := range service.DependsOn {
+		dep, config := dep, config
 		eg.Go(func() error {
 			ticker := time.NewTicker(500 * time.Millisecond)
 			defer ticker.Stop()


Test patch:
diff --git a/aci/context_test.go b/aci/context_test.go
index 51a384e3..88d72656 100644
--- a/aci/context_test.go
+++ b/aci/context_test.go
@@ -107,28 +107,6 @@ func TestCreateNewResourceGroup(t *testing.T) {
 	assert.DeepEqual(t, data, aciContext("1234", "newResourceGroup", "eastus"))
 }
 
-func TestCreateNewResourceGroupWithSpecificLocation(t *testing.T) {
-	ctx := context.TODO()
-	opts := options("1234", "")
-	opts.Location = "eastus2"
-	m := testContextMocks()
-	m.resourceGroupHelper.On("GetSubscriptionIDs", ctx).Return([]subscription.Model{subModel("1234", "Subscription1")}, nil)
-	m.resourceGroupHelper.On("GetGroup", ctx, "1234", "myResourceGroup").Return(group("myResourceGroup", "eastus"), nil)
-
-	selectOptions := []string{"create a new resource group", "group1 (eastus)", "group2 (westeurope)"}
-	m.userPrompt.On("Select", "Select a resource group", selectOptions).Return(0, nil)
-	m.resourceGroupHelper.On("CreateOrUpdate", ctx, "1234", mock.AnythingOfType("string"), mock.AnythingOfType("resources.Group")).Return(group("newResourceGroup", "eastus"), nil)
-	m.resourceGroupHelper.On("ListGroups", ctx, "1234").Return([]resources.Group{
-		group("group1", "eastus"),
-		group("group2", "westeurope"),
-	}, nil)
-
-	data, description, err := m.contextCreateHelper.createContextData(ctx, opts)
-	assert.NilError(t, err)
-	assert.Equal(t, description, "newResourceGroup@eastus2")
-	assert.DeepEqual(t, data, aciContext("1234", "newResourceGroup", "eastus2"))
-}
-
 func TestSelectExistingResourceGroup(t *testing.T) {
 	ctx := context.TODO()
 	opts := options("1234", "")
@@ -216,6 +194,7 @@ func options(subscriptionID string, resourceGroupName string) ContextParams {
 	return ContextParams{
 		SubscriptionID: subscriptionID,
 		ResourceGroup:  resourceGroupName,
+		Location:       "eastus",
 	}
 }
 
diff --git a/local/e2e/compose/compose_build_test.go b/local/e2e/compose/compose_build_test.go
index c49f8168..75076962 100644
--- a/local/e2e/compose/compose_build_test.go
+++ b/local/e2e/compose/compose_build_test.go
@@ -17,10 +17,7 @@
 package e2e
 
 import (
-	"io/ioutil"
 	"net/http"
-	"os"
-	"path/filepath"
 	"strings"
 	"testing"
 	"time"
@@ -109,41 +106,3 @@ func TestLocalComposeBuild(t *testing.T) {
 		c.RunDockerCmd("rmi", "custom-nginx")
 	})
 }
-
-func TestLocalComposeBuildStaticDockerfilePath(t *testing.T) {
-	c := NewParallelE2eCLI(t, binDir)
-
-	t.Run("build ddev-style compose files", func(t *testing.T) {
-		dir, err := ioutil.TempDir("", "ddev")
-		assert.NilError(t, err)
-		defer os.RemoveAll(dir) //nolint:errcheck
-
-		assert.NilError(t, ioutil.WriteFile(filepath.Join(dir, "docker-compose.yml"), []byte(`services:
-  service1:
-    build:
-      context: `+dir+`/service1
-      dockerfile: Dockerfile
-  service2:
-    build:
-      context: `+dir+`/service2
-      dockerfile: `+dir+`/service2/Dockerfile
-  `), 0644))
-
-		assert.NilError(t, os.Mkdir(filepath.Join(dir, "service1"), 0700))
-		assert.NilError(t, ioutil.WriteFile(filepath.Join(dir, "service1", "Dockerfile"), []byte(`FROM alpine
-		RUN echo "hello"
-		`), 0644))
-
-		assert.NilError(t, os.Mkdir(filepath.Join(dir, "service2"), 0700))
-		assert.NilError(t, ioutil.WriteFile(filepath.Join(dir, "service2", "Dockerfile"), []byte(`FROM alpine
-		RUN echo "world"
-		`), 0644))
-
-		res := c.RunDockerCmd("compose", "-f", filepath.Join(dir, "docker-compose.yml"), "build")
-
-		res.Assert(t, icmd.Expected{Out: `RUN echo "hello"`})
-		res.Assert(t, icmd.Expected{Out: `RUN echo "world"`})
-
-		c.RunDockerCmd("compose", "-f", filepath.Join(dir, "docker-compose.yml"), "down", "--rmi", "all")
-	})
-}