Introduce ECS emulation mode

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2020-08-25 10:30:51 +02:00
parent ed1776fec0
commit 7f8bb030e6
No known key found for this signature in database
GPG key ID: 9858809D6F8F6E7E
10 changed files with 146 additions and 9 deletions

View file

@ -60,7 +60,7 @@ func (o *composeOptions) toProjectOptions() (*cli.ProjectOptions, error) {
}
// Command returns the compose command with its child commands
func Command() *cobra.Command {
func Command(contextType string) *cobra.Command {
command := &cobra.Command{
Short: "Docker Compose",
Use: "compose",
@ -70,7 +70,7 @@ func Command() *cobra.Command {
}
command.AddCommand(
upCommand(),
upCommand(contextType),
downCommand(),
psCommand(),
logsCommand(),

View file

@ -24,15 +24,17 @@ import (
"github.com/spf13/cobra"
"github.com/docker/compose-cli/client"
"github.com/docker/compose-cli/context/store"
"github.com/docker/compose-cli/progress"
)
func upCommand() *cobra.Command {
func upCommand(contextType string) *cobra.Command {
opts := composeOptions{}
var simulation bool
upCmd := &cobra.Command{
Use: "up",
RunE: func(cmd *cobra.Command, args []string) error {
return runUp(cmd.Context(), opts)
return runUp(cmd.Context(), opts, simulation)
},
}
upCmd.Flags().StringVarP(&opts.Name, "project-name", "p", "", "Project name")
@ -40,11 +42,14 @@ func upCommand() *cobra.Command {
upCmd.Flags().StringArrayVarP(&opts.ConfigPaths, "file", "f", []string{}, "Compose configuration files")
upCmd.Flags().StringArrayVarP(&opts.Environment, "environment", "e", []string{}, "Environment variables")
upCmd.Flags().BoolP("detach", "d", true, " Detached mode: Run containers in the background")
if contextType == store.EcsContextType {
upCmd.Flags().BoolVar(&simulation, "simulate", false, " Simulation mode: run compose app with ECS local container endpoints")
}
return upCmd
}
func runUp(ctx context.Context, opts composeOptions) error {
func runUp(ctx context.Context, opts composeOptions, simulation bool) error {
c, err := client.New(ctx)
if err != nil {
return err
@ -60,6 +65,9 @@ func runUp(ctx context.Context, opts composeOptions) error {
return err
}
if simulation {
return c.ComposeService().Emulate(ctx, options)
}
return c.ComposeService().Up(ctx, project)
})
}

View file

@ -121,7 +121,6 @@ func main() {
cmd.RmCommand(),
cmd.StartCommand(),
cmd.InspectCommand(),
compose.Command(),
login.Command(),
logout.Command(),
cmd.VersionCommand(version),
@ -184,6 +183,8 @@ func main() {
$ docker context create %s <name>`, cc.Type(), store.EcsContextType))
}
root.AddCommand(compose.Command(ctype))
metrics.Track(ctype, os.Args[1:], root.PersistentFlags())
ctx = apicontext.WithCurrentContext(ctx, currentContext)