Skip to content

Commit

Permalink
add devservice
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrebert committed Aug 21, 2024
1 parent 76249ee commit 5a5084b
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 6 deletions.
8 changes: 4 additions & 4 deletions docs/modules/ROOT/pages/includes/quarkus-temporal.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_TEMPORAL_ENABLE_MOCK+++`
endif::add-copy-button-to-env-var[]
--|boolean
|`false`
|`true`


a|icon:lock[title=Fixed at build time] [[quarkus-temporal_quarkus-temporal-start-workers]]`link:#quarkus-temporal_quarkus-temporal-start-workers[quarkus.temporal.start-workers]`
Expand Down Expand Up @@ -630,7 +630,7 @@ a| [[quarkus-temporal_quarkus-temporal-connection-target]]`link:#quarkus-tempora

[.description]
--
Sets a target string, which can be either a valid `NameResolver`-compliant URI, or an authority string. See `ManagedChannelBuilder++#++forTarget(String)` for more information about parameter format. Default is 127.0.0.1:7233
Sets a target string, which can be either a valid `NameResolver`-compliant URI, or an authority string. See `ManagedChannelBuilder++#++forTarget(String)` for more information about parameter format.

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_TEMPORAL_CONNECTION_TARGET+++[]
Expand All @@ -639,7 +639,7 @@ ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_TEMPORAL_CONNECTION_TARGET+++`
endif::add-copy-button-to-env-var[]
--|string
|`127.0.0.1:7233`
|required icon:exclamation-circle[title=Configuration property is required]


a| [[quarkus-temporal_quarkus-temporal-connection-enable-https]]`link:#quarkus-temporal_quarkus-temporal-connection-enable-https[quarkus.temporal.connection.enable-https]`
Expand Down Expand Up @@ -840,7 +840,7 @@ Environment variable: `+++QUARKUS_TEMPORAL_WORKFLOW_RETRIES_INITIAL_INTERVAL+++`
endif::add-copy-button-to-env-var[]
--|link:https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html[Duration]
link:#duration-note-anchor-{summaryTableId}[icon:question-circle[title=More information about the Duration format]]
|`1s`
|`1S`


a| [[quarkus-temporal_quarkus-temporal-workflow-retries-backoff-coefficient]]`link:#quarkus-temporal_quarkus-temporal-workflow-retries-backoff-coefficient[quarkus.temporal.workflow.retries.backoff-coefficient]`
Expand Down
14 changes: 14 additions & 0 deletions extension/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc-common-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-devservices-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkiverse.temporal</groupId>
<artifactId>quarkus-temporal</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.quarkiverse.temporal.deployment.devui;

import org.testcontainers.containers.GenericContainer;
import org.testcontainers.utility.DockerImageName;

// import io.quarkus.devservices.common.ConfigureUtil;

public class TemporalContainer extends GenericContainer<TemporalContainer> {

private static final Integer SERVER_EXPOSED_PORT = 7233;
private static final Integer UI_EXPOSED_PORT = 8233;

private final TemporalDevserviceConfig config;
private String serviceName;
// private String hostname;

public TemporalContainer(DockerImageName dockerImageName, TemporalDevserviceConfig config) {
super(dockerImageName);
this.config = config;
this.serviceName = "temporal";
}

@Override
protected void configure() {
super.configure();

withCreateContainerCmdModifier(cmd -> {
cmd.withEntrypoint("/usr/local/bin/temporal");
cmd.withCmd("server", "start-dev", "--ip", "0.0.0.0");
});

withExposedPorts(SERVER_EXPOSED_PORT, UI_EXPOSED_PORT);

withLabel("quarkus-devservice-temporal", serviceName);

withReuse(config.reuse());

// hostname = ConfigureUtil.configureSharedNetwork(this, "temporal-" + serviceName);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.quarkiverse.temporal.deployment.devui;

import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;

@ConfigMapping(prefix = "quarkus.temporal.devservice")
@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
public interface TemporalDevserviceConfig {

/**
* Enable the Temporal Devservice.
*/
@WithDefault("true")
Boolean enabled();

/**
* The image to use for the Temporal Devservice.
*/
@WithDefault("temporalio/auto-setup")
String image();

/**
* The version of the image to use for the Temporal Devservice.
*/
@WithDefault("latest")
String version();

/**
* Whether to reuse the Temporal Devservice.
*/
@WithDefault("true")
Boolean reuse();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.quarkiverse.temporal.deployment.devui;

import java.util.Map;

import org.testcontainers.utility.DockerImageName;

import io.quarkus.deployment.IsNormal;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.BuildSteps;
import io.quarkus.deployment.builditem.DevServicesResultBuildItem;
import io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig;
import io.quarkus.devservices.common.ContainerLocator;

@BuildSteps(onlyIfNot = IsNormal.class, onlyIf = { GlobalDevServicesConfig.Enabled.class })
public class TemporalDevserviceProcessor {

private static final Integer SERVER_EXPOSED_PORT = 7233;
private static final Integer UI_EXPOSED_PORT = 8233;
private static final String DEV_SERVICE_LABEL = "quarkus-devservice-temporal";
private static final ContainerLocator containerLocator = new ContainerLocator(DEV_SERVICE_LABEL, SERVER_EXPOSED_PORT);

@BuildStep
public void build(TemporalDevserviceConfig config, BuildProducer<DevServicesResultBuildItem> devServiceProducer) {
if (Boolean.FALSE.equals(config.enabled())) {
return;
}

var imageStr = config.image() + ":" + config.version();
var image = DockerImageName.parse(imageStr)
.asCompatibleSubstituteFor(imageStr);

var serverContainer = new TemporalContainer(image, config);
serverContainer.start();

var serverPort = serverContainer.getMappedPort(SERVER_EXPOSED_PORT);
devServiceProducer.produce(new DevServicesResultBuildItem("temporal", serverContainer.getContainerId(), Map.of(
"quarkus.temporal.connection.target", "localhost:" + serverPort)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ public interface ConnectionRuntimeConfig {
/**
* Sets a target string, which can be either a valid {@link NameResolver}-compliant URI, or an
* authority string. See {@link ManagedChannelBuilder#forTarget(String)} for more information
* about parameter format. Default is 127.0.0.1:7233
* about parameter format.
*/
@WithDefault("127.0.0.1:7233")
String target();

/**
Expand Down

0 comments on commit 5a5084b

Please sign in to comment.