From decaf6383470e9095a2c3d93643f6cf8a19fdcf7 Mon Sep 17 00:00:00 2001 From: shelajev Date: Mon, 23 Sep 2024 16:47:33 +0300 Subject: [PATCH] fixe the ports! --- .../java/com/testcontainers/TestMain.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/test/java/com/testcontainers/TestMain.java b/src/test/java/com/testcontainers/TestMain.java index 96600fa..be4036f 100644 --- a/src/test/java/com/testcontainers/TestMain.java +++ b/src/test/java/com/testcontainers/TestMain.java @@ -12,15 +12,17 @@ import org.testcontainers.lifecycle.Startables; import org.testcontainers.utility.DockerImageName; +import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.List; import java.util.Scanner; import static org.testcontainers.utility.DockerImageName.parse; public class TestMain { - public static void main(String[] args) { + public static void main(String[] args) throws IOException, InterruptedException { Network network = Network.newNetwork(); PostgreSQLContainer postgres = @@ -35,12 +37,13 @@ public static void main(String[] args) { Path dockerfile = Paths.get("Dockerfile"); + + ; + GenericContainer app = new GenericContainer<>(new ImageFromDockerfile("gatling-demo-app", false) .withFileFromPath("Dockerfile", Paths.get("Dockerfile")) .withFileFromPath("target/java-local-development-workshop-0.0.1-SNAPSHOT.jar", Paths.get("target/java-local-development-workshop-0.0.1-SNAPSHOT.jar")) ) - - .withExposedPorts(8080) .withEnv("SPRING_KAFKA_BOOTSTRAP_SERVERS", "BROKER://kafka:9092") .withEnv("SPRING_DATASOURCE_URL", "jdbc:postgresql://postgres:5432/test") .withEnv("SPRING_DATASOURCE_USERNAME", "test") @@ -49,19 +52,22 @@ public static void main(String[] args) { .withEnv("SPRING_CLOUD_AWS_CREDENTIALS_SECRET-KEY", localStack.getSecretKey()) .withEnv("SPRING_CLOUD_AWS_REGION_STATIC", localStack.getRegion()) .withEnv("SPRING_CLOUD_AWS_ENDPOINT", "localstack:4566") - + .withExposedPorts(8080) .withNetwork(network) - .waitingFor(Wait.forHttp("/actuator/health")) - .withCreateContainerCmdModifier(createContainerCmd -> { - var hostConfig = new HostConfig(); - hostConfig.withMemory(1 * 1024L * 1024L); - hostConfig.withCpuCount(1L); - createContainerCmd.withHostConfig(hostConfig); - } - ); + .waitingFor(Wait.forHttp("/actuator/health")); + +// .withCreateContainerCmdModifier(createContainerCmd -> { +// var hostConfig = new HostConfig(); +// hostConfig.withMemory(1024L * 1024L * 1024L); +// hostConfig.withCpuCount(1L); +// createContainerCmd.withHostConfig(hostConfig); +// } +// ); Startables.deepStart(postgres, kafka, localStack).join(); + localStack.execInContainer("awslocal", "s3api", "create-bucket", "--bucket product-images"); + app.setPortBindings(List.of("8080:8080")); app.start(); CloudflaredContainer cloudflaredContainer = new CloudflaredContainer(parse("cloudflare/cloudflared"), app.getMappedPort(8080));