From c1ecb2b7be8e3501a3d0d258f9deb90fd6c97d86 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Wed, 26 Aug 2020 09:12:30 +0200 Subject: [PATCH] Check we have compose 1.27 or later Signed-off-by: Nicolas De Loof --- ecs/emulate.go | 27 +++++++++++++++++++++++---- go.mod | 1 + go.sum | 1 + 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/ecs/emulate.go b/ecs/emulate.go index f3859b485..6e11648cf 100644 --- a/ecs/emulate.go +++ b/ecs/emulate.go @@ -17,6 +17,8 @@ package ecs import ( + "bufio" + "bytes" "context" "fmt" "os" @@ -25,10 +27,11 @@ import ( "strings" "github.com/aws/aws-sdk-go/aws" - "github.com/compose-spec/compose-go/types" - "github.com/sanathkr/go-yaml" - "github.com/compose-spec/compose-go/cli" + "github.com/compose-spec/compose-go/types" + "github.com/pkg/errors" + "github.com/sanathkr/go-yaml" + "golang.org/x/mod/semver" ) func (c *ecsAPIService) Emulate(ctx context.Context, options *cli.ProjectOptions) error { @@ -104,7 +107,23 @@ func (c *ecsAPIService) Emulate(ctx context.Context, options *cli.ProjectOptions return err } - cmd := exec.Command("docker-compose", "--context", "default", "--project-directory", project.WorkingDir, "--project-name", project.Name, "-f", "-", "up") + cmd := exec.Command("docker-compose", "version", "--short") + b := bytes.Buffer{} + b.WriteString("v") + cmd.Stdout = bufio.NewWriter(&b) + err = cmd.Run() + if err != nil { + return errors.Wrap(err, "ECS simulation mode require Docker-compose 1.27") + } + version := semver.MajorMinor(strings.TrimSpace(b.String())) + if version == "" { + return fmt.Errorf("can't parse docker-compose version: %s", b.String()) + } + if semver.Compare(version, "v1.27") < 0 { + return fmt.Errorf("ECS simulation mode require Docker-compose 1.27, found %s", version) + } + + cmd = exec.Command("docker-compose", "--context", "default", "--project-directory", project.WorkingDir, "--project-name", project.Name, "-f", "-", "up") cmd.Stdin = strings.NewReader(string(marshal)) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr diff --git a/go.mod b/go.mod index 5f7ed8190..adea637a0 100644 --- a/go.mod +++ b/go.mod @@ -52,6 +52,7 @@ require ( github.com/spf13/cobra v1.0.0 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.6.1 + golang.org/x/mod v0.3.0 golang.org/x/net v0.0.0-20200625001655-4c5254603344 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 diff --git a/go.sum b/go.sum index 1b2ca12ef..b85de99ba 100644 --- a/go.sum +++ b/go.sum @@ -417,6 +417,7 @@ golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=