Skip to content

Commit b626647

Browse files
committed
initial workflow dashboard config
Signed-off-by: salaboy <Salaboy@gmail.com>
1 parent fd2606b commit b626647

File tree

3 files changed

+142
-5
lines changed

3 files changed

+142
-5
lines changed

spring-boot-examples/workflows/patterns/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@
4747
<artifactId>microcks-testcontainers</artifactId>
4848
<scope>test</scope>
4949
</dependency>
50+
<dependency>
51+
<groupId>org.testcontainers</groupId>
52+
<artifactId>testcontainers-postgresql</artifactId>
53+
<version>2.0.1</version>
54+
<scope>test</scope>
55+
</dependency>
5056
</dependencies>
5157

5258
<build>

spring-boot-examples/workflows/patterns/src/test/java/io/dapr/springboot/examples/wfp/DaprTestContainersConfig.java

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313

1414
package io.dapr.springboot.examples.wfp;
1515

16+
1617
import io.dapr.testcontainers.Component;
1718
import io.dapr.testcontainers.DaprContainer;
18-
import io.dapr.testcontainers.DaprLogLevel;
19+
import io.dapr.testcontainers.WorkflowDashboardContainer;
1920
import io.github.microcks.testcontainers.MicrocksContainersEnsemble;
2021
import org.junit.runner.Description;
2122
import org.junit.runners.model.Statement;
@@ -26,9 +27,12 @@
2627
import org.springframework.test.context.DynamicPropertyRegistrar;
2728
import org.testcontainers.DockerClientFactory;
2829
import org.testcontainers.containers.Network;
30+
import org.testcontainers.postgresql.PostgreSQLContainer;
31+
import org.testcontainers.utility.DockerImageName;
2932

30-
import java.util.Collections;
33+
import java.util.HashMap;
3134
import java.util.List;
35+
import java.util.Map;
3236

3337
import static io.dapr.testcontainers.DaprContainerConstants.DAPR_RUNTIME_IMAGE_TAG;
3438

@@ -45,19 +49,44 @@
4549
@TestConfiguration(proxyBeanMethods = false)
4650
public class DaprTestContainersConfig {
4751

52+
Map<String, String> postgreSQLDetails = new HashMap<>();
53+
54+
{{
55+
postgreSQLDetails.put("host", "postgresql");
56+
postgreSQLDetails.put("user", "postgres");
57+
postgreSQLDetails.put("password", "postgres");
58+
postgreSQLDetails.put("database", "dapr");
59+
postgreSQLDetails.put("port", "5432");
60+
postgreSQLDetails.put("actorStateStore", String.valueOf(true));
61+
62+
}}
63+
64+
private Component stateStoreComponent = new Component("kvstore",
65+
"state.postgresql", "v2", postgreSQLDetails);
66+
4867
@Bean
4968
@ServiceConnection
50-
public DaprContainer daprContainer(Network network) {
69+
public DaprContainer daprContainer(Network network, PostgreSQLContainer postgreSQLContainer) {
5170

5271
return new DaprContainer(DAPR_RUNTIME_IMAGE_TAG)
5372
.withAppName("workflow-patterns-app")
54-
.withComponent(new Component("kvstore", "state.in-memory", "v1", Collections.singletonMap("actorStateStore", String.valueOf(true))))
73+
.withComponent(stateStoreComponent)
5574
.withAppPort(8080)
5675
.withNetwork(network)
5776
.withAppHealthCheckPath("/actuator/health")
58-
.withAppChannelAddress("host.testcontainers.internal");
77+
.withAppChannelAddress("host.testcontainers.internal")
78+
.dependsOn(postgreSQLContainer);
5979
}
6080

81+
@Bean
82+
public PostgreSQLContainer postgreSQLContainer(Network network) {
83+
return new PostgreSQLContainer(DockerImageName.parse("postgres"))
84+
.withNetworkAliases("postgresql")
85+
.withDatabaseName("dapr")
86+
.withUsername("postgres")
87+
.withPassword("postgres")
88+
.withNetwork(network);
89+
}
6190

6291
@Bean
6392
MicrocksContainersEnsemble microcksEnsemble(Network network) {
@@ -66,6 +95,14 @@ MicrocksContainersEnsemble microcksEnsemble(Network network) {
6695
.withMainArtifacts("third-parties/remote-http-service.yaml");
6796
}
6897

98+
@Bean
99+
public WorkflowDashboardContainer workflowDashboard(Network network) {
100+
return new WorkflowDashboardContainer(WorkflowDashboardContainer.getDefaultImageName())
101+
.withNetwork(network)
102+
.withStateStoreComponent(stateStoreComponent)
103+
.withExposedPorts(8080);
104+
}
105+
69106
@Bean
70107
public DynamicPropertyRegistrar endpointsProperties(MicrocksContainersEnsemble ensemble) {
71108
// We need to replace the default endpoints with those provided by Microcks.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright 2024 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package io.dapr.testcontainers;
15+
16+
import io.dapr.testcontainers.converter.ComponentYamlConverter;
17+
import io.dapr.testcontainers.converter.YamlConverter;
18+
import io.dapr.testcontainers.converter.YamlMapperFactory;
19+
import org.testcontainers.containers.GenericContainer;
20+
import org.testcontainers.images.builder.Transferable;
21+
import org.testcontainers.utility.DockerImageName;
22+
import org.yaml.snakeyaml.Yaml;
23+
24+
/**
25+
* Test container for Dapr Workflow Dashboard.
26+
*/
27+
public class WorkflowDashboardContainer extends GenericContainer<WorkflowDashboardContainer> {
28+
29+
private static final Yaml YAML_MAPPER = YamlMapperFactory.create();
30+
private static final YamlConverter<Component> COMPONENT_CONVERTER = new ComponentYamlConverter(YAML_MAPPER);
31+
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName
32+
.parse("public.ecr.aws/diagrid-dev/diagrid-dashboard:latest");
33+
private int dashboardPort = 8080;
34+
private Component stateStoreComponent;
35+
36+
/**
37+
* Creates a new Dapr scheduler container.
38+
* @param dockerImageName Docker image name.
39+
*/
40+
public WorkflowDashboardContainer(DockerImageName dockerImageName) {
41+
super(dockerImageName);
42+
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
43+
withExposedPorts(dashboardPort);
44+
}
45+
46+
public WorkflowDashboardContainer withStateStoreComponent(Component stateStoreComponent) {
47+
this.stateStoreComponent = stateStoreComponent;
48+
return this;
49+
}
50+
51+
/**
52+
* Creates a new Dapr schedulers container.
53+
* @param image Docker image name.
54+
*/
55+
public WorkflowDashboardContainer(String image) {
56+
this(DockerImageName.parse(image));
57+
}
58+
59+
@Override
60+
protected void configure() {
61+
super.configure();
62+
if (stateStoreComponent != null) {
63+
String componentYaml = COMPONENT_CONVERTER.convert(stateStoreComponent);
64+
withCopyToContainer(Transferable.of(componentYaml), "/app/components/" + stateStoreComponent.getName() + ".yaml");
65+
}
66+
67+
withEnv("COMPONENT_FILE", "/app/components/" + stateStoreComponent.getName() + ".yaml");
68+
69+
}
70+
71+
public static DockerImageName getDefaultImageName() {
72+
return DEFAULT_IMAGE_NAME;
73+
}
74+
75+
public WorkflowDashboardContainer withPort(Integer port) {
76+
this.dashboardPort = port;
77+
return this;
78+
}
79+
80+
public int getPort() {
81+
return dashboardPort;
82+
}
83+
84+
// Required by spotbugs plugin
85+
@Override
86+
public boolean equals(Object o) {
87+
return super.equals(o);
88+
}
89+
90+
@Override
91+
public int hashCode() {
92+
return super.hashCode();
93+
}
94+
}

0 commit comments

Comments
 (0)