Skip to content

Commit

Permalink
implemented .setCurrentProject(project.getBasedir().toString()) into …
Browse files Browse the repository at this point in the history
…MavenArtifactResolver in order to resolve go-offline issue, merged 3 commits to 1
  • Loading branch information
Your Name authored and Noonchi1004 committed Oct 10, 2022
1 parent 86049c9 commit a1d8d06
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ private void resolveAppModel(final MavenArtifactResolver resolver, final Artifac
private MavenArtifactResolver getResolver() throws MojoExecutionException {
try {
return MavenArtifactResolver.builder()
.setCurrentProject(project.getBasedir().toString())
.setRemoteRepositoryManager(remoteRepositoryManager)
.setRemoteRepositories(repos)
.setPreferPomsFromWorkspace(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,9 @@ private RunningDevService startContainer(DockerStatusBuildItem dockerStatusBuild

String internalUrl = startURL(oidcContainer.getHost(), oidcContainer.getPort(), oidcContainer.keycloakX);
String hostUrl = oidcContainer.useSharedNetwork
? startURL("localhost", oidcContainer.fixedExposedPort.getAsInt(), oidcContainer.keycloakX)
// we need to use auto-detected host and port, so it works when docker host != localhost
? startURL(oidcContainer.getSharedNetworkExternalHost(), oidcContainer.getSharedNetworkExternalPort(),
oidcContainer.keycloakX)
: null;

Map<String, String> configs = prepareConfiguration(keycloakBuildItemBuildProducer, internalUrl, hostUrl,
Expand Down Expand Up @@ -406,7 +408,7 @@ public QuarkusOidcContainer(DockerImageName dockerImageName, OptionalInt fixedEx
this.javaOpts = javaOpts;
this.keycloakX = isKeycloakX(dockerImageName);

if (sharedContainer && fixedExposedPort.isEmpty()) {
if (useSharedNetwork && fixedExposedPort.isEmpty()) {
// We need to know the port we are exposing when using the shared network, in order to be able to tell
// Keycloak what the client URL is. This is necessary in order for Keycloak to create the proper 'issuer'
// when creating tokens
Expand Down Expand Up @@ -435,6 +437,11 @@ protected void configure() {

if (fixedExposedPort.isPresent()) {
addFixedExposedPort(fixedExposedPort.getAsInt(), KEYCLOAK_PORT);
if (useSharedNetwork) {
// expose random port for which we are able to ask Testcontainers for the actual mapped port at runtime
// as from the host's perspective Testcontainers actually expose container ports on random host port
addExposedPort(KEYCLOAK_PORT);
}
} else {
addExposedPort(KEYCLOAK_PORT);
}
Expand Down Expand Up @@ -528,6 +535,24 @@ public String getHost() {
return super.getHost();
}

/**
* Host name used for calls from outside of docker when {@code useSharedNetwork} is true.
*
* @return host name
*/
private String getSharedNetworkExternalHost() {
return super.getHost();
}

/**
* Host port used for calls from outside of docker when {@code useSharedNetwork} is true.
*
* @return port
*/
private int getSharedNetworkExternalPort() {
return getFirstMappedPort();
}

public int getPort() {
if (useSharedNetwork) {
return KEYCLOAK_PORT;
Expand Down

0 comments on commit a1d8d06

Please sign in to comment.