2020-06-18 17:13:24 +03:00
/ *
Copyright 2020 Docker , Inc .
Licensed under the Apache License , Version 2.0 ( the "License" ) ;
you may not use this file except in compliance with the License .
You may obtain a copy of the License at
http : //www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing , software
distributed under the License is distributed on an "AS IS" BASIS ,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
See the License for the specific language governing permissions and
limitations under the License .
* /
2020-07-29 16:12:45 +03:00
package aci
2020-04-29 20:57:53 +03:00
import (
"context"
2020-05-03 14:41:45 +03:00
"fmt"
2020-08-17 18:48:52 +03:00
"io"
2020-05-10 23:37:28 +03:00
"net/http"
2020-05-04 17:38:02 +03:00
"strconv"
"strings"
2020-04-29 20:57:53 +03:00
"github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2018-10-01/containerinstance"
2020-08-12 11:35:15 +03:00
"github.com/Azure/go-autorest/autorest"
2020-06-30 13:23:22 +03:00
"github.com/Azure/go-autorest/autorest/to"
2020-05-01 16:28:44 +03:00
"github.com/compose-spec/compose-go/types"
2020-04-29 20:57:53 +03:00
"github.com/pkg/errors"
2020-05-01 16:28:44 +03:00
"github.com/sirupsen/logrus"
2020-08-21 18:24:53 +03:00
"github.com/docker/compose-cli/aci/convert"
"github.com/docker/compose-cli/aci/login"
2020-09-07 14:22:08 +03:00
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/containers"
"github.com/docker/compose-cli/api/secrets"
2020-08-21 18:24:53 +03:00
"github.com/docker/compose-cli/backend"
apicontext "github.com/docker/compose-cli/context"
"github.com/docker/compose-cli/context/cloud"
"github.com/docker/compose-cli/context/store"
"github.com/docker/compose-cli/errdefs"
2020-04-29 20:57:53 +03:00
)
2020-07-03 11:53:50 +03:00
const (
2020-07-29 17:05:13 +03:00
backendType = store . AciContextType
2020-07-10 15:27:55 +03:00
singleContainerTag = "docker-single-container"
composeContainerTag = "docker-compose-application"
2020-07-03 11:53:50 +03:00
composeContainerSeparator = "_"
)
2020-05-06 18:14:53 +03:00
2020-07-13 11:38:29 +03:00
// ContextParams options for creating ACI context
type ContextParams struct {
Description string
Location string
SubscriptionID string
ResourceGroup string
}
// LoginParams azure login options
type LoginParams struct {
2020-08-10 17:38:59 +03:00
TenantID string
ClientID string
ClientSecret string
}
// Validate returns an error if options are not used properly
func ( opts LoginParams ) Validate ( ) error {
if opts . ClientID != "" || opts . ClientSecret != "" {
if opts . ClientID == "" || opts . ClientSecret == "" || opts . TenantID == "" {
return errors . New ( "for Service Principal login, 3 options must be specified: --client-id, --client-secret and --tenant-id" )
}
}
return nil
2020-07-13 11:38:29 +03:00
}
2020-04-29 20:57:53 +03:00
func init ( ) {
2020-07-29 16:12:45 +03:00
backend . Register ( backendType , backendType , service , getCloudService )
2020-04-29 20:57:53 +03:00
}
2020-05-28 18:37:59 +03:00
func service ( ctx context . Context ) ( backend . Service , error ) {
2020-05-20 18:15:56 +03:00
contextStore := store . ContextStore ( ctx )
2020-05-28 18:37:59 +03:00
currentContext := apicontext . CurrentContext ( ctx )
Change the way a context is stored
Initially we stored the context data in the `Metadata` of the context
but in hindsight this data would be better of in the `Endpoints` because
that's what it is used for.
Before:
```json
{
"Name": "aci",
"Metadata": {
"Type": "aci",
"Data": {
"key": "value"
}
},
"Endpoints": {
"docker": {}
}
}
```
After:
```json
{
"Name": "aci",
"Type": "aci",
"Metadata": {},
"Endpoints": {
"aci": {
"key": "value"
},
"docker": {}
}
}
```
With this change the contexts that we create are more in line with the contexts the docker cli creates.
It also makes the code less complicated since we don't need to marsal twice any more. The API is nicer too:
```go
// Get a context:
c, err := store.Get(contextName)
// Get the stored endpoint:
var aciContext store.AciContext
if err := contextStore.GetEndpoint(currentContext, &aciContext); err != nil {
return nil, err
}
```
2020-05-22 12:16:01 +03:00
var aciContext store . AciContext
2020-05-28 18:37:59 +03:00
Change the way a context is stored
Initially we stored the context data in the `Metadata` of the context
but in hindsight this data would be better of in the `Endpoints` because
that's what it is used for.
Before:
```json
{
"Name": "aci",
"Metadata": {
"Type": "aci",
"Data": {
"key": "value"
}
},
"Endpoints": {
"docker": {}
}
}
```
After:
```json
{
"Name": "aci",
"Type": "aci",
"Metadata": {},
"Endpoints": {
"aci": {
"key": "value"
},
"docker": {}
}
}
```
With this change the contexts that we create are more in line with the contexts the docker cli creates.
It also makes the code less complicated since we don't need to marsal twice any more. The API is nicer too:
```go
// Get a context:
c, err := store.Get(contextName)
// Get the stored endpoint:
var aciContext store.AciContext
if err := contextStore.GetEndpoint(currentContext, &aciContext); err != nil {
return nil, err
}
```
2020-05-22 12:16:01 +03:00
if err := contextStore . GetEndpoint ( currentContext , & aciContext ) ; err != nil {
return nil , err
2020-04-29 20:57:53 +03:00
}
2020-05-28 18:37:59 +03:00
return getAciAPIService ( aciContext ) , nil
2020-05-05 16:37:12 +03:00
}
2020-05-28 18:37:59 +03:00
func getCloudService ( ) ( cloud . Service , error ) {
2020-05-14 00:33:16 +03:00
service , err := login . NewAzureLoginService ( )
if err != nil {
return nil , err
}
2020-05-28 18:37:59 +03:00
return & aciCloudService {
loginService : service ,
} , nil
}
func getAciAPIService ( aciCtx store . AciContext ) * aciAPIService {
2020-05-05 17:27:22 +03:00
return & aciAPIService {
2020-05-28 18:37:59 +03:00
aciContainerService : & aciContainerService {
2020-05-28 11:16:42 +03:00
ctx : aciCtx ,
2020-05-05 16:37:12 +03:00
} ,
2020-05-28 18:37:59 +03:00
aciComposeService : & aciComposeService {
2020-05-13 00:00:58 +03:00
ctx : aciCtx ,
2020-05-05 16:37:12 +03:00
} ,
2020-05-28 18:37:59 +03:00
}
2020-05-05 16:37:12 +03:00
}
2020-05-05 17:27:22 +03:00
type aciAPIService struct {
2020-05-28 18:37:59 +03:00
* aciContainerService
* aciComposeService
2020-04-29 20:57:53 +03:00
}
2020-05-05 17:27:22 +03:00
func ( a * aciAPIService ) ContainerService ( ) containers . Service {
2020-05-28 18:37:59 +03:00
return a . aciContainerService
2020-05-05 16:37:12 +03:00
}
2020-05-05 17:27:22 +03:00
func ( a * aciAPIService ) ComposeService ( ) compose . Service {
2020-05-28 18:37:59 +03:00
return a . aciComposeService
2020-05-12 14:37:28 +03:00
}
2020-08-18 10:13:58 +03:00
func ( a * aciAPIService ) SecretsService ( ) secrets . Service {
return nil
}
2020-05-05 16:37:12 +03:00
type aciContainerService struct {
2020-05-28 11:16:42 +03:00
ctx store . AciContext
2020-05-05 16:37:12 +03:00
}
2020-08-12 12:59:36 +03:00
func ( cs * aciContainerService ) List ( ctx context . Context , all bool ) ( [ ] containers . Container , error ) {
2020-09-04 19:11:02 +03:00
containerGroups , err := getContainerGroups ( ctx , cs . ctx . SubscriptionID , cs . ctx . ResourceGroup )
2020-04-29 20:57:53 +03:00
if err != nil {
return [ ] containers . Container { } , err
}
2020-05-05 11:58:24 +03:00
var res [ ] containers . Container
2020-09-04 19:11:02 +03:00
for _ , group := range containerGroups {
2020-08-12 12:59:36 +03:00
if group . Containers == nil || len ( * group . Containers ) < 1 {
2020-09-04 19:11:02 +03:00
return [ ] containers . Container { } , fmt . Errorf ( "no containers found in ACI container group %s" , * group . Name )
2020-07-09 00:31:01 +03:00
}
2020-05-04 10:57:52 +03:00
for _ , container := range * group . Containers {
2020-08-28 15:38:51 +03:00
if isContainerVisible ( container , group , all ) {
2020-06-18 16:51:13 +03:00
continue
}
2020-08-28 15:38:51 +03:00
c := convert . ContainerGroupToContainer ( getContainerID ( group , container ) , group , container )
2020-07-09 00:31:01 +03:00
res = append ( res , c )
2020-04-29 20:57:53 +03:00
}
}
return res , nil
}
2020-05-01 16:28:44 +03:00
2020-09-04 19:11:02 +03:00
func getContainerGroups ( ctx context . Context , subscriptionID string , resourceGroup string ) ( [ ] containerinstance . ContainerGroup , error ) {
groupsClient , err := login . NewContainerGroupsClient ( subscriptionID )
if err != nil {
return nil , err
}
var containerGroups [ ] containerinstance . ContainerGroup
result , err := groupsClient . ListByResourceGroup ( ctx , resourceGroup )
if err != nil {
return [ ] containerinstance . ContainerGroup { } , err
}
for result . NotDone ( ) {
containerGroups = append ( containerGroups , result . Values ( ) ... )
if err := result . NextWithContext ( ctx ) ; err != nil {
return [ ] containerinstance . ContainerGroup { } , err
}
}
2020-09-07 15:26:10 +03:00
var groups [ ] containerinstance . ContainerGroup
for _ , group := range containerGroups {
group , err := groupsClient . Get ( ctx , resourceGroup , * group . Name )
if err != nil {
return [ ] containerinstance . ContainerGroup { } , err
}
groups = append ( groups , group )
}
return groups , nil
2020-09-04 19:11:02 +03:00
}
2020-08-28 15:38:51 +03:00
func getContainerID ( group containerinstance . ContainerGroup , container containerinstance . Container ) string {
containerID := * group . Name + composeContainerSeparator + * container . Name
if _ , ok := group . Tags [ singleContainerTag ] ; ok {
containerID = * group . Name
}
return containerID
}
func isContainerVisible ( container containerinstance . Container , group containerinstance . ContainerGroup , showAll bool ) bool {
2020-09-04 16:09:57 +03:00
return * container . Name == convert . ComposeDNSSidecarName || ( ! showAll && convert . GetStatus ( container , group ) != convert . StatusRunning )
2020-08-28 15:38:51 +03:00
}
2020-05-05 16:37:12 +03:00
func ( cs * aciContainerService ) Run ( ctx context . Context , r containers . ContainerConfig ) error {
2020-07-03 11:53:50 +03:00
if strings . Contains ( r . ID , composeContainerSeparator ) {
2020-07-03 16:39:44 +03:00
return errors . New ( fmt . Sprintf ( "invalid container name. ACI container name cannot include %q" , composeContainerSeparator ) )
2020-07-03 11:53:50 +03:00
}
2020-07-09 00:31:01 +03:00
project , err := convert . ContainerToComposeProject ( r )
2020-05-07 05:58:04 +03:00
if err != nil {
return err
}
2020-05-01 16:28:44 +03:00
logrus . Debugf ( "Running container %q with name %q\n" , r . Image , r . ID )
2020-08-14 18:01:35 +03:00
groupDefinition , err := convert . ToContainerGroup ( ctx , cs . ctx , project )
2020-05-01 16:48:20 +03:00
if err != nil {
return err
}
2020-07-16 11:01:49 +03:00
addTag ( & groupDefinition , singleContainerTag )
2020-05-01 16:48:20 +03:00
2020-07-10 15:27:55 +03:00
return createACIContainers ( ctx , cs . ctx , groupDefinition )
}
2020-07-16 11:01:49 +03:00
func addTag ( groupDefinition * containerinstance . ContainerGroup , tagName string ) {
2020-07-09 00:31:01 +03:00
if groupDefinition . Tags == nil {
groupDefinition . Tags = make ( map [ string ] * string , 1 )
}
2020-07-16 11:01:49 +03:00
groupDefinition . Tags [ tagName ] = to . StringPtr ( tagName )
2020-05-01 16:28:44 +03:00
}
2020-05-03 14:35:25 +03:00
2020-08-12 11:35:15 +03:00
func ( cs * aciContainerService ) Start ( ctx context . Context , containerID string ) error {
groupName , containerName := getGroupAndContainerName ( containerID )
if groupName != containerID {
2020-08-12 16:10:54 +03:00
msg := "cannot start specified service %q from compose application %q, you can update and restart the entire compose app with docker compose up --project-name %s"
2020-08-12 11:35:15 +03:00
return errors . New ( fmt . Sprintf ( msg , containerName , groupName , groupName ) )
}
2020-08-14 18:07:33 +03:00
containerGroupsClient , err := login . NewContainerGroupsClient ( cs . ctx . SubscriptionID )
2020-08-12 11:35:15 +03:00
if err != nil {
return err
}
future , err := containerGroupsClient . Start ( ctx , cs . ctx . ResourceGroup , containerName )
if err != nil {
var aerr autorest . DetailedError
if ok := errors . As ( err , & aerr ) ; ok {
if aerr . StatusCode == http . StatusNotFound {
return errdefs . ErrNotFound
}
}
return err
}
return future . WaitForCompletionRef ( ctx , containerGroupsClient . Client )
}
2020-08-11 18:49:02 +03:00
func ( cs * aciContainerService ) Stop ( ctx context . Context , containerID string , timeout * uint32 ) error {
if timeout != nil && * timeout != uint32 ( 0 ) {
return errors . Errorf ( "ACI integration does not support setting a timeout to stop a container before killing it." )
}
groupName , containerName := getGroupAndContainerName ( containerID )
if groupName != containerID {
msg := "cannot stop service %q from compose application %q, you can stop the entire compose app with docker stop %s"
return errors . New ( fmt . Sprintf ( msg , containerName , groupName , groupName ) )
}
return stopACIContainerGroup ( ctx , cs . ctx , groupName )
2020-05-16 13:13:51 +03:00
}
2020-09-01 17:06:07 +03:00
func ( cs * aciContainerService ) Kill ( ctx context . Context , containerID string , _ string ) error {
groupName , containerName := getGroupAndContainerName ( containerID )
if groupName != containerID {
msg := "cannot kill service %q from compose application %q, you can kill the entire compose app with docker kill %s"
return errors . New ( fmt . Sprintf ( msg , containerName , groupName , groupName ) )
}
return stopACIContainerGroup ( ctx , cs . ctx , groupName ) // As ACI doesn't have a kill command, we are using the stop implementation instead
}
2020-07-09 00:31:01 +03:00
func getGroupAndContainerName ( containerID string ) ( string , string ) {
2020-07-03 11:53:50 +03:00
tokens := strings . Split ( containerID , composeContainerSeparator )
2020-07-09 00:31:01 +03:00
groupName := tokens [ 0 ]
containerName := groupName
2020-05-06 18:14:53 +03:00
if len ( tokens ) > 1 {
containerName = tokens [ len ( tokens ) - 1 ]
groupName = containerID [ : len ( containerID ) - ( len ( containerName ) + 1 ) ]
}
return groupName , containerName
}
2020-07-08 15:31:27 +03:00
func ( cs * aciContainerService ) Exec ( ctx context . Context , name string , request containers . ExecRequest ) error {
err := verifyExecCommand ( request . Command )
2020-07-06 04:29:48 +03:00
if err != nil {
return err
}
2020-05-18 15:56:32 +03:00
groupName , containerAciName := getGroupAndContainerName ( name )
2020-07-08 15:31:27 +03:00
containerExecResponse , err := execACIContainer ( ctx , cs . ctx , request . Command , groupName , containerAciName )
2020-05-03 14:35:25 +03:00
if err != nil {
return err
}
return exec (
context . Background ( ) ,
* containerExecResponse . WebSocketURI ,
* containerExecResponse . Password ,
2020-07-08 15:31:27 +03:00
request ,
2020-05-03 14:35:25 +03:00
)
}
2020-05-03 14:41:45 +03:00
2020-07-06 04:29:48 +03:00
func verifyExecCommand ( command string ) error {
tokens := strings . Split ( command , " " )
if len ( tokens ) > 1 {
return errors . New ( "ACI exec command does not accept arguments to the command. " +
"Only the binary should be specified" )
}
return nil
}
2020-05-05 16:37:12 +03:00
func ( cs * aciContainerService ) Logs ( ctx context . Context , containerName string , req containers . LogsRequest ) error {
2020-05-18 15:56:32 +03:00
groupName , containerAciName := getGroupAndContainerName ( containerName )
2020-06-29 16:40:58 +03:00
var tail * int32
2020-06-30 13:23:22 +03:00
if req . Follow {
2020-07-09 11:50:48 +03:00
return streamLogs ( ctx , cs . ctx , groupName , containerAciName , req )
2020-06-30 13:23:22 +03:00
}
2020-05-04 17:38:02 +03:00
if req . Tail != "all" {
2020-06-29 16:40:58 +03:00
reqTail , err := strconv . Atoi ( req . Tail )
2020-05-04 17:38:02 +03:00
if err != nil {
return err
}
2020-06-29 16:40:58 +03:00
i32 := int32 ( reqTail )
tail = & i32
}
2020-05-04 17:38:02 +03:00
2020-06-29 16:40:58 +03:00
logs , err := getACIContainerLogs ( ctx , cs . ctx , groupName , containerAciName , tail )
if err != nil {
return err
2020-05-04 17:38:02 +03:00
}
_ , err = fmt . Fprint ( req . Writer , logs )
2020-05-03 14:41:45 +03:00
return err
}
2020-05-05 11:58:24 +03:00
2020-08-11 16:46:29 +03:00
func ( cs * aciContainerService ) Delete ( ctx context . Context , containerID string , request containers . DeleteRequest ) error {
2020-07-03 11:03:46 +03:00
groupName , containerName := getGroupAndContainerName ( containerID )
if groupName != containerID {
2020-07-03 16:55:51 +03:00
msg := "cannot delete service %q from compose application %q, you can delete the entire compose app with docker compose down --project-name %s"
return errors . New ( fmt . Sprintf ( msg , containerName , groupName , groupName ) )
2020-07-03 11:03:46 +03:00
}
2020-08-11 16:46:29 +03:00
if ! request . Force {
2020-08-14 18:07:33 +03:00
containerGroupsClient , err := login . NewContainerGroupsClient ( cs . ctx . SubscriptionID )
2020-08-12 11:35:15 +03:00
if err != nil {
return err
}
2020-08-11 16:46:29 +03:00
cg , err := containerGroupsClient . Get ( ctx , cs . ctx . ResourceGroup , groupName )
if err != nil {
if cg . StatusCode == http . StatusNotFound {
return errdefs . ErrNotFound
}
return err
}
for _ , container := range * cg . Containers {
2020-08-18 11:50:56 +03:00
status := convert . GetStatus ( container , cg )
2020-08-11 16:46:29 +03:00
2020-09-04 16:09:57 +03:00
if status == convert . StatusRunning {
2020-08-11 16:46:29 +03:00
return errdefs . ErrForbidden
}
}
}
cg , err := deleteACIContainerGroup ( ctx , cs . ctx , groupName )
// Delete returns `StatusNoContent` if the group is not found
2020-05-10 23:37:28 +03:00
if cg . StatusCode == http . StatusNoContent {
2020-08-11 16:46:29 +03:00
return errdefs . ErrNotFound
}
if err != nil {
return err
2020-05-10 23:37:28 +03:00
}
return err
}
2020-06-12 11:53:06 +03:00
func ( cs * aciContainerService ) Inspect ( ctx context . Context , containerID string ) ( containers . Container , error ) {
2020-06-15 11:38:37 +03:00
groupName , containerName := getGroupAndContainerName ( containerID )
cg , err := getACIContainerGroup ( ctx , cs . ctx , groupName )
2020-06-12 11:53:06 +03:00
if err != nil {
return containers . Container { } , err
}
if cg . StatusCode == http . StatusNoContent {
2020-08-11 16:46:29 +03:00
return containers . Container { } , errdefs . ErrNotFound
2020-06-12 11:53:06 +03:00
}
2020-06-15 11:38:37 +03:00
var cc containerinstance . Container
var found = false
for _ , c := range * cg . Containers {
if to . String ( c . Name ) == containerName {
cc = c
found = true
break
}
2020-06-12 11:53:06 +03:00
}
2020-06-15 11:38:37 +03:00
if ! found {
2020-08-11 16:46:29 +03:00
return containers . Container { } , errdefs . ErrNotFound
2020-06-12 11:53:06 +03:00
}
2020-08-18 11:50:56 +03:00
return convert . ContainerGroupToContainer ( containerID , cg , cc ) , nil
2020-06-12 11:53:06 +03:00
}
2020-05-05 16:37:12 +03:00
type aciComposeService struct {
2020-05-13 00:00:58 +03:00
ctx store . AciContext
2020-05-05 16:37:12 +03:00
}
2020-08-20 17:42:37 +03:00
func ( cs * aciComposeService ) Up ( ctx context . Context , project * types . Project ) error {
2020-05-05 11:58:24 +03:00
logrus . Debugf ( "Up on project with name %q\n" , project . Name )
2020-08-14 18:01:35 +03:00
groupDefinition , err := convert . ToContainerGroup ( ctx , cs . ctx , * project )
2020-07-16 11:01:49 +03:00
addTag ( & groupDefinition , composeContainerTag )
2020-05-06 18:14:53 +03:00
2020-05-05 11:58:24 +03:00
if err != nil {
return err
}
2020-06-18 11:03:28 +03:00
return createOrUpdateACIContainers ( ctx , cs . ctx , groupDefinition )
2020-05-05 11:58:24 +03:00
}
2020-08-20 17:42:37 +03:00
func ( cs * aciComposeService ) Down ( ctx context . Context , project string ) error {
logrus . Debugf ( "Down on project with name %q\n" , project )
2020-05-10 23:37:28 +03:00
2020-08-20 17:42:37 +03:00
cg , err := deleteACIContainerGroup ( ctx , cs . ctx , project )
2020-05-10 23:37:28 +03:00
if err != nil {
return err
}
if cg . StatusCode == http . StatusNoContent {
2020-08-11 16:46:29 +03:00
return errdefs . ErrNotFound
2020-05-10 23:37:28 +03:00
}
2020-05-05 11:58:24 +03:00
return err
}
2020-05-12 14:37:28 +03:00
2020-08-20 17:42:37 +03:00
func ( cs * aciComposeService ) Ps ( ctx context . Context , project string ) ( [ ] compose . ServiceStatus , error ) {
2020-08-28 15:38:51 +03:00
groupsClient , err := login . NewContainerGroupsClient ( cs . ctx . SubscriptionID )
if err != nil {
return nil , err
}
group , err := groupsClient . Get ( ctx , cs . ctx . ResourceGroup , project )
if err != nil {
return [ ] compose . ServiceStatus { } , err
}
if group . Containers == nil || len ( * group . Containers ) < 1 {
return [ ] compose . ServiceStatus { } , fmt . Errorf ( "no containers found in ACI container group %s" , project )
}
res := [ ] compose . ServiceStatus { }
for _ , container := range * group . Containers {
if isContainerVisible ( container , group , false ) {
continue
}
res = append ( res , convert . ContainerGroupToServiceStatus ( getContainerID ( group , container ) , group , container ) )
}
return res , nil
2020-08-05 17:32:51 +03:00
}
2020-09-04 19:11:02 +03:00
2020-09-04 14:20:11 +03:00
func ( cs * aciComposeService ) List ( ctx context . Context , project string ) ( [ ] compose . Stack , error ) {
2020-09-04 19:11:02 +03:00
containerGroups , err := getContainerGroups ( ctx , cs . ctx . SubscriptionID , cs . ctx . ResourceGroup )
if err != nil {
return [ ] compose . Stack { } , err
}
stacks := [ ] compose . Stack { }
for _ , group := range containerGroups {
if _ , found := group . Tags [ composeContainerTag ] ; ! found {
continue
}
2020-09-07 12:15:39 +03:00
if project != "" && * group . Name != project {
continue
}
2020-09-04 19:11:02 +03:00
state := compose . RUNNING
for _ , container := range * group . ContainerGroupProperties . Containers {
containerState := convert . GetStatus ( container , group )
if containerState != compose . RUNNING {
state = containerState
break
}
}
stacks = append ( stacks , compose . Stack {
ID : * group . ID ,
Name : * group . Name ,
Status : state ,
} )
}
return stacks , nil
2020-09-04 14:20:11 +03:00
}
2020-08-05 17:32:51 +03:00
2020-08-20 17:42:37 +03:00
func ( cs * aciComposeService ) Logs ( ctx context . Context , project string , w io . Writer ) error {
2020-08-05 17:32:51 +03:00
return errdefs . ErrNotImplemented
}
2020-08-20 17:42:37 +03:00
func ( cs * aciComposeService ) Convert ( ctx context . Context , project * types . Project ) ( [ ] byte , error ) {
2020-08-18 09:58:37 +03:00
return nil , errdefs . ErrNotImplemented
}
2020-05-12 14:37:28 +03:00
type aciCloudService struct {
2020-08-10 17:38:59 +03:00
loginService login . AzureLoginServiceAPI
2020-05-12 14:37:28 +03:00
}
2020-07-10 17:55:44 +03:00
func ( cs * aciCloudService ) Login ( ctx context . Context , params interface { } ) error {
2020-08-10 17:38:59 +03:00
opts , ok := params . ( LoginParams )
if ! ok {
return errors . New ( "Could not read azure LoginParams struct from generic parameter" )
}
if opts . ClientID != "" {
return cs . loginService . LoginServicePrincipal ( opts . ClientID , opts . ClientSecret , opts . TenantID )
}
return cs . loginService . Login ( ctx , opts . TenantID )
2020-05-12 14:37:28 +03:00
}
2020-06-02 10:49:30 +03:00
2020-07-08 17:01:54 +03:00
func ( cs * aciCloudService ) Logout ( ctx context . Context ) error {
return cs . loginService . Logout ( ctx )
}
2020-07-10 17:39:09 +03:00
func ( cs * aciCloudService ) CreateContextData ( ctx context . Context , params interface { } ) ( interface { } , string , error ) {
2020-06-03 00:33:41 +03:00
contextHelper := newContextCreateHelper ( )
2020-07-13 11:38:29 +03:00
createOpts := params . ( ContextParams )
2020-07-10 17:39:09 +03:00
return contextHelper . createContextData ( ctx , createOpts )
2020-06-02 10:49:30 +03:00
}