Skip to content

Commit 4c90f6d

Browse files
committed
Add support for Temporal (#2339)
1 parent 3512912 commit 4c90f6d

File tree

11 files changed

+445
-0
lines changed

11 files changed

+445
-0
lines changed

embedded-temporal/README.adoc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
=== embedded-temporal
2+
3+
==== Maven dependency
4+
5+
.pom.xml
6+
[source,xml]
7+
----
8+
<dependency>
9+
<groupId>com.playtika.testcontainers</groupId>
10+
<artifactId>embedded-temporal</artifactId>
11+
<scope>test</scope>
12+
</dependency>
13+
----
14+
15+
==== Consumes (via `bootstrap.properties`)
16+
17+
* `embedded.temporal.enabled` `(true|false, default is true)`
18+
* `embedded.temporal.reuseContainer` `(true|false, default is false)`
19+
* `embedded.temporal.cliVersion` `(default is '1.3.0')`
20+
** Temporal CLI versions on https://github.com/temporalio/cli/releases
21+
22+
==== Produces
23+
24+
* `embedded.temporal.host`
25+
* `embedded.temporal.port`
26+
* `embedded.temporal.networkAlias`
27+
* `embedded.temporal.internalPort`

embedded-temporal/pom.xml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>com.playtika.testcontainers</groupId>
9+
<artifactId>testcontainers-spring-boot-parent</artifactId>
10+
<version>3.1.11</version>
11+
<relativePath>../testcontainers-spring-boot-parent</relativePath>
12+
</parent>
13+
14+
<artifactId>embedded-temporal</artifactId>
15+
16+
<properties>
17+
<temporal.version>1.28.4</temporal.version>
18+
</properties>
19+
20+
<dependencyManagement>
21+
<dependencies>
22+
<dependency>
23+
<groupId>io.temporal</groupId>
24+
<artifactId>temporal-bom</artifactId>
25+
<version>${temporal.version}</version>
26+
<type>pom</type>
27+
<scope>import</scope>
28+
</dependency>
29+
</dependencies>
30+
</dependencyManagement>
31+
32+
<dependencies>
33+
<dependency>
34+
<groupId>com.playtika.testcontainers</groupId>
35+
<artifactId>testcontainers-common</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.springframework.boot</groupId>
39+
<artifactId>spring-boot-starter-webflux</artifactId>
40+
<scope>test</scope>
41+
<exclusions>
42+
<exclusion>
43+
<groupId>org.springframework.boot</groupId>
44+
<artifactId>spring-boot-starter-logging</artifactId>
45+
</exclusion>
46+
</exclusions>
47+
</dependency>
48+
<dependency>
49+
<groupId>io.temporal</groupId>
50+
<artifactId>temporal-spring-boot-starter</artifactId>
51+
<scope>test</scope>
52+
<exclusions>
53+
<exclusion>
54+
<groupId>org.springframework.boot</groupId>
55+
<artifactId>spring-boot-starter-logging</artifactId>
56+
</exclusion>
57+
</exclusions>
58+
</dependency>
59+
</dependencies>
60+
61+
</project>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package com.playtika.testcontainer.temporal;
2+
3+
import com.playtika.testcontainer.common.spring.DockerPresenceBootstrapConfiguration;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
6+
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
7+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
8+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
9+
import org.springframework.context.annotation.Bean;
10+
import org.springframework.context.annotation.Configuration;
11+
import org.springframework.core.env.ConfigurableEnvironment;
12+
import org.springframework.core.env.MapPropertySource;
13+
import org.testcontainers.containers.GenericContainer;
14+
import org.testcontainers.containers.Network;
15+
import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy;
16+
import org.testcontainers.images.builder.ImageFromDockerfile;
17+
18+
import java.util.LinkedHashMap;
19+
import java.util.Optional;
20+
21+
import static com.playtika.testcontainer.common.utils.ContainerUtils.configureCommonsAndStart;
22+
import static com.playtika.testcontainer.temporal.TemporalProperties.BEAN_NAME_EMBEDDED_TEMPORAL;
23+
import static com.playtika.testcontainer.temporal.TemporalProperties.INTERNAL_PORT;
24+
import static com.playtika.testcontainer.temporal.TemporalProperties.INTERNAL_UI_PORT;
25+
26+
@Slf4j
27+
@Configuration
28+
@ConditionalOnExpression("${embedded.containers.enabled:true}")
29+
@AutoConfigureAfter(DockerPresenceBootstrapConfiguration.class)
30+
@ConditionalOnProperty(
31+
name = "embedded.temporal.enabled",
32+
havingValue = "true",
33+
matchIfMissing = true)
34+
@EnableConfigurationProperties(TemporalProperties.class)
35+
public class EmbeddedTemporalBootstrapConfiguration {
36+
37+
private static final String TEMPORAL_NETWORK_ALIAS = "temporal.testcontainer.docker";
38+
39+
@Bean(value = BEAN_NAME_EMBEDDED_TEMPORAL, destroyMethod = "stop")
40+
public GenericContainer<?> temporal(ConfigurableEnvironment environment,
41+
TemporalProperties properties,
42+
Optional<Network> network) {
43+
44+
GenericContainer<?> container =
45+
new GenericContainer<>(new ImageFromDockerfile(properties.getDefaultDockerImage(), false)
46+
.withFileFromClasspath("Dockerfile", "/Dockerfile")
47+
.withBuildArg("TEMPORAL_CLI_VERSION", properties.getCliVersion()))
48+
.withExposedPorts(INTERNAL_PORT)
49+
.withNetworkAliases(TEMPORAL_NETWORK_ALIAS)
50+
.waitingFor(new HostPortWaitStrategy());
51+
52+
if (properties.isUiEnabled()) {
53+
container
54+
.withCommand("--ip", "0.0.0.0")
55+
.addExposedPort(INTERNAL_UI_PORT);
56+
}
57+
58+
network.ifPresent(container::withNetwork);
59+
60+
configureCommonsAndStart(container, properties, log);
61+
62+
registerTemporalEnvironment(container, environment, properties);
63+
64+
return container;
65+
}
66+
67+
private void registerTemporalEnvironment(GenericContainer<?> container,
68+
ConfigurableEnvironment environment,
69+
TemporalProperties properties) {
70+
71+
String host = container.getHost();
72+
Integer port = container.getMappedPort(INTERNAL_PORT);
73+
74+
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
75+
map.put("embedded.temporal.host", host);
76+
map.put("embedded.temporal.port", port);
77+
map.put("embedded.temporal.networkAlias", TEMPORAL_NETWORK_ALIAS);
78+
map.put("embedded.temporal.internalPort", INTERNAL_PORT);
79+
80+
log.info("Temporal Server started. Available on: http://{}:{}", host, port);
81+
82+
if (properties.isUiEnabled()) {
83+
Integer uiPort = container.getMappedPort(INTERNAL_UI_PORT);
84+
map.put("embedded.temporal.uiPort", uiPort);
85+
log.info("Temporal UI started. Available on: http://{}:{}", host, uiPort);
86+
}
87+
88+
MapPropertySource propertySource = new MapPropertySource("embeddedTemporalInfo", map);
89+
environment.getPropertySources().addFirst(propertySource);
90+
}
91+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.playtika.testcontainer.temporal;
2+
3+
import com.playtika.testcontainer.common.properties.CommonContainerProperties;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
import org.springframework.boot.context.properties.ConfigurationProperties;
7+
8+
@Data
9+
@EqualsAndHashCode(callSuper = true)
10+
@ConfigurationProperties("embedded.temporal")
11+
public class TemporalProperties extends CommonContainerProperties {
12+
13+
public static final String BEAN_NAME_EMBEDDED_TEMPORAL = "embeddedTemporal";
14+
public static final int INTERNAL_PORT = 7233;
15+
public static final int INTERNAL_UI_PORT = 8233;
16+
17+
private boolean uiEnabled;
18+
private String cliVersion = "1.3.0";
19+
20+
@Override
21+
public String getDefaultDockerImage() {
22+
return "temporalio/dev:" + cliVersion;
23+
}
24+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
ARG BASE_IMAGE=alpine:3
2+
3+
FROM ${BASE_IMAGE} AS builder
4+
ARG TEMPORAL_CLI_VERSION
5+
6+
ADD https://temporal.download/cli.sh /tmp/cli.sh
7+
RUN sh /tmp/cli.sh --version $TEMPORAL_CLI_VERSION --dir /tmp
8+
9+
FROM ${BASE_IMAGE} AS runtime
10+
11+
COPY --from=builder /tmp/bin/temporal /bin/temporal
12+
13+
ENTRYPOINT ["temporal", "server", "start-dev"]
14+
CMD ["--ip", "0.0.0.0", "--headless"]
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"groups": [
3+
],
4+
"properties": [
5+
{
6+
"name": "embedded.temporal.enabled",
7+
"type": "java.lang.Boolean",
8+
"description": "Enables or disables the Temporal container.",
9+
"defaultValue": "true"
10+
},
11+
{
12+
"name": "embedded.temporal.cli-version",
13+
"type": "java.lang.String",
14+
"description": "The Temporal CLI version.",
15+
"defaultValue": "1.3.0"
16+
},
17+
{
18+
"name": "embedded.temporal.ui-enabled",
19+
"type": "java.lang.Boolean",
20+
"description": "Enables or disables the Temporal UI.",
21+
"defaultValue": "false"
22+
}
23+
],
24+
"hints": [
25+
{
26+
"name": "embedded.temporal.enabled",
27+
"values": [
28+
{
29+
"value": "true",
30+
"description": "Enables the Temporal container."
31+
},
32+
{
33+
"value": "false",
34+
"description": "Disables the Temporal container."
35+
}
36+
]
37+
},
38+
{
39+
"name": "embedded.temporal.cli-version",
40+
"values": [
41+
{
42+
"value": "1.3.0",
43+
"description": "Default Temporal CLI Ref https://github.com/temporalio/cli/releases for further info."
44+
}
45+
]
46+
},
47+
{
48+
"name": "embedded.temporal.ui-enabled",
49+
"values": [
50+
{
51+
"value": "true",
52+
"description": "Enables the Temporal UI."
53+
},
54+
{
55+
"value": "false",
56+
"description": "Disables the Temporal UI."
57+
}
58+
]
59+
}
60+
]
61+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
2+
com.playtika.testcontainer.temporal.EmbeddedTemporalBootstrapConfiguration

0 commit comments

Comments
 (0)