mirror of https://github.com/docker/compose.git
Use proper context in storage key retrieval
This commit is contained in:
parent
6552a00004
commit
274dc8283f
|
@ -209,7 +209,7 @@ func (cs *aciContainerService) Run(ctx context.Context, r containers.ContainerCo
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Debugf("Running container %q with name %q\n", r.Image, r.ID)
|
logrus.Debugf("Running container %q with name %q\n", r.Image, r.ID)
|
||||||
groupDefinition, err := convert.ToContainerGroup(cs.ctx, project)
|
groupDefinition, err := convert.ToContainerGroup(ctx, cs.ctx, project)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -410,7 +410,7 @@ func (cs *aciComposeService) Up(ctx context.Context, opts cli.ProjectOptions) er
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
logrus.Debugf("Up on project with name %q\n", project.Name)
|
logrus.Debugf("Up on project with name %q\n", project.Name)
|
||||||
groupDefinition, err := convert.ToContainerGroup(cs.ctx, *project)
|
groupDefinition, err := convert.ToContainerGroup(ctx, cs.ctx, *project)
|
||||||
addTag(&groupDefinition, composeContainerTag)
|
addTag(&groupDefinition, composeContainerTag)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package convert
|
package convert
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -47,7 +48,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// ToContainerGroup converts a compose project into a ACI container group
|
// ToContainerGroup converts a compose project into a ACI container group
|
||||||
func ToContainerGroup(aciContext store.AciContext, p types.Project) (containerinstance.ContainerGroup, error) {
|
func ToContainerGroup(ctx context.Context, aciContext store.AciContext, p types.Project) (containerinstance.ContainerGroup, error) {
|
||||||
project := projectAciHelper(p)
|
project := projectAciHelper(p)
|
||||||
containerGroupName := strings.ToLower(project.Name)
|
containerGroupName := strings.ToLower(project.Name)
|
||||||
loginService, err := login.NewAzureLoginService()
|
loginService, err := login.NewAzureLoginService()
|
||||||
|
@ -58,7 +59,7 @@ func ToContainerGroup(aciContext store.AciContext, p types.Project) (containerin
|
||||||
LoginService: *loginService,
|
LoginService: *loginService,
|
||||||
AciContext: aciContext,
|
AciContext: aciContext,
|
||||||
}
|
}
|
||||||
volumesCache, volumesSlice, err := project.getAciFileVolumes(storageHelper)
|
volumesCache, volumesSlice, err := project.getAciFileVolumes(ctx, storageHelper)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return containerinstance.ContainerGroup{}, err
|
return containerinstance.ContainerGroup{}, err
|
||||||
}
|
}
|
||||||
|
@ -199,7 +200,7 @@ func (p projectAciHelper) getAciSecretVolumes() ([]containerinstance.Volume, err
|
||||||
return secretVolumes, nil
|
return secretVolumes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p projectAciHelper) getAciFileVolumes(helper login.StorageAccountHelper) (map[string]bool, []containerinstance.Volume, error) {
|
func (p projectAciHelper) getAciFileVolumes(ctx context.Context, helper login.StorageAccountHelper) (map[string]bool, []containerinstance.Volume, error) {
|
||||||
azureFileVolumesMap := make(map[string]bool, len(p.Volumes))
|
azureFileVolumesMap := make(map[string]bool, len(p.Volumes))
|
||||||
var azureFileVolumesSlice []containerinstance.Volume
|
var azureFileVolumesSlice []containerinstance.Volume
|
||||||
for name, v := range p.Volumes {
|
for name, v := range p.Volumes {
|
||||||
|
@ -212,7 +213,7 @@ func (p projectAciHelper) getAciFileVolumes(helper login.StorageAccountHelper) (
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, nil, fmt.Errorf("cannot retrieve account name for Azurefile")
|
return nil, nil, fmt.Errorf("cannot retrieve account name for Azurefile")
|
||||||
}
|
}
|
||||||
accountKey, err := helper.GetAzureStorageAccountKey(accountName)
|
accountKey, err := helper.GetAzureStorageAccountKey(ctx, accountName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package convert
|
package convert
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@ func TestProjectName(t *testing.T) {
|
||||||
project := types.Project{
|
project := types.Project{
|
||||||
Name: "TEST",
|
Name: "TEST",
|
||||||
}
|
}
|
||||||
containerGroup, err := ToContainerGroup(convertCtx, project)
|
containerGroup, err := ToContainerGroup(context.TODO(), convertCtx, project)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.Equal(t, *containerGroup.Name, "test")
|
assert.Equal(t, *containerGroup.Name, "test")
|
||||||
}
|
}
|
||||||
|
@ -117,7 +118,7 @@ func TestComposeContainerGroupToContainerWithDnsSideCarSide(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
group, err := ToContainerGroup(convertCtx, project)
|
group, err := ToContainerGroup(context.TODO(), convertCtx, project)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.Assert(t, is.Len(*group.Containers, 3))
|
assert.Assert(t, is.Len(*group.Containers, 3))
|
||||||
|
|
||||||
|
@ -142,7 +143,7 @@ func TestComposeSingleContainerGroupToContainerNoDnsSideCarSide(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
group, err := ToContainerGroup(convertCtx, project)
|
group, err := ToContainerGroup(context.TODO(), convertCtx, project)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
assert.Assert(t, is.Len(*group.Containers, 1))
|
assert.Assert(t, is.Len(*group.Containers, 1))
|
||||||
|
@ -165,7 +166,7 @@ func TestComposeSingleContainerRestartPolicy(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
group, err := ToContainerGroup(convertCtx, project)
|
group, err := ToContainerGroup(context.TODO(), convertCtx, project)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
assert.Assert(t, is.Len(*group.Containers, 1))
|
assert.Assert(t, is.Len(*group.Containers, 1))
|
||||||
|
@ -197,7 +198,7 @@ func TestComposeMultiContainerRestartPolicy(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
group, err := ToContainerGroup(convertCtx, project)
|
group, err := ToContainerGroup(context.TODO(), convertCtx, project)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
assert.Assert(t, is.Len(*group.Containers, 3))
|
assert.Assert(t, is.Len(*group.Containers, 3))
|
||||||
|
@ -231,7 +232,7 @@ func TestComposeInconsistentMultiContainerRestartPolicy(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := ToContainerGroup(convertCtx, project)
|
_, err := ToContainerGroup(context.TODO(), convertCtx, project)
|
||||||
assert.Error(t, err, "ACI integration does not support specifying different restart policies on containers in the same compose application")
|
assert.Error(t, err, "ACI integration does not support specifying different restart policies on containers in the same compose application")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,7 +249,7 @@ func TestLabelsErrorMessage(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := ToContainerGroup(convertCtx, project)
|
_, err := ToContainerGroup(context.TODO(), convertCtx, project)
|
||||||
assert.Error(t, err, "ACI integration does not support labels in compose applications")
|
assert.Error(t, err, "ACI integration does not support labels in compose applications")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,7 +263,7 @@ func TestComposeSingleContainerGroupToContainerDefaultRestartPolicy(t *testing.T
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
group, err := ToContainerGroup(convertCtx, project)
|
group, err := ToContainerGroup(context.TODO(), convertCtx, project)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
assert.Assert(t, is.Len(*group.Containers, 1))
|
assert.Assert(t, is.Len(*group.Containers, 1))
|
||||||
|
@ -296,7 +297,7 @@ func TestComposeContainerGroupToContainerMultiplePorts(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
group, err := ToContainerGroup(convertCtx, project)
|
group, err := ToContainerGroup(context.TODO(), convertCtx, project)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.Assert(t, is.Len(*group.Containers, 3))
|
assert.Assert(t, is.Len(*group.Containers, 3))
|
||||||
|
|
||||||
|
@ -335,7 +336,7 @@ func TestComposeContainerGroupToContainerResourceLimits(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
group, err := ToContainerGroup(convertCtx, project)
|
group, err := ToContainerGroup(context.TODO(), convertCtx, project)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
limits := *((*group.Containers)[0]).Resources.Limits
|
limits := *((*group.Containers)[0]).Resources.Limits
|
||||||
|
@ -361,7 +362,7 @@ func TestComposeContainerGroupToContainerResourceLimitsDefaults(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
group, err := ToContainerGroup(convertCtx, project)
|
group, err := ToContainerGroup(context.TODO(), convertCtx, project)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
limits := *((*group.Containers)[0]).Resources.Limits
|
limits := *((*group.Containers)[0]).Resources.Limits
|
||||||
|
@ -385,7 +386,7 @@ func TestComposeContainerGroupToContainerenvVar(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
group, err := ToContainerGroup(convertCtx, project)
|
group, err := ToContainerGroup(context.TODO(), convertCtx, project)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
envVars := *((*group.Containers)[0]).EnvironmentVariables
|
envVars := *((*group.Containers)[0]).EnvironmentVariables
|
||||||
|
|
|
@ -16,12 +16,12 @@ type StorageAccountHelper struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAzureStorageAccountKey retrieves the storage account ket from the current azure login
|
// GetAzureStorageAccountKey retrieves the storage account ket from the current azure login
|
||||||
func (helper StorageAccountHelper) GetAzureStorageAccountKey(accountName string) (string, error) {
|
func (helper StorageAccountHelper) GetAzureStorageAccountKey(ctx context.Context, accountName string) (string, error) {
|
||||||
client, err := GetStorageAccountsClient(helper.AciContext.SubscriptionID)
|
client, err := GetStorageAccountsClient(helper.AciContext.SubscriptionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
result, err := client.ListKeys(context.TODO(), helper.AciContext.ResourceGroup, accountName, "")
|
result, err := client.ListKeys(ctx, helper.AciContext.ResourceGroup, accountName, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errors.Wrap(err, fmt.Sprintf("could not access storage account acountKeys for %s, using the azure login", accountName))
|
return "", errors.Wrap(err, fmt.Sprintf("could not access storage account acountKeys for %s, using the azure login", accountName))
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
"github.com/docker/api/errdefs"
|
"github.com/docker/api/errdefs"
|
||||||
)
|
)
|
||||||
|
|
||||||
const aciDockerUserAgent = "docker-cli"
|
const userAgent = "docker-cli"
|
||||||
|
|
||||||
// GetContainerGroupsClient get client toi manipulate containerGrouos
|
// GetContainerGroupsClient get client toi manipulate containerGrouos
|
||||||
func GetContainerGroupsClient(subscriptionID string) (containerinstance.ContainerGroupsClient, error) {
|
func GetContainerGroupsClient(subscriptionID string) (containerinstance.ContainerGroupsClient, error) {
|
||||||
|
@ -29,7 +29,7 @@ func GetContainerGroupsClient(subscriptionID string) (containerinstance.Containe
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupClient(aciClient *autorest.Client) error {
|
func setupClient(aciClient *autorest.Client) error {
|
||||||
aciClient.UserAgent = aciDockerUserAgent
|
aciClient.UserAgent = userAgent
|
||||||
auth, err := NewAuthorizerFromLogin()
|
auth, err := NewAuthorizerFromLogin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
|
@ -19,11 +19,11 @@ package aci
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/docker/api/aci/login"
|
|
||||||
|
|
||||||
"github.com/Azure/azure-sdk-for-go/profiles/2019-03-01/resources/mgmt/resources"
|
"github.com/Azure/azure-sdk-for-go/profiles/2019-03-01/resources/mgmt/resources"
|
||||||
"github.com/Azure/azure-sdk-for-go/profiles/preview/preview/subscription/mgmt/subscription"
|
"github.com/Azure/azure-sdk-for-go/profiles/preview/preview/subscription/mgmt/subscription"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
|
"github.com/docker/api/aci/login"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ResourceGroupHelper interface to manage resource groups and subscription IDs
|
// ResourceGroupHelper interface to manage resource groups and subscription IDs
|
||||||
|
|
Loading…
Reference in New Issue