introduce `Convert` in compose API

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2020-08-18 08:58:37 +02:00
parent e02d8d549b
commit 91427d0492
No known key found for this signature in database
GPG Key ID: 9858809D6F8F6E7E
6 changed files with 28 additions and 4 deletions

View File

@ -451,6 +451,10 @@ func (cs *aciComposeService) Logs(ctx context.Context, opts *cli.ProjectOptions,
return errdefs.ErrNotImplemented
}
func Convert(ctx context.Context, opts *cli.ProjectOptions) ([]byte, error) {
return nil, errdefs.ErrNotImplemented
}
type aciCloudService struct {
loginService login.AzureLoginServiceAPI
}

View File

@ -33,6 +33,8 @@ type Service interface {
Logs(ctx context.Context, opts *cli.ProjectOptions, w io.Writer) error
// Ps executes the equivalent to a `compose ps`
Ps(ctx context.Context, opts *cli.ProjectOptions) ([]ServiceStatus, error)
// Convert translate compose model into backend's native format
Convert(ctx context.Context, opts *cli.ProjectOptions) ([]byte, error)
}

View File

@ -1,7 +1,9 @@
package ecs
import (
"context"
"fmt"
"github.com/compose-spec/compose-go/cli"
"github.com/docker/api/compose"
"io/ioutil"
"regexp"
@ -33,8 +35,20 @@ const (
ParameterLoadBalancerARN = "ParameterLoadBalancerARN"
)
func (b *ecsAPIService) Convert(ctx context.Context, opts *cli.ProjectOptions) ([]byte, error) {
project, err := cli.ProjectFromOptions(opts)
if err != nil {
return nil, err
}
template, err := b.convert(project)
if err != nil {
return nil, err
}
return Marshall(template)
}
// Convert a compose project into a CloudFormation template
func (b ecsAPIService) Convert(project *types.Project) (*cloudformation.Template, error) {
func (b *ecsAPIService) convert(project *types.Project) (*cloudformation.Template, error) {
var checker compatibility.Checker = &FargateCompatibilityChecker{
compatibility.AllowList{
Supported: compatibleComposeAttributes,
@ -128,7 +142,7 @@ func (b ecsAPIService) Convert(project *types.Project) (*cloudformation.Template
for _, service := range project.Services {
definition, err := Convert(project, service)
definition, err := convert(project, service)
if err != nil {
return nil, err
}

View File

@ -23,7 +23,7 @@ import (
const secretsInitContainerImage = "docker/ecs-secrets-sidecar"
func Convert(project *types.Project, service types.ServiceConfig) (*ecs.TaskDefinition, error) {
func convert(project *types.Project, service types.ServiceConfig) (*ecs.TaskDefinition, error) {
cpu, mem, err := toLimits(service)
if err != nil {
return nil, err

View File

@ -27,7 +27,7 @@ func (b *ecsAPIService) Up(ctx context.Context, options *cli.ProjectOptions) err
return err
}
template, err := b.Convert(project)
template, err := b.convert(project)
if err != nil {
return err
}

View File

@ -142,3 +142,7 @@ func (cs *composeService) Ps(ctx context.Context, opts *cli.ProjectOptions) ([]c
func (cs *composeService) Logs(ctx context.Context, opts *cli.ProjectOptions, w io.Writer) error {
return errdefs.ErrNotImplemented
}
func Convert(ctx context.Context, opts *cli.ProjectOptions) ([]byte, error) {
return nil, errdefs.ErrNotImplemented
}