Skip to content

Commit 88bd3c9

Browse files
authored
Merge pull request quarkusio#55663 from sberyozkin/keycloak-host-port-access
Optional access to application host ports from Keycloak Container
2 parents c38739c + fff89f9 commit 88bd3c9

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

extensions/devservices/keycloak/src/main/java/io/quarkus/devservices/keycloak/KeycloakDevServicesConfig.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,13 @@ public interface KeycloakDevServicesConfig {
229229
@WithDefault("false")
230230
boolean disableHttps();
231231

232+
/**
233+
* The host ports to expose to the Keycloak container.
234+
*
235+
* When this list is non-empty, the host is made accessible from the container
236+
* using the {@code host.testcontainers.internal} hostname, and only the listed ports are exposed.
237+
* This may be necessary when Keycloak needs to make HTTP callbacks to the application running on the host.
238+
*/
239+
Optional<List<Integer>> hostAccessiblePorts();
240+
232241
}

extensions/devservices/keycloak/src/main/java/io/quarkus/devservices/keycloak/KeycloakDevServicesProcessor.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.keycloak.representations.idm.RolesRepresentation;
4444
import org.keycloak.representations.idm.UserRepresentation;
4545
import org.keycloak.util.JsonSerialization;
46+
import org.testcontainers.Testcontainers;
4647
import org.testcontainers.containers.BindMode;
4748
import org.testcontainers.containers.GenericContainer;
4849
import org.testcontainers.containers.wait.strategy.Wait;
@@ -527,6 +528,12 @@ protected void configure() {
527528
addExposedPort(KEYCLOAK_PORT);
528529
}
529530

531+
if (config.hostAccessiblePorts().isPresent()) {
532+
for (int port : config.hostAccessiblePorts().get()) {
533+
Testcontainers.exposeHostPorts(port);
534+
}
535+
}
536+
530537
if (sharedContainer && LaunchMode.current() == LaunchMode.DEVELOPMENT) {
531538
withLabel(DEV_SERVICE_LABEL, containerLabelValue);
532539
withLabel(QUARKUS_DEV_SERVICE, containerLabelValue);

0 commit comments

Comments
 (0)