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

chore: proper messaging on disabling ryuk #566

Merged
merged 6 commits into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
15 changes: 15 additions & 0 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,8 @@ func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerReque
req.Labels[k] = v
}
}
} else {
p.printReaperBanner("container")
}

if err = req.Validate(); err != nil {
Expand Down Expand Up @@ -1145,6 +1147,8 @@ func (p *DockerProvider) ReuseOrCreateContainer(ctx context.Context, req Contain
if err != nil {
return nil, fmt.Errorf("%w: connecting to reaper failed", err)
}
} else {
p.printReaperBanner("container")
}
dc := &DockerContainer{
ID: c.ID,
Expand Down Expand Up @@ -1304,6 +1308,8 @@ func (p *DockerProvider) CreateNetwork(ctx context.Context, req NetworkRequest)
req.Labels[k] = v
}
}
} else {
p.printReaperBanner("network")
}

response, err := p.client.NetworkCreate(ctx, req.Name, nc)
Expand Down Expand Up @@ -1362,6 +1368,15 @@ func (p *DockerProvider) GetGatewayIP(ctx context.Context) (string, error) {
return ip, nil
}

func (p *DockerProvider) printReaperBanner(resource string) {
ryukDisabledMessage := `
**********************************************************************************************
Ryuk has been disabled for the ` + resource + `. This can cause unexpected behavior in your environment.
More on this: https://golang.testcontainers.org/features/garbage_collector/
**********************************************************************************************`
p.Logger.Printf(ryukDisabledMessage)
}

func inAContainer() bool {
// see https://github.com/testcontainers/testcontainers-java/blob/3ad8d80e2484864e554744a4800a81f6b7982168/core/src/main/java/org/testcontainers/dockerclient/DockerClientConfigUtils.java#L15
if _, err := os.Stat("/.dockerenv"); err == nil {
Expand Down
8 changes: 6 additions & 2 deletions docs/features/garbage_collector.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ container labels to determine which resources were created by the package
to determine the entities that are safe to remove. If a container is running
for more than 10 seconds, it will be killed.

!!!tip
!!!warning

This feature can be disabled when creating a container or a network,
but it can cause **unexpected behavior** in your environment.

This feature can be disabled when creating a container.
We recommend using it only for Continuous Integration services that have their
own mechanism to clean up resources.

Even if you do not call Terminate, Ryuk ensures that the environment will be
kept clean and even cleans itself when there is nothing left to do.