Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Support for Compose logs #2344

Open
benmoss opened this issue Mar 12, 2024 · 1 comment
Open

[Feature]: Support for Compose logs #2344

benmoss opened this issue Mar 12, 2024 · 1 comment
Labels
feature New functionality or new behaviors on the existing one

Comments

@benmoss
Copy link
Contributor

benmoss commented Mar 12, 2024

Problem

One of my docker compose containers is failing to come up, and so I get an unhelpful error message:

dependency failed to start: container 62e034fc-fae9-4e80-af07-8c1d8902b1da-minio_init-1 is unhealthy

If I was using the Docker compose CLI, I would call docker compose logs to see why the container was failing.

Solution

Add something to the Compose module's API to get logs of all the containers

Benefit

Debugging, providing helpful test output in the case of failures

Alternatives

Not as far as I can think of

Would you like to help contributing this feature?

Yes

@benmoss benmoss added the feature New functionality or new behaviors on the existing one label Mar 12, 2024
@benmoss
Copy link
Contributor Author

benmoss commented Mar 12, 2024

As a workaround I came up with this:

t.Cleanup(func() {
	ctx := context.Background()
	for _, service := range compose.Services() {
		container, err := compose.ServiceContainer(ctx, service)
		if err != nil {
			t.Logf("failed to get container for service %q: %v", service, err)
			continue
		}
		logs, err := container.Logs(ctx)
		if err != nil {
			t.Logf("failed to get logs for service %q: %v", service, err)
			continue
		}
		buf, err := io.ReadAll(logs)
		if err != nil {
			t.Logf("failed to read logs for service %q: %v", service, err)
			continue
		}
		t.Logf("[%s]\n%s", service, string(buf))
	}
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality or new behaviors on the existing one
Projects
None yet
Development

No branches or pull requests

1 participant