another hack-ish hack to support compose logs

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2020-09-01 16:02:06 +02:00
parent 4bd8a8860f
commit 7104b8126a
No known key found for this signature in database
GPG Key ID: 9858809D6F8F6E7E
1 changed files with 27 additions and 1 deletions

View File

@ -27,6 +27,9 @@ import (
"path/filepath"
"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/errdefs"
@ -145,7 +148,30 @@ services:
}
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) {