Skip to content

Only publish exposed ports - #4122

Merged
rnorth merged 11 commits into
masterfrom
only-publish-exposed-ports
May 26, 2021
Merged

Only publish exposed ports#4122
rnorth merged 11 commits into
masterfrom
only-publish-exposed-ports

Conversation

@rnorth

@rnorth rnorth commented May 24, 2021

Copy link
Copy Markdown
Member

Fixes #4119

@rnorth
rnorth force-pushed the only-publish-exposed-ports branch from 0b15097 to 0e0e8c8 Compare May 24, 2021 16:25
@@ -1,8 +1,5 @@
package org.testcontainers.containers;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Regarding imports, there are some changes in ordering, but AFAICT these only match the IntelliJ defaults (with our .editorconfig tweaks layered on top for star imports).

TBH I'd prefer to go with the changed (hopefully stable) import order in this PR, rather than continue to constantly have the burden of maintaining the order (I don't know why the current order is as it is).

I think if we find ourselves continuing to run up against this then we should introduce a code formatter to our build (e.g. spotless gradle plugin + google formatter with AOSP style (4 space indent)).

Comment on lines +740 to +745
// Next, ExposedPorts must be set up to publish all of the above ports, randomized and fixed.
// Collect all of the exposed ports for publication
final List<ExposedPort> exposedPorts = allPortBindings.stream()
.map(PortBinding::getExposedPort)
.distinct()
.collect(Collectors.toList());

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is the thing that is substantially different from the previous implementation; changes above are mainly to support this change and to make it clearer what we're doing.

Of course, createCommand.withPublishAllPorts(true); on line 801 is also nuked.

@Override
protected Integer getLivenessCheckPort() {
return getMappedPort(HTTP_PORT);
public Set<Integer> getLivenessCheckPortNumbers() {

@rnorth rnorth May 25, 2021

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not strictly required for this PR, but during experimenting with approaches I found that a handful of our modules are using the getLivenessCheckPort method, which has been deprecated for 4 years. I'd like to take this chance to clean up.

protected void configure() {
super.configure();

addExposedPorts(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Interestingly the Couchbase module seems to have always relied on an EXPOSE statement + all-ports publication.

@rnorth
rnorth marked this pull request as ready for review May 25, 2021 07:07
@rnorth
rnorth requested a review from kiview as a code owner May 25, 2021 07:07
Comment thread core/src/main/java/org/testcontainers/containers/GenericContainer.java Outdated
@bsideup bsideup added this to the next milestone May 25, 2021
Comment thread core/src/main/java/org/testcontainers/containers/GenericContainer.java Outdated
Comment thread core/src/main/java/org/testcontainers/containers/GenericContainer.java Outdated
Comment thread core/src/main/java/org/testcontainers/containers/GenericContainer.java Outdated
Comment thread core/src/test/java/org/testcontainers/containers/GenericContainerTest.java Outdated

@bsideup bsideup left a comment

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.

💯

@rnorth
rnorth merged commit 96b2065 into master May 26, 2021
@delete-merged-branch
delete-merged-branch Bot deleted the only-publish-exposed-ports branch May 26, 2021 05:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Publish only explicitly exposed ports

2 participants