-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add capability to use --optimized option (#170)
* Add capability to use --optimized option Signed-off-by: Robin Meese <[email protected]> * Fixes comments on PR Signed-off-by: Robin Meese <[email protected]> * Add Documentation and remove todo´s Signed-off-by: Robin Meese <[email protected]> * add implicit call for .withProductionMode() Signed-off-by: Robin Meese <[email protected]> * slightly adjusted and moved documentation to proper chapter Signed-off-by: Niko Köbler <[email protected]> --------- Signed-off-by: Robin Meese <[email protected]> Signed-off-by: Niko Köbler <[email protected]> Co-authored-by: Niko Köbler <[email protected]>
- Loading branch information
Showing
5 changed files
with
122 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/test/java/dasniko/testcontainers/keycloak/KeycloakContainerOptimizedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package dasniko.testcontainers.keycloak; | ||
|
||
import io.restassured.RestAssured; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.images.builder.ImageFromDockerfile; | ||
|
||
import java.nio.file.Paths; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.hamcrest.Matchers.startsWith; | ||
|
||
public class KeycloakContainerOptimizedTest { | ||
|
||
public static final String UPDATING_THE_CONFIGURATION = "Updating the configuration and installing your custom providers, if any. Please wait."; | ||
private KeycloakContainer keycloakContainer; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
try (GenericContainer<?> container = new GenericContainer<>( | ||
new ImageFromDockerfile("temporary-keycloak-image", false) | ||
.withDockerfile(Paths.get("src/test/resources/Dockerfile")) | ||
.withTarget("builder"))) { | ||
try (KeycloakContainer keycloak = new KeycloakContainer(container.getDockerImageName() + ":latest") | ||
.useTls() | ||
.withEnv("KC_HOSTNAME_STRICT", "false") | ||
.withOptimizedFlag()) { | ||
keycloakContainer = keycloak; | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
public void shouldBeAvailableOnHTTPS() { | ||
keycloakContainer.start(); | ||
RestAssured.useRelaxedHTTPSValidation(); | ||
assertThat(keycloakContainer.getAuthServerUrl(), startsWith("https://")); | ||
given() | ||
.when().get(keycloakContainer.getAuthServerUrl()) | ||
.then().statusCode(200); | ||
} | ||
|
||
@Test | ||
public void shouldBeAvailableWithProfileProd() { | ||
keycloakContainer.start(); | ||
assertThat(keycloakContainer.getLogs(), containsString("Profile prod activated.")); | ||
} | ||
|
||
@Test | ||
public void shouldBeAvailableWithoutInstallingProviderLogMessage() { | ||
keycloakContainer.start(); | ||
assertThat(keycloakContainer.getLogs(), | ||
not(containsString(UPDATING_THE_CONFIGURATION))); | ||
} | ||
|
||
@Test | ||
public void shouldStartWithProviderInstallationLogMessageWhenOptimizedIsNotSet() { | ||
try (KeycloakContainer keycloak = new KeycloakContainer()) { | ||
keycloak.start(); | ||
assertThat(keycloak.getLogs(), | ||
containsString(UPDATING_THE_CONFIGURATION)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -230,5 +230,4 @@ private void testDebugPortAvailable(final String debugHost, final int debugPort) | |
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM quay.io/keycloak/keycloak:nightly AS builder | ||
|
||
# copied from: https://www.keycloak.org/server/containers | ||
# DISCLAIMER THIS IS ONLY FOR TESTING PURPOSE. DO NOT, I REAPEAT DO NOT USE THIS Dockerfile IN PRODUCTION | ||
|
||
ENV KC_HEALTH_ENABLED=true | ||
|
||
WORKDIR /opt/keycloak | ||
# for demonstration purposes only, please make sure to use proper certificates in production instead | ||
RUN keytool -genkeypair -storepass password -storetype PKCS12 -keyalg RSA -keysize 2048 -dname "CN=server" -alias server -ext "SAN:c=DNS:localhost,IP:127.0.0.1" -keystore conf/server.keystore | ||
RUN /opt/keycloak/bin/kc.sh build | ||
|
||
FROM quay.io/keycloak/keycloak:nightly | ||
COPY --from=builder /opt/keycloak/ /opt/keycloak/ | ||
|
||
ENTRYPOINT ["/opt/keycloak/bin/kc.sh"] |