mirror of
https://github.com/docker/compose.git
synced 2025-07-22 13:14:29 +02:00
commit
6a2ce681b4
22
azure/aci.go
22
azure/aci.go
@ -29,10 +29,10 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createACIContainers(ctx context.Context, aciContext store.AciContext, groupDefinition containerinstance.ContainerGroup) (c containerinstance.ContainerGroup, err error) {
|
func createACIContainers(ctx context.Context, aciContext store.AciContext, groupDefinition containerinstance.ContainerGroup) error {
|
||||||
containerGroupsClient, err := getContainerGroupsClient(aciContext.SubscriptionID)
|
containerGroupsClient, err := getContainerGroupsClient(aciContext.SubscriptionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c, errors.Wrapf(err, "cannot get container group client")
|
return errors.Wrapf(err, "cannot get container group client")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the container group already exists
|
// Check if the container group already exists
|
||||||
@ -40,13 +40,13 @@ func createACIContainers(ctx context.Context, aciContext store.AciContext, group
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if err, ok := err.(autorest.DetailedError); ok {
|
if err, ok := err.(autorest.DetailedError); ok {
|
||||||
if err.StatusCode != http.StatusNotFound {
|
if err.StatusCode != http.StatusNotFound {
|
||||||
return c, err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return c, err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return c, fmt.Errorf("container group %q already exists", *groupDefinition.Name)
|
return fmt.Errorf("container group %q already exists", *groupDefinition.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
future, err := containerGroupsClient.CreateOrUpdate(
|
future, err := containerGroupsClient.CreateOrUpdate(
|
||||||
@ -57,16 +57,16 @@ func createACIContainers(ctx context.Context, aciContext store.AciContext, group
|
|||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = future.WaitForCompletionRef(ctx, containerGroupsClient.Client)
|
err = future.WaitForCompletionRef(ctx, containerGroupsClient.Client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c, err
|
return err
|
||||||
}
|
}
|
||||||
containerGroup, err := future.Result(containerGroupsClient)
|
containerGroup, err := future.Result(containerGroupsClient)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(*containerGroup.Containers) > 1 {
|
if len(*containerGroup.Containers) > 1 {
|
||||||
@ -80,7 +80,7 @@ func createACIContainers(ctx context.Context, aciContext store.AciContext, group
|
|||||||
container := containers[0]
|
container := containers[0]
|
||||||
response, err := execACIContainer(ctx, aciContext, "/bin/sh", *containerGroup.Name, *container.Name)
|
response, err := execACIContainer(ctx, aciContext, "/bin/sh", *containerGroup.Name, *container.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = execCommands(
|
if err = execCommands(
|
||||||
@ -89,11 +89,11 @@ func createACIContainers(ctx context.Context, aciContext store.AciContext, group
|
|||||||
*response.Password,
|
*response.Password,
|
||||||
commands,
|
commands,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return containerinstance.ContainerGroup{}, err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return containerGroup, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteACIContainerGroup(ctx context.Context, aciContext store.AciContext, containerGroupName string) (c containerinstance.ContainerGroup, err error) {
|
func deleteACIContainerGroup(ctx context.Context, aciContext store.AciContext, containerGroupName string) (c containerinstance.ContainerGroup, err error) {
|
||||||
|
@ -48,11 +48,11 @@ func New(ctx context.Context) (backend.Service, error) {
|
|||||||
containerGroupsClient := containerinstance.NewContainerGroupsClient(aciContext.SubscriptionID)
|
containerGroupsClient := containerinstance.NewContainerGroupsClient(aciContext.SubscriptionID)
|
||||||
containerGroupsClient.Authorizer = auth
|
containerGroupsClient.Authorizer = auth
|
||||||
|
|
||||||
return getAciApiService(containerGroupsClient, aciContext), nil
|
return getAciAPIService(containerGroupsClient, aciContext), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAciApiService(cgc containerinstance.ContainerGroupsClient, aciCtx store.AciContext) *aciApiService {
|
func getAciAPIService(cgc containerinstance.ContainerGroupsClient, aciCtx store.AciContext) *aciAPIService {
|
||||||
return &aciApiService{
|
return &aciAPIService{
|
||||||
container: aciContainerService{
|
container: aciContainerService{
|
||||||
containerGroupsClient: cgc,
|
containerGroupsClient: cgc,
|
||||||
ctx: aciCtx,
|
ctx: aciCtx,
|
||||||
@ -64,19 +64,19 @@ func getAciApiService(cgc containerinstance.ContainerGroupsClient, aciCtx store.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type aciApiService struct {
|
type aciAPIService struct {
|
||||||
container aciContainerService
|
container aciContainerService
|
||||||
compose aciComposeService
|
compose aciComposeService
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aciApiService) ContainerService() containers.Service {
|
func (a *aciAPIService) ContainerService() containers.Service {
|
||||||
return &aciContainerService{
|
return &aciContainerService{
|
||||||
containerGroupsClient: a.container.containerGroupsClient,
|
containerGroupsClient: a.container.containerGroupsClient,
|
||||||
ctx: a.container.ctx,
|
ctx: a.container.ctx,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aciApiService) ComposeService() compose.Service {
|
func (a *aciAPIService) ComposeService() compose.Service {
|
||||||
return &aciComposeService{
|
return &aciComposeService{
|
||||||
containerGroupsClient: a.compose.containerGroupsClient,
|
containerGroupsClient: a.compose.containerGroupsClient,
|
||||||
ctx: a.compose.ctx,
|
ctx: a.compose.ctx,
|
||||||
@ -152,8 +152,7 @@ func (cs *aciContainerService) Run(ctx context.Context, r containers.ContainerCo
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = createACIContainers(ctx, cs.ctx, groupDefinition)
|
return createACIContainers(ctx, cs.ctx, groupDefinition)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *aciContainerService) Exec(ctx context.Context, name string, command string, reader io.Reader, writer io.Writer) error {
|
func (cs *aciContainerService) Exec(ctx context.Context, name string, command string, reader io.Reader, writer io.Writer) error {
|
||||||
@ -208,8 +207,7 @@ func (cs *aciComposeService) Up(ctx context.Context, opts compose.ProjectOptions
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = createACIContainers(ctx, cs.ctx, groupDefinition)
|
return createACIContainers(ctx, cs.ctx, groupDefinition)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *aciComposeService) Down(ctx context.Context, opts compose.ProjectOptions) error {
|
func (cs *aciComposeService) Down(ctx context.Context, opts compose.ProjectOptions) error {
|
||||||
|
@ -29,7 +29,7 @@ var backends = struct {
|
|||||||
r []*registeredBackend
|
r []*registeredBackend
|
||||||
}{}
|
}{}
|
||||||
|
|
||||||
// Aggregation of service interfaces
|
// Service aggregates the service interfaces
|
||||||
type Service interface {
|
type Service interface {
|
||||||
ContainerService() containers.Service
|
ContainerService() containers.Service
|
||||||
ComposeService() compose.Service
|
ComposeService() compose.Service
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/docker/api/compose"
|
"github.com/docker/api/compose"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Command returns the compose command with its child commands
|
||||||
func Command() *cobra.Command {
|
func Command() *cobra.Command {
|
||||||
command := &cobra.Command{
|
command := &cobra.Command{
|
||||||
Short: "Docker Compose",
|
Short: "Docker Compose",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user