Skip to content

Commit

Permalink
Revert to Testcontainers-based build setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan971 committed Jan 9, 2025
1 parent 077a2d1 commit 2f3136b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 31 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/build-hotspot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ on:
jobs:
build-test:
runs-on: "ubuntu-latest"
services:
knotdns:
image: "cznic/knot:3.4"
ports:
- "5353:5353"
volumes:
- "${{ github.workspace }}/src/test/resources/knotdns:/var/lib/knotd"
steps:
- name: "Checkout repository"
uses: "actions/checkout@v4"
Expand All @@ -41,10 +34,6 @@ jobs:
set -euo pipefail
export VERSION="git-$(date +'%Y%m%d%H%M')-$(git rev-parse --short HEAD)"
export KNOTDNS_CI="localhost:5353"
export JAVAIOTMPDIR="$(pwd)/.github/tmpdir"
chmod -v -R 0777 "$JAVAIOTMPDIR"
mvn -B -e -fae --show-version -T$(nproc)C -Drevision="$VERSION" -DsurefireTmpDir="$(pwd)/.github/tmpdir" verify package
awk -F"," '{ instructions += $4 + $5; covered += $5 } END { print covered, "/", instructions, " instructions covered"; print 100*covered/instructions, "% covered" }' target/site/jacoco/jacoco.csv
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/mangadex/mcw/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,15 @@ public void run(ApplicationArguments args) throws Exception {

public record BuildInfo(
String version,
String commit,
String timestamp
) {

public static BuildInfo fromApplicationYaml() {
try {
var properties = new YamlPropertySourceLoader().load("meta", new ClassPathResource("application.yml")).getFirst();
var version = requireNonNull((String) properties.getProperty("spring.application.version"));
var commit = requireNonNull((String) properties.getProperty("spring.application.build.commit"));
var timestamp = requireNonNull((String) properties.getProperty("spring.application.build.timestamp"));
return new BuildInfo(version, commit, timestamp);
return new BuildInfo(version, timestamp);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/mangadex/mcw/MCW.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class MCW {
public static void main(String[] args) {
var buildInfo = BuildInfo.fromApplicationYaml();
if (asList(args).contains("--version")) {
System.out.printf("MCW version %s (%s %s)\n", buildInfo.version(), buildInfo.commit(), buildInfo.timestamp());
System.out.printf("MCW version %s (%s)\n", buildInfo.version(), buildInfo.timestamp());
return;
}

Expand Down
1 change: 0 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ spring:
name: @project.artifactId@
environment: "${ENVIRONMENT:local}"
build:
commit: @git.commit.id.describe-short@
timestamp: @build.timestamp@
version: @project.version@
jdkver: "${java.vendor.version}"
Expand Down
32 changes: 17 additions & 15 deletions src/test/java/org/mangadex/mcw/dns/KnotSidecar.java
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));
}

}

0 comments on commit 2f3136b

Please sign in to comment.