Merge pull request #573 from docker/simulation

This commit is contained in:
Nicolas De loof 2020-09-03 16:10:55 +02:00 committed by GitHub
commit a0a0e391cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 36 additions and 2 deletions

View File

@ -27,6 +27,9 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
types2 "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/compose-cli/compose" "github.com/docker/compose-cli/compose"
"github.com/docker/compose-cli/errdefs" "github.com/docker/compose-cli/errdefs"
@ -133,11 +136,42 @@ func (e ecsLocalSimulation) Convert(ctx context.Context, project *types.Project)
} }
func (e ecsLocalSimulation) Down(ctx context.Context, projectName string) error { func (e ecsLocalSimulation) Down(ctx context.Context, projectName string) error {
return errors.Wrap(errdefs.ErrNotImplemented, "use docker-compose down") cmd := exec.Command("docker-compose", "--context", "default", "--project-name", projectName, "-f", "-", "down", "--remove-orphans")
cmd.Stdin = strings.NewReader(string(`
services:
ecs-local-endpoints:
image: "amazon/amazon-ecs-local-container-endpoints"
`))
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
} }
func (e ecsLocalSimulation) Logs(ctx context.Context, projectName string, w io.Writer) error { func (e ecsLocalSimulation) Logs(ctx context.Context, projectName string, w io.Writer) error {
return errors.Wrap(errdefs.ErrNotImplemented, "use docker-compose logs") list, err := e.moby.ContainerList(ctx, types2.ContainerListOptions{
Filters: filters.NewArgs(filters.Arg("label", "com.docker.compose.project="+projectName)),
})
if err != nil {
return err
}
services := map[string]types.ServiceConfig{}
for _, c := range list {
services[c.Labels["com.docker.compose.service"]] = types.ServiceConfig{
Image: "unused",
}
}
marshal, err := yaml.Marshal(map[string]interface{}{
"services": services,
})
if err != nil {
return err
}
cmd := exec.Command("docker-compose", "--context", "default", "--project-name", projectName, "-f", "-", "logs", "-f")
cmd.Stdin = strings.NewReader(string(marshal))
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
} }
func (e ecsLocalSimulation) Ps(ctx context.Context, projectName string) ([]compose.ServiceStatus, error) { func (e ecsLocalSimulation) Ps(ctx context.Context, projectName string) ([]compose.ServiceStatus, error) {