Skip to content

Commit

Permalink
Replace temporalite with the CLI dev-server (#351)
Browse files Browse the repository at this point in the history
Temporalite has been deprecated in favor of the CLI's dev-server functionality
  • Loading branch information
tdeebswihart authored Oct 20, 2023
1 parent 108215a commit cc11799
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 29 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/docker-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
${{ !inputs.sdk-repo-ref && format('--version {0}', inputs.sdk-version) || '' }} \
${{ inputs.semver-latest != 'none' && format('--semver-latest {0}', inputs.semver-latest) || '' }}
- name: Test with Temporalite
- name: Test with Dev Server
run: docker run --rm -i -v /tmp/temporal-certs:/certs ${{ env.FEATURES_BUILT_IMAGE_TAG }}

- name: Test with Cloud
Expand All @@ -92,4 +92,3 @@ jobs:
- name: Push image to DockerHub
if: inputs.do-push
run: go run . push-images

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ The built image will be tagged with `features:go-1.13.1`

### External Server and Namespace

By default, a [temporalite](https://github.com/DataDog/temporalite) is dynamically started at runtime to handle all
By default, a [CLI Dev Server](https://github.com/temporalio/cli/#start-the-server) is dynamically started at runtime to handle all
feature runs and a namespace is dynamically generated. To not start the embedded server, use `--server` to specify the
address of a server to use. Similarly, to not use a dynamic namespace (that may not be registered on the external
server), use `--namespace`.
Expand Down
6 changes: 3 additions & 3 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
"github.com/google/uuid"
"github.com/pmezard/go-difflib/difflib"
"github.com/temporalio/features/harness/go/cmd"
"github.com/temporalio/features/harness/go/devserver"
"github.com/temporalio/features/harness/go/harness"
"github.com/temporalio/features/harness/go/history"
"github.com/temporalio/features/harness/go/temporalite"
"github.com/temporalio/features/sdkbuild"
"github.com/urfave/cli/v2"
"go.temporal.io/sdk/client"
Expand Down Expand Up @@ -195,14 +195,14 @@ func (r *Runner) Run(ctx context.Context, patterns []string) error {

// If the server is not set, start it ourselves
if r.config.Server == "" {
server, err := temporalite.Start(temporalite.Options{
server, err := devserver.Start(devserver.Options{
Log: r.log,
// TODO(cretz): Configurable?
LogLevel: "error",
Namespace: r.config.Namespace,
})
if err != nil {
return fmt.Errorf("failed starting temporalite: %w", err)
return fmt.Errorf("failed starting devserver: %w", err)
}
defer server.Stop()
r.config.Server = server.FrontendHostPort
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package temporalite
package devserver

import (
"archive/tar"
Expand All @@ -21,19 +21,19 @@ import (
"go.temporal.io/sdk/log"
)

// DefaultVersion is the default Temporalite version when not provided.
// DefaultVersion is the default DevServer version when not provided.
const DefaultVersion = "v0.2.0"

// Temporalite is a running Temporalite instance.
type Temporalite struct {
// DevServer is a running DevServer instance.
type DevServer struct {
// The frontend host:port for use with Temporal SDK client.
FrontendHostPort string
cmd *exec.Cmd
}

// Temporalite start options.
// DevServer start options.
type Options struct {
// This logger is only used by this process, not Temporalite
// This logger is only used by this process, not DevServer
Log log.Logger
// Defaults to random free port
GetFrontendPort func() (int, error)
Expand All @@ -43,12 +43,12 @@ type Options struct {
Version string
// Defaults to unset
LogLevel string
// TODO(cretz): Other Temporalite options?
// TODO(cretz): Other DevServer options?
}

// Start a Temporalite server. This may download the server if not already
// Start a DevServer server. This may download the server if not already
// downloaded.
func Start(options Options) (*Temporalite, error) {
func Start(options Options) (*DevServer, error) {
if options.Log == nil {
options.Log = harness.DefaultLogger
}
Expand All @@ -75,7 +75,7 @@ func Start(options Options) (*Temporalite, error) {
return nil, err
}

// Temporalite has no way to give us the port they chose, so we have to find
// DevServer has no way to give us the port they chose, so we have to find
// our own free port
port, err := options.GetFrontendPort()
if err != nil {
Expand All @@ -85,8 +85,8 @@ func Start(options Options) (*Temporalite, error) {

// Start
args := []string{
"start",
"--ephemeral", "--headless", "--namespace", options.Namespace, "--port", portStr,
"server", "start-dev",
"--headless", "--namespace", options.Namespace, "--port", portStr,
"--dynamic-config-value", "system.forceSearchAttributesCacheRefreshOnRead=true",
"--dynamic-config-value", "system.enableActivityEagerExecution=true",
}
Expand All @@ -95,7 +95,7 @@ func Start(options Options) (*Temporalite, error) {
}
cmd := exec.Command(exePath, args...)
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
options.Log.Info("Starting Temporalite", "ExePath", exePath, "Args", args)
options.Log.Info("Starting DevServer", "ExePath", exePath, "Args", args)
if err := cmd.Start(); err != nil {
return nil, fmt.Errorf("failed starting: %w", err)
}
Expand All @@ -105,12 +105,12 @@ func Start(options Options) (*Temporalite, error) {
if err != nil {
return nil, err
}
return &Temporalite{FrontendHostPort: "127.0.0.1:" + portStr, cmd: cmd}, nil
return &DevServer{FrontendHostPort: "127.0.0.1:" + portStr, cmd: cmd}, nil
}

// Stop the running Temporalite server and wait for it to stop. This errors if
// Temporalite returned a failed exit code.
func (t *Temporalite) Stop() error {
// Stop the running DevServer server and wait for it to stop. This errors if
// DevServer returned a failed exit code.
func (t *DevServer) Stop() error {
if err := t.cmd.Process.Kill(); err != nil {
return err
}
Expand All @@ -119,7 +119,7 @@ func (t *Temporalite) Stop() error {

func (o *Options) loadExePath() (string, error) {
// Build path based on version and check if already present
exePath := filepath.Join(os.TempDir(), "features-temporalite-"+o.Version)
exePath := filepath.Join(os.TempDir(), "features-cli-"+o.Version)
if runtime.GOOS == "windows" {
exePath += ".exe"
}
Expand All @@ -136,7 +136,7 @@ func (o *Options) loadExePath() (string, error) {
if arch != "amd64" && arch != "arm64" {
return "", fmt.Errorf("unrecognized architecture %v", arch)
}
infoURL := fmt.Sprintf("https://temporal.download/temporalite/%v?platform=%v&arch=%v", o.Version, platform, arch)
infoURL := fmt.Sprintf("https://temporal.download/cli/%v?platform=%v&arch=%v", o.Version, platform, arch)

// Get info
info := struct {
Expand All @@ -158,7 +158,7 @@ func (o *Options) loadExePath() (string, error) {
}

// Download and extract
o.Log.Info("Downloading Temporalite", "Url", info.ArchiveURL, "ExePath", exePath)
o.Log.Info("Downloading CLI", "Url", info.ArchiveURL, "ExePath", exePath)
resp, err = http.Get(info.ArchiveURL)
if err != nil {
return "", fmt.Errorf("failed downloading: %w", err)
Expand All @@ -168,7 +168,7 @@ func (o *Options) loadExePath() (string, error) {
// atomic downloader would use a common temp file and check whether it exists
// and wait on it, but doing multiple downloads in racy situations is
// good/simple enough for now.
f, err := os.CreateTemp("", "temporalite-downloading-")
f, err := os.CreateTemp("", "cli-downloading-")
if err != nil {
return "", fmt.Errorf("failed creating temp file: %w", err)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package temporalite
package devserver

import (
"fmt"
Expand All @@ -21,7 +21,7 @@ func (p *portProvider) GetFreePort() (int, error) {
addr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:0")
if err != nil {
if addr, err = net.ResolveTCPAddr("tcp6", "[::1]:0"); err != nil {
panic(fmt.Sprintf("temporalite: failed to get free port: %v", err))
panic(fmt.Sprintf("cli: failed to get free port: %v", err))
}
}

Expand Down

0 comments on commit cc11799

Please sign in to comment.