Skip to content
Merged
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import com.github.dockerjava.api.model.ExposedPort;
import com.github.dockerjava.api.model.PortBinding;
import com.google.common.collect.ImmutableList;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.utility.TestcontainersConfiguration;

Expand Down Expand Up @@ -69,12 +68,10 @@ public static void exposeFixedPorts(GenericContainer<?> container)
"This method is supposed to be invoked from local development helpers only e.g. QueryRunner.main(), " +
"hence it should never run on CI");

ImmutableList<PortBinding> portBindings = container.getExposedPorts().stream()
.map(exposedPort -> new PortBinding(bindPort(exposedPort), new ExposedPort(exposedPort)))
.collect(toImmutableList());

container.withCreateContainerCmdModifier(cmd -> cmd
.withHostConfig(requireNonNull(cmd.getHostConfig(), "hostConfig is null")
.withPortBindings(portBindings)));
.withPortBindings(container.getExposedPorts().stream()
.map(exposedPort -> new PortBinding(bindPort(exposedPort), new ExposedPort(exposedPort)))
.collect(toImmutableList()))));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fix for method exposing port on local environment 

This fix prevents loosing ports which were exposed
after we call this method

I couldn't understand what was wrong. I ran PostgreSqlQueryRunner with/without this commit, but the result looks same to me. Could you describe more details?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ebyhr
Call to this method add some override rules, which will be executed later.
So it's possible such situation.

  1. we collect current expose ports by calling this method (but not yet execute it)
  2. .... add more expose ports in other code ....
  3. actually apply overrides but only with values from 1) missing values from 2)

With Postgres it works because all exposed ports was added before 1)

Copy link
Copy Markdown
Member

@hashhar hashhar Oct 6, 2022

Choose a reason for hiding this comment

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

@vlad-lyutenko can you add some of this detailed context to the commit message?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

}
}