Merge pull request #544 from docker/simulation

Introduce ECS emulation mode
This commit is contained in:
Guillaume Tardif 2020-09-01 15:18:32 +02:00 committed by GitHub
commit c7e2db077e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 355 additions and 9 deletions

View file

@ -40,7 +40,6 @@ 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")
return upCmd
}

View file

@ -38,17 +38,22 @@ $ docker context create ecs CONTEXT [flags]
}
func createEcsCommand() *cobra.Command {
var localSimulation bool
var opts ecs.ContextParams
cmd := &cobra.Command{
Use: "ecs CONTEXT [flags]",
Short: "Create a context for Amazon ECS",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if localSimulation {
return runCreateLocalSimulation(cmd.Context(), args[0], opts)
}
return runCreateEcs(cmd.Context(), args[0], opts)
},
}
addDescriptionFlag(cmd, &opts.Description)
cmd.Flags().BoolVar(&localSimulation, "local-simulation", false, "Create context for ECS local simulation endpoints")
cmd.Flags().StringVar(&opts.Profile, "profile", "", "Profile")
cmd.Flags().StringVar(&opts.Region, "region", "", "Region")
cmd.Flags().StringVar(&opts.AwsID, "key-id", "", "AWS Access Key ID")
@ -56,6 +61,21 @@ func createEcsCommand() *cobra.Command {
return cmd
}
func runCreateLocalSimulation(ctx context.Context, contextName string, opts ecs.ContextParams) error {
if contextExists(ctx, contextName) {
return errors.Wrapf(errdefs.ErrAlreadyExists, "context %q", contextName)
}
cs, err := client.GetCloudService(ctx, store.EcsLocalSimulationContextType)
if err != nil {
return errors.Wrap(err, "cannot connect to ECS backend")
}
data, description, err := cs.CreateContextData(ctx, opts)
if err != nil {
return err
}
return createDockerContext(ctx, contextName, store.EcsLocalSimulationContextType, description, data)
}
func runCreateEcs(ctx context.Context, contextName string, opts ecs.ContextParams) error {
if contextExists(ctx, contextName) {
return errors.Wrapf(errdefs.ErrAlreadyExists, "context %q", contextName)
@ -71,7 +91,7 @@ func runCreateEcs(ctx context.Context, contextName string, opts ecs.ContextParam
func getEcsContextData(ctx context.Context, opts ecs.ContextParams) (interface{}, string, error) {
cs, err := client.GetCloudService(ctx, store.EcsContextType)
if err != nil {
return nil, "", errors.Wrap(err, "cannot connect to AWS backend")
return nil, "", errors.Wrap(err, "cannot connect to ECS backend")
}
return cs.CreateContextData(ctx, opts)
}

View file

@ -27,6 +27,8 @@ import (
"syscall"
"time"
"github.com/docker/compose-cli/cli/cmd/compose"
"github.com/docker/compose-cli/cli/cmd/logout"
"github.com/docker/compose-cli/errdefs"
@ -38,12 +40,12 @@ import (
// Backend registrations
_ "github.com/docker/compose-cli/aci"
_ "github.com/docker/compose-cli/ecs"
_ "github.com/docker/compose-cli/ecs/local"
_ "github.com/docker/compose-cli/example"
_ "github.com/docker/compose-cli/local"
"github.com/docker/compose-cli/metrics"
"github.com/docker/compose-cli/cli/cmd"
"github.com/docker/compose-cli/cli/cmd/compose"
contextcmd "github.com/docker/compose-cli/cli/cmd/context"
"github.com/docker/compose-cli/cli/cmd/login"
"github.com/docker/compose-cli/cli/cmd/run"
@ -121,12 +123,12 @@ func main() {
cmd.RmCommand(),
cmd.StartCommand(),
cmd.InspectCommand(),
compose.Command(),
login.Command(),
logout.Command(),
cmd.VersionCommand(version),
cmd.StopCommand(),
cmd.SecretCommand(),
compose.Command(),
// Place holders
cmd.EcsCommand(),