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

consolidate pod and clean up errlogs #295

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions internal/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ func (d *Client) Run(ctx context.Context, req *Request) (string, error) {

if inspect.State != nil && inspect.State.Health != nil {
if inspect.State.Health.Status == "unhealthy" {
status := inspect.State.Health.Log[len(inspect.State.Health.Log)-1].Output
unhealthyCh <- fmt.Errorf("container became unhealthy, last status: %s", status)
code := inspect.State.Health.Log[len(inspect.State.Health.Log)-1].ExitCode
unhealthyCh <- fmt.Errorf("container became unhealthy with exit code: %d", code)
return
}
}
Expand All @@ -164,11 +164,11 @@ func (d *Client) Run(ctx context.Context, req *Request) (string, error) {

case status := <-statusCh:
if status.Error != nil {
return "", fmt.Errorf("container exited with error: %s", status.Error.Message)
return "", fmt.Errorf("container exited with error (%d): %s", status.StatusCode, status.Error.Message)
}

if status.StatusCode != 0 {
return "", fmt.Errorf("container exited with non-zero status code: %d", status.StatusCode)
return "", fmt.Errorf("container exited with non-zero exit code: %v", status.StatusCode)
}

case err := <-unhealthyCh:
Expand Down
9 changes: 7 additions & 2 deletions internal/drivers/docker_in_docker/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dockerindocker

import (
"bufio"
"bytes"
"context"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -140,6 +141,10 @@ func (d *driver) Run(ctx context.Context, ref name.Reference) error {
r, w := io.Pipe()
defer w.Close()

// collect container output for better error messages
stw := bytes.NewBuffer(nil)
mw := io.MultiWriter(w, stw)

go func() {
defer r.Close()
scanner := bufio.NewScanner(r)
Expand Down Expand Up @@ -168,10 +173,10 @@ func (d *driver) Run(ctx context.Context, ref name.Reference) error {
},
ExtraHosts: []string{"host.docker.internal:host-gateway"},
Contents: content,
Logger: w,
Logger: mw,
})
if err != nil {
return err
return fmt.Errorf("docker-in-docker test failed: %w\n\n%s", err, stw.String())
}

if err := d.stack.Add(func(ctx context.Context) error {
Expand Down
Loading