Last active
May 21, 2024 08:08
-
-
Save pisarukv/6e942d53a43f8973ce610af1398a2e68 to your computer and use it in GitHub Desktop.
read.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Excellent find!