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

Issue 439: use an existing container #464

Conversation

VladimirStepanov
Copy link
Contributor

Close #439

@codecov
Copy link

codecov bot commented Jun 15, 2022

Codecov Report

Merging #464 (cb81fb6) into main (f46205c) will increase coverage by 0.89%.
The diff coverage is 73.01%.

@@            Coverage Diff             @@
##             main     #464      +/-   ##
==========================================
+ Coverage   69.30%   70.20%   +0.89%     
==========================================
  Files          21       21              
  Lines        1942     2014      +72     
==========================================
+ Hits         1346     1414      +68     
- Misses        477      480       +3     
- Partials      119      120       +1     
Impacted Files Coverage Δ
container.go 80.72% <ø> (ø)
docker.go 71.13% <67.92%> (+1.68%) ⬆️
generic.go 75.00% <100.00%> (+7.14%) ⬆️
reaper.go 83.78% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f46205c...cb81fb6. Read the comment docs.

@VladimirStepanov VladimirStepanov changed the title Issue 439: use existing container Issue 439: use an existing container Jun 15, 2022
generic.go Outdated Show resolved Hide resolved
docs/features/creating_container.md Outdated Show resolved Hide resolved
docker.go Show resolved Hide resolved
generic.go Outdated Show resolved Hide resolved
@mdelapenya
Copy link
Member

I did not mention, but great job while elaborating the PR! Thanks for your time here

Comment on lines 88 to 89
Reusing will work only if you pass an existing container's name via 'req.Name' field.
If the name is empty, or it is not in a list of existing containers, the function will create a new generic container
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading this description, which is pretty clear, this thought came to my mind: why adding a new type of container that could be used in a wrong manner, like creating a GenericReusableContainer but with a name that is not reusable?

This is thinking out loud: do you think adding the same logic to the reusable container into the generic container would make sense? Please take a look at how the Java folks do it: https:/testcontainers/testcontainers-java/blob/de1324ed2800eff4da326d0c23d281399d006bc0/core/src/main/java/org/testcontainers/containers/GenericContainer.java#L384

The GenericContainer, if defined as reusable, reuses the container ID. I think this API would be simpler in terms of usability: as a consumer I don't have to remember the different types of Containers, simply configure the generic one.

Again, this is an opinion, as valid as any other, so please tell us your thoughts

Copy link
Contributor Author

@VladimirStepanov VladimirStepanov Jul 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdelapenya I want to suggest next behavior: we add Reuse optional flag to GenericContainerRequest, because maybe a user doesn't want to reuse an existing container..

c, err := GenericContainer(ctx, GenericContainerRequest{
	ContainerRequest: ContainerRequest{
		Image:        "nginx:1.17.6",
		ExposedPorts: []string{"80/tcp"},
		WaitingFor:   wait.ForListeningPort("80/tcp"),
                Name: "my_reusable_container",

	},
	Started: true,
	Reuse: true,
})

And we will get next possible options:

  1. Reuse is true. We will reuse an existing container by Name or create a new one if it not exists . If we reuse an existing container, we will ignore flag Started, because the container is already started.
  2. Reuse is false. Try to create a new container or return an error if a container already exists.

Wdyt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! Please go for it 🚀

@VladimirStepanov
Copy link
Contributor Author

@mdelapenya updated:)

docker.go Outdated Show resolved Hide resolved
@mdelapenya mdelapenya added the feature New functionality or new behaviors on the existing one label Jul 5, 2022
@mdelapenya mdelapenya self-assigned this Jul 5, 2022
@mdelapenya mdelapenya merged commit 2feda90 into testcontainers:main Jul 5, 2022
@deepakyadav deepakyadav mentioned this pull request Aug 1, 2022
sessionID := uuid.New()
var termSignal chan bool
if !req.SkipReaper {
r, err := NewReaper(ctx, sessionID.String(), p, req.ReaperImage)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need reaper for reused container?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reaper will only be created if it does not exist, so the code for the reaper creation is there, but will check if a real reaper container already exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality or new behaviors on the existing one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use existing container?
3 participants