Repository: docker/compose-cli (go)

Issue:
`docker context create aci` --location flag seems to have no effect.
<!--
If you are reporting a new issue, make sure that we do not have any duplicates
already open. You can ensure this by searching the issue list for this
repository. If there is a duplicate, please close your issue and add a comment
to the existing issue instead.

If you suspect your issue is a bug, please edit your issue description to
include the BUG REPORT INFORMATION shown below. If you fail to provide this
information within 7 days, we cannot debug your issue and will close it. We
will, however, reopen it if you later provide the information.

For more information about reporting issues, see
https://github.com/docker/compose-cli/blob/master/CONTRIBUTING.md#reporting-other-issues

---------------------------------------------------
GENERAL SUPPORT INFORMATION
---------------------------------------------------

The GitHub issue tracker is for bug reports and feature requests.
General support can be found at the following locations:

- Docker Support Forums - https://forums.docker.com
- Docker Community Slack - https://dockr.ly/community
- Post a question on StackOverflow, using the Docker tag

---------------------------------------------------
BUG REPORT INFORMATION
---------------------------------------------------
Use the commands below to provide key information from your environment:
You do NOT have to include this information if this is a FEATURE REQUEST
-->
When using docker compose to deploy a container group to Azure Container Instances, the `--location` argument specified when creating the docker context for aci, `docker context create aci...`, appears to have no effect.

I'm following [these azure instructions](https://docs.microsoft.com/en-us/azure/container-instances/tutorial-docker-compose) for using docker compose with azure container instances
and [this docker documentation](https://docs.docker.com/cloud/aci-integration/#create-an-aci-context) showing the additional arguments for the `docker context create` command

The ultimate manifestation of this issue is that I am unable to create a container group in azure because I'm working in the context of a resource group _which I cannot change_, but the resource group is in a location that does not support Azure Container Instances.
When I try and issue the `docker-compose up` command in the aci context that I *thought* I created in a location that *supports* azure container instances, I get a location not supported error, listing the location of the resource group and not the location I specified for the docker aci context.

Am I misunderstanding the purpose of the `--location` parameter?

I know you *can* mix and match locations between a container instance and a resource group because I am able to create a container instance via azure cli with a location different to that of the resource group that it is linked to.

**Steps to reproduce the issue:**
 1. Log into azure via the cli `az login`
 2. Authenticate docker with azure `docker login azure`
 3. Create an azure resource group in a specific location `az group create -l uksouth -n test-aci-ctx-group`
 4. Create a docker context specifying a location different to the resource group location `docker context create aci aci-context-eastus --resource-group test-aci-ctx-group --location eastus`
 
**Describe the results you received:**
a context bound to the same location as the azure resource group, i.e., uksouth

**Describe the results you expected:**
a context bound to the location specified as `--location` for the `docker context create` command, i.e.,  eastus

**Additional information you deem important (e.g. issue happens only occasionally):**

**Output of `docker version`:**

```
Docker version 20.10.5, build 55c4c88
```

**Output of `docker context show`:**  
```
[
    {
        "Name": "aci-context-eastus",
        "Metadata": {
            "Description": "test-aci-ctx-group@uksouth",
            "Type": "aci"
        },
        "Endpoints": {
            "aci": {
                "Location": "uksouth",
                "ResourceGroup": "test-aci-ctx-group",
                "SubscriptionID": "xxxxxxxxxxxxxxxxxxx"
            },
            "docker": {
                "SkipTLSVerify": false
            }
        },
        "TLSMaterial": {},
        "Storage": {
            "MetadataPath": "xxxx",
            "TLSPath": "xxxx"
        }
    }
]
```

**Output of `docker info`:**

```
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
  scan: Docker Scan (Docker Inc., v0.6.0)

Server:
 Containers: 13
  Running: 3
  Paused: 0
  Stopped: 10
 Images: 71
 Server Version: 20.10.5
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 05f951a3781f4f2c1911b05e61c160e9c30eaa8e
 runc version: 12644e614e25b05da6fd08a38ffa0cfe1903fdec
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 5.4.72-microsoft-standard-WSL2
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 16
 Total Memory: 49.72GiB
 Name: docker-desktop
 ID: 2QSF:BLXR:WIR6:Q3BE:FNRD:SBHI:JNS7:PTVJ:OOFF:Q6AQ:AUSU:W2WS
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support
```

**Additional environment details (AWS ECS, Azure ACI, local, etc.):**
**Output of `az  version`:**
```
{
  "azure-cli": "2.22.1",
  "azure-cli-core": "2.22.1",
  "azure-cli-telemetry": "1.0.6",
  "extensions": {}
}
```

Not sure if this is relevant but issuing the `docker info` command when in the non-default docker context, the following message was returned
`Command "info" not available in current context (aci-context-eastus), you can use the "default" context to run this command`

Pull request:
Use location specified by user if provided, and do not override with group location
ACI allow deploying in any location regardless of resource group

Signed-off-by: Guillaume Tardif <guillaume.tardif@gmail.com>

**What I did**
Do not always use resource group location, keep user location option if provided

**Related issue**
Fixes #1589 

<!-- 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
-->
/test-aci

**(not mandatory) A picture of a cute animal, if possible in relation with what you did**
![](https://www.pngkit.com/png/detail/127-1279908_share-this-image-steampunk-octopus-tattoo.png)


Patch:
diff --git a/aci/context.go b/aci/context.go
index 7f9cdb4c..2ce1b6c1 100644
--- a/aci/context.go
+++ b/aci/context.go
@@ -99,7 +99,10 @@ func (helper contextCreateACIHelper) createContextData(ctx context.Context, opts
 		}
 	}
 
-	location := *group.Location
+	location := opts.Location
+	if opts.Location == "" {
+		location = *group.Location
+	}
 
 	description := fmt.Sprintf("%s@%s", *group.Name, location)
 	if opts.Description != "" {
diff --git a/builder.Makefile b/builder.Makefile
index 65d50240..79c7b0f0 100644
--- a/builder.Makefile
+++ b/builder.Makefile
@@ -28,7 +28,7 @@ STATIC_FLAGS=CGO_ENABLED=0
 
 GIT_TAG?=$(shell git describe --tags --match "v[0-9]*")
 
-LDFLAGS="-s -w -X $(PKG_NAME)/internal.Version=${GIT_TAG} -X $(PKG_NAME)/internal.ComposePluginVersion=2.0.0-beta.2"
+LDFLAGS="-s -w -X $(PKG_NAME)/internal.Version=${GIT_TAG} -X $(PKG_NAME)/internal.ComposePluginVersion=2.0.0-beta.1"
 GO_BUILD=$(STATIC_FLAGS) go build -trimpath -ldflags=$(LDFLAGS)
 
 BINARY?=bin/docker
diff --git a/cli/cmd/context/create_aci.go b/cli/cmd/context/create_aci.go
index 3efaee52..775fd810 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", "eastus", "Location")
-	cmd.Flags().StringVar(&opts.SubscriptionID, "subscription-id", "", "Location")
+	cmd.Flags().StringVar(&opts.Location, "location", "", "Location")
+	cmd.Flags().StringVar(&opts.SubscriptionID, "subscription-id", "", "Subscription id")
 	cmd.Flags().StringVar(&opts.ResourceGroup, "resource-group", "", "Resource group")
 
 	return cmd


Test patch:
diff --git a/aci/context_test.go b/aci/context_test.go
index 88d72656..51a384e3 100644
--- a/aci/context_test.go
+++ b/aci/context_test.go
@@ -107,6 +107,28 @@ 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", "")
@@ -194,7 +216,6 @@ func options(subscriptionID string, resourceGroupName string) ContextParams {
 	return ContextParams{
 		SubscriptionID: subscriptionID,
 		ResourceGroup:  resourceGroupName,
-		Location:       "eastus",
 	}
 }