Skip to content

Instantly share code, notes, and snippets.

@pisarukv
Last active May 21, 2024 08:08
Show Gist options
  • Save pisarukv/6e942d53a43f8973ce610af1398a2e68 to your computer and use it in GitHub Desktop.
Save pisarukv/6e942d53a43f8973ce610af1398a2e68 to your computer and use it in GitHub Desktop.
read.go
package docker
import (
"context"
"io"
"github.com/ory/dockertest"
"github.com/ory/dockertest/docker"
)
type Container struct {
pool *dockertest.Pool
resource *dockertest.Resource
}
func NewContainer(pool, repository, tag string, env []string) (*Container, error) {
p, err := dockertest.NewPool(pool)
if err != nil {
return nil, err
}
r, err := p.Run(repository, tag, env)
if err != nil {
return nil, err
}
return &Container{
pool: p,
resource: r,
}, nil
}
func (c *Container) TailLogs(ctx context.Context, wr io.Writer, follow bool) error {
opts := docker.LogsOptions{
Context: ctx,
Stderr: true,
Stdout: true,
Follow: follow,
Timestamps: true,
RawTerminal: true,
Container: c.resource.Container.ID,
OutputStream: wr,
}
return c.pool.Client.Logs(opts)
}
@jamesseanwright
Copy link

Excellent find!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment