|  | @@ -21,7 +21,7 @@ import (
 | 
	
		
			
				|  |  |  	"github.com/docker/api/context/store"
 | 
	
		
			
				|  |  |  )
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -type containerService struct {
 | 
	
		
			
				|  |  | +type aciApiService struct {
 | 
	
		
			
				|  |  |  	containerGroupsClient containerinstance.ContainerGroupsClient
 | 
	
		
			
				|  |  |  	ctx                   store.AciContext
 | 
	
		
			
				|  |  |  }
 | 
	
	
		
			
				|  | @@ -36,8 +36,13 @@ func getter() interface{} {
 | 
	
		
			
				|  |  |  	return &store.AciContext{}
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +type AciService interface {
 | 
	
		
			
				|  |  | +	containers.ContainerService
 | 
	
		
			
				|  |  | +	compose.Service
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  // New creates a backend that can manage containers on ACI
 | 
	
		
			
				|  |  | -func New(ctx context.Context) (containers.ContainerService, error) {
 | 
	
		
			
				|  |  | +func New(ctx context.Context) (AciService, error) {
 | 
	
		
			
				|  |  |  	currentContext := apicontext.CurrentContext(ctx)
 | 
	
		
			
				|  |  |  	contextStore, err := store.New()
 | 
	
		
			
				|  |  |  	if err != nil {
 | 
	
	
		
			
				|  | @@ -53,13 +58,13 @@ func New(ctx context.Context) (containers.ContainerService, error) {
 | 
	
		
			
				|  |  |  	containerGroupsClient := containerinstance.NewContainerGroupsClient(aciContext.SubscriptionID)
 | 
	
		
			
				|  |  |  	containerGroupsClient.Authorizer = auth
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	return &containerService{
 | 
	
		
			
				|  |  | +	return &aciApiService{
 | 
	
		
			
				|  |  |  		containerGroupsClient: containerGroupsClient,
 | 
	
		
			
				|  |  |  		ctx:                   aciContext,
 | 
	
		
			
				|  |  |  	}, nil
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -func (cs *containerService) List(ctx context.Context) ([]containers.Container, error) {
 | 
	
		
			
				|  |  | +func (cs *aciApiService) List(ctx context.Context) ([]containers.Container, error) {
 | 
	
		
			
				|  |  |  	var containerGroups []containerinstance.ContainerGroup
 | 
	
		
			
				|  |  |  	result, err := cs.containerGroupsClient.ListByResourceGroup(ctx, cs.ctx.ResourceGroup)
 | 
	
		
			
				|  |  |  	if err != nil {
 | 
	
	
		
			
				|  | @@ -73,7 +78,7 @@ func (cs *containerService) List(ctx context.Context) ([]containers.Container, e
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	res := []containers.Container{}
 | 
	
		
			
				|  |  | +	var res []containers.Container
 | 
	
		
			
				|  |  |  	for _, containerGroup := range containerGroups {
 | 
	
		
			
				|  |  |  		group, err := cs.containerGroupsClient.Get(ctx, cs.ctx.ResourceGroup, *containerGroup.Name)
 | 
	
		
			
				|  |  |  		if err != nil {
 | 
	
	
		
			
				|  | @@ -96,7 +101,7 @@ func (cs *containerService) List(ctx context.Context) ([]containers.Container, e
 | 
	
		
			
				|  |  |  	return res, nil
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -func (cs *containerService) Run(ctx context.Context, r containers.ContainerConfig) error {
 | 
	
		
			
				|  |  | +func (cs *aciApiService) Run(ctx context.Context, r containers.ContainerConfig) error {
 | 
	
		
			
				|  |  |  	var ports []types.ServicePortConfig
 | 
	
		
			
				|  |  |  	for _, p := range r.Ports {
 | 
	
		
			
				|  |  |  		ports = append(ports, types.ServicePortConfig{
 | 
	
	
		
			
				|  | @@ -127,7 +132,7 @@ func (cs *containerService) Run(ctx context.Context, r containers.ContainerConfi
 | 
	
		
			
				|  |  |  	return err
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -func (cs *containerService) Exec(ctx context.Context, name string, command string, reader io.Reader, writer io.Writer) error {
 | 
	
		
			
				|  |  | +func (cs *aciApiService) Exec(ctx context.Context, name string, command string, reader io.Reader, writer io.Writer) error {
 | 
	
		
			
				|  |  |  	containerExecResponse, err := execACIContainer(ctx, cs.ctx, command, name, name)
 | 
	
		
			
				|  |  |  	if err != nil {
 | 
	
		
			
				|  |  |  		return err
 | 
	
	
		
			
				|  | @@ -142,7 +147,7 @@ func (cs *containerService) Exec(ctx context.Context, name string, command strin
 | 
	
		
			
				|  |  |  	)
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -func (cs *containerService) Logs(ctx context.Context, containerName string, req containers.LogsRequest) error {
 | 
	
		
			
				|  |  | +func (cs *aciApiService) Logs(ctx context.Context, containerName string, req containers.LogsRequest) error {
 | 
	
		
			
				|  |  |  	logs, err := getACIContainerLogs(ctx, cs.ctx, containerName, containerName)
 | 
	
		
			
				|  |  |  	if err != nil {
 | 
	
		
			
				|  |  |  		return err
 | 
	
	
		
			
				|  | @@ -163,3 +168,27 @@ func (cs *containerService) Logs(ctx context.Context, containerName string, req
 | 
	
		
			
				|  |  |  	_, err = fmt.Fprint(req.Writer, logs)
 | 
	
		
			
				|  |  |  	return err
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +func (cs *aciApiService) Up(ctx context.Context, opts compose.ProjectOptions) error {
 | 
	
		
			
				|  |  | +	project, err := compose.ProjectFromOptions(&opts)
 | 
	
		
			
				|  |  | +	if err != nil {
 | 
	
		
			
				|  |  | +		return err
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +	logrus.Debugf("Up on project with name %q\n", project.Name)
 | 
	
		
			
				|  |  | +	groupDefinition, err := convert.ToContainerGroup(cs.ctx, *project)
 | 
	
		
			
				|  |  | +	if err != nil {
 | 
	
		
			
				|  |  | +		return err
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +	_, err = createACIContainers(ctx, cs.ctx, groupDefinition)
 | 
	
		
			
				|  |  | +	return err
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +func (cs *aciApiService) Down(ctx context.Context, opts compose.ProjectOptions) error {
 | 
	
		
			
				|  |  | +	project, err := compose.ProjectFromOptions(&opts)
 | 
	
		
			
				|  |  | +	if err != nil {
 | 
	
		
			
				|  |  | +		return err
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +	logrus.Debugf("Down on project with name %q\n", project.Name)
 | 
	
		
			
				|  |  | +	_, err = deleteACIContainerGroup(ctx, cs.ctx, project.Name)
 | 
	
		
			
				|  |  | +	return err
 | 
	
		
			
				|  |  | +}
 |