12
12
import org .testcontainers .lifecycle .Startables ;
13
13
import org .testcontainers .utility .DockerImageName ;
14
14
15
+ import java .io .IOException ;
15
16
import java .nio .file .Path ;
16
17
import java .nio .file .Paths ;
18
+ import java .util .List ;
17
19
import java .util .Scanner ;
18
20
19
21
import static org .testcontainers .utility .DockerImageName .parse ;
20
22
21
23
public class TestMain {
22
24
23
- public static void main (String [] args ) {
25
+ public static void main (String [] args ) throws IOException , InterruptedException {
24
26
Network network = Network .newNetwork ();
25
27
26
28
PostgreSQLContainer <?> postgres =
@@ -35,12 +37,13 @@ public static void main(String[] args) {
35
37
36
38
37
39
Path dockerfile = Paths .get ("Dockerfile" );
40
+
41
+ ;
42
+
38
43
GenericContainer <?> app = new GenericContainer <>(new ImageFromDockerfile ("gatling-demo-app" , false )
39
44
.withFileFromPath ("Dockerfile" , Paths .get ("Dockerfile" ))
40
45
.withFileFromPath ("target/java-local-development-workshop-0.0.1-SNAPSHOT.jar" , Paths .get ("target/java-local-development-workshop-0.0.1-SNAPSHOT.jar" ))
41
46
)
42
-
43
- .withExposedPorts (8080 )
44
47
.withEnv ("SPRING_KAFKA_BOOTSTRAP_SERVERS" , "BROKER://kafka:9092" )
45
48
.withEnv ("SPRING_DATASOURCE_URL" , "jdbc:postgresql://postgres:5432/test" )
46
49
.withEnv ("SPRING_DATASOURCE_USERNAME" , "test" )
@@ -49,19 +52,22 @@ public static void main(String[] args) {
49
52
.withEnv ("SPRING_CLOUD_AWS_CREDENTIALS_SECRET-KEY" , localStack .getSecretKey ())
50
53
.withEnv ("SPRING_CLOUD_AWS_REGION_STATIC" , localStack .getRegion ())
51
54
.withEnv ("SPRING_CLOUD_AWS_ENDPOINT" , "localstack:4566" )
52
-
55
+ . withExposedPorts ( 8080 )
53
56
.withNetwork (network )
54
- .waitingFor (Wait .forHttp ("/actuator/health" ))
55
- .withCreateContainerCmdModifier (createContainerCmd -> {
56
- var hostConfig = new HostConfig ();
57
- hostConfig .withMemory (1 * 1024L * 1024L );
58
- hostConfig .withCpuCount (1L );
59
- createContainerCmd .withHostConfig (hostConfig );
60
- }
61
- );
57
+ .waitingFor (Wait .forHttp ("/actuator/health" ));
58
+
59
+ // .withCreateContainerCmdModifier(createContainerCmd -> {
60
+ // var hostConfig = new HostConfig();
61
+ // hostConfig.withMemory(1024L * 1024L * 1024L);
62
+ // hostConfig.withCpuCount(1L);
63
+ // createContainerCmd.withHostConfig(hostConfig);
64
+ // }
65
+ // );
62
66
63
67
Startables .deepStart (postgres , kafka , localStack ).join ();
68
+ localStack .execInContainer ("awslocal" , "s3api" , "create-bucket" , "--bucket product-images" );
64
69
70
+ app .setPortBindings (List .of ("8080:8080" ));
65
71
app .start ();
66
72
67
73
CloudflaredContainer cloudflaredContainer = new CloudflaredContainer (parse ("cloudflare/cloudflared" ), app .getMappedPort (8080 ));
0 commit comments