Skip to content

Commit

Permalink
chore: proper messaging on disabling ryuk (#566)
Browse files Browse the repository at this point in the history
* chore: add a banner qhen Ryuk is disabled

* docs: document unexpected behaviors when disabling Ryuk

* chore: link to docs in the message

* docs: improve message in docs

* chore: extract banner to a function
  • Loading branch information
mdelapenya committed Oct 16, 2022
1 parent b798926 commit b70166b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
15 changes: 15 additions & 0 deletions docker.go
Expand Up @@ -951,6 +951,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 @@ -1164,6 +1166,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 @@ -1323,6 +1327,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 @@ -1381,6 +1387,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
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.

0 comments on commit b70166b

Please sign in to comment.