Browse Source

Skeletton for "compose up" command

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 5 years ago
parent
commit
91daf0dcc0
4 changed files with 69 additions and 2 deletions
  1. 21 0
      ecs/cmd/main/main.go
  2. 32 2
      ecs/pkg/amazon/client.go
  3. 11 0
      ecs/pkg/amazon/compose.go
  4. 5 0
      ecs/pkg/compose/api.go

+ 21 - 0
ecs/cmd/main/main.go

@@ -5,6 +5,7 @@ import (
 	"github.com/docker/cli/cli-plugins/manager"
 	"github.com/docker/cli/cli-plugins/plugin"
 	"github.com/docker/cli/cli/command"
+	"github.com/docker/ecs-plugin/pkg/amazon"
 	"github.com/docker/ecs-plugin/pkg/compose"
 	"github.com/spf13/cobra"
 )
@@ -24,6 +25,7 @@ func main() {
 }
 
 type clusterOptions struct {
+	profile string
 	region  string
 	cluster string
 }
@@ -42,6 +44,7 @@ func NewRootCmd(name string, dockerCli command.Cli) *cobra.Command {
 		VersionCommand(),
 		ComposeCommand(&opts),
 	)
+	cmd.Flags().StringVarP(&opts.profile, "profile", "p", "default", "AWS Profile")
 	cmd.Flags().StringVarP(&opts.cluster, "cluster", "c", "default", "ECS cluster")
 	cmd.Flags().StringVarP(&opts.region, "region", "r", "", "AWS region")
 
@@ -65,5 +68,23 @@ func ComposeCommand(clusteropts *clusterOptions) *cobra.Command {
 	}
 	opts := &compose.ProjectOptions{}
 	opts.AddFlags(cmd.Flags())
+
+	cmd.AddCommand(
+		UpCommand(clusteropts, opts),
+	)
 	return cmd
 }
+
+func UpCommand(clusteropts *clusterOptions, opts *compose.ProjectOptions) *cobra.Command {
+	cmd := &cobra.Command{
+		Use: "up",
+		RunE: compose.WithProject(opts, func(project *compose.Project, args []string) error {
+			client, err := amazon.NewClient(clusteropts.profile, clusteropts.cluster, clusteropts.region)
+			if err != nil {
+				return err
+			}
+			return client.ComposeUp(project)
+		}),
+	}
+	return cmd
+}

+ 32 - 2
ecs/pkg/amazon/client.go

@@ -1,7 +1,37 @@
 package amazon
 
-import "github.com/aws/aws-sdk-go/aws/session"
+import (
+	"github.com/aws/aws-sdk-go/aws"
+	"github.com/aws/aws-sdk-go/aws/session"
+	"github.com/docker/ecs-plugin/pkg/compose"
+)
 
-type Client struct {
+
+const (
+	ProjectTag = "com.docker.compose.project"
+)
+
+func NewClient(profile string, cluster string, region string) (compose.API, error) {
+	sess, err := session.NewSessionWithOptions(session.Options{
+		Profile: profile,
+		Config: aws.Config{
+			Region: aws.String(region),
+		},
+	})
+	if err != nil {
+		return nil, err
+	}
+	return &client{
+		Cluster: cluster,
+		Region: region,
+		sess: sess,
+	}, nil
+}
+
+type client struct {
+	Cluster string
+	Region string
 	sess *session.Session
 }
+
+var _ compose.API = &client{}

+ 11 - 0
ecs/pkg/amazon/compose.go

@@ -0,0 +1,11 @@
+package amazon
+
+import (
+	"fmt"
+	"github.com/docker/ecs-plugin/pkg/compose"
+)
+
+func (c *client) ComposeUp(project *compose.Project) error {
+	fmt.Println("TODO Up")
+	return nil
+}

+ 5 - 0
ecs/pkg/compose/api.go

@@ -0,0 +1,5 @@
+package compose
+
+type API interface {
+	ComposeUp(project *Project) error
+}