Skip to content

Commit

Permalink
fixe the ports!
Browse files Browse the repository at this point in the history
  • Loading branch information
shelajev committed Sep 23, 2024
1 parent acc8a14 commit decaf63
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/test/java/com/testcontainers/TestMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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")
Expand All @@ -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));
Expand Down

0 comments on commit decaf63

Please sign in to comment.