-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert to Testcontainers-based build setup
- Loading branch information
1 parent
077a2d1
commit 2f3136b
Showing
5 changed files
with
19 additions
and
31 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
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
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 |
---|---|---|
@@ -1,44 +1,46 @@ | ||
package org.mangadex.mcw.dns; | ||
|
||
import static java.lang.System.getenv; | ||
|
||
import java.io.File; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.springframework.test.context.DynamicPropertySource; | ||
import org.testcontainers.containers.ComposeContainer; | ||
import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy; | ||
import org.testcontainers.junit.jupiter.Container; | ||
|
||
import org.mangadex.mcw.dns.DnsProperties.DnsDiscovery; | ||
import org.mangadex.mcw.dns.DnsProperties.DnsOptions; | ||
|
||
@TestConfiguration(proxyBeanMethods = false) | ||
public class KnotSidecar { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(KnotSidecar.class); | ||
|
||
private static final File KNOTDNS_COMPOSE_FILE = Paths.get("docker-compose.yml").toFile(); | ||
private static final int KNOTDNS_PORT_DNS = 15353; | ||
private static final int KNOTDNS_PORT_DNS = 5353; | ||
|
||
@Container | ||
static ComposeContainer knotdns = new ComposeContainer(KNOTDNS_COMPOSE_FILE) | ||
.withLocalCompose(true) | ||
.withExposedService("knotdns", KNOTDNS_PORT_DNS) | ||
.withTailChildContainers(true) | ||
.waitingFor("knotdns", new HostPortWaitStrategy()); | ||
.waitingFor("knotdns", new HostPortWaitStrategy().forPorts(KNOTDNS_PORT_DNS)); | ||
|
||
@DynamicPropertySource | ||
static void testNameservers(DynamicPropertyRegistry registry) { | ||
if (getenv("KNOTDNS_CI") != null) { | ||
registry.add("org.mangadex.mcw.dns.nameservers", () -> List.of(getenv("KNOTDNS_CI"))); | ||
} else { | ||
var knotdns = startContainerAndGetHostname() + ":" + KNOTDNS_PORT_DNS; | ||
registry.add("org.mangadex.mcw.dns.nameservers", () -> List.of(knotdns)); | ||
} | ||
} | ||
|
||
private static String startContainerAndGetHostname() { | ||
knotdns.start(); | ||
knotdns.waitingFor("knotdns", new HostPortWaitStrategy()); | ||
return knotdns.getServiceHost("knotdns", KNOTDNS_PORT_DNS); | ||
var host = knotdns.getServiceHost("knotdns", KNOTDNS_PORT_DNS); | ||
var port = knotdns.getServicePort("knotdns", KNOTDNS_PORT_DNS); | ||
LOGGER.info("Test KnotDNS server: '{}:{}'", host, port); | ||
|
||
registry.add("org.mangadex.mcw.dns.discovery", () -> DnsDiscovery.STATIC); | ||
registry.add("org.mangadex.mcw.dns.options", () -> List.of(DnsOptions.FORCE_TCP)); | ||
registry.add("org.mangadex.mcw.dns.nameservers", () -> List.of(host + ":" + port)); | ||
} | ||
|
||
} |