Skip to content

Commit

Permalink
Keep exposed ports order in ContainerDef (#7811)
Browse files Browse the repository at this point in the history
Order is lost and break modules with multiple ports defined.
  • Loading branch information
eddumelendez authored Nov 15, 2023
1 parent 1419510 commit 6d33055
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ContainerDef {
@Getter
private RemoteDockerImage image;

Set<ExposedPort> exposedPorts = new HashSet<>();
Set<ExposedPort> exposedPorts = new LinkedHashSet<>();

Set<PortBinding> portBindings = new HashSet<>();

Expand Down Expand Up @@ -150,7 +150,7 @@ protected void setImage(DockerImageName image) {
}

public Set<ExposedPort> getExposedPorts() {
return new HashSet<>(this.exposedPorts);
return new LinkedHashSet<>(this.exposedPorts);
}

protected void setExposedPorts(Set<ExposedPort> exposedPorts) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,19 @@ public void setImage(Future<String> image) {

@Override
public List<Integer> getExposedPorts() {
return this.containerDef.getExposedPorts().stream().map(ExposedPort::getPort).collect(Collectors.toList());
List<Integer> exposedPorts = new ArrayList<>();
for (ExposedPort exposedPort : this.containerDef.getExposedPorts()) {
exposedPorts.add(exposedPort.getPort());
}
return exposedPorts;
}

@Override
public void setExposedPorts(List<Integer> exposedPorts) {
this.containerDef.setExposedPorts(exposedPorts.stream().map(ExposedPort::tcp).collect(Collectors.toSet()));
this.containerDef.exposedPorts.clear();
for (Integer exposedPort : exposedPorts) {
this.containerDef.addExposedTcpPort(exposedPort);
}
}

/**
Expand Down

0 comments on commit 6d33055

Please sign in to comment.