Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
Ensure temporalite build in headless mode
Browse files Browse the repository at this point in the history
Ensures we don't import github.com/temporalio/ui-server/v2 dependency
when we use the headless build tag.
  • Loading branch information
lminaudier committed Dec 1, 2022
1 parent a564cc9 commit 5432436
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
15 changes: 10 additions & 5 deletions cmd/temporalite/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"path/filepath"
"strings"

uiconfig "github.com/temporalio/ui-server/v2/server/config"
"github.com/urfave/cli/v2"
"go.temporal.io/server/common/config"
"go.temporal.io/server/common/dynamicconfig"
Expand Down Expand Up @@ -52,6 +51,14 @@ const (
dynamicConfigValueFlag = "dynamic-config-value"
)

type uiConfig struct {
Host string
Port int
TemporalGRPCAddress string
EnableUI bool
CodecEndpoint string
}

func main() {
if err := buildCLI().Run(os.Args); err != nil {
goLog.Fatal(err)
Expand Down Expand Up @@ -269,14 +276,12 @@ func buildCLI() *cli.App {
}
if !c.Bool(headlessFlag) {
frontendAddr := fmt.Sprintf("%s:%d", ip, serverPort)
cfg := &uiconfig.Config{
cfg := &uiConfig{
Host: uiIP,
Port: uiPort,
TemporalGRPCAddress: frontendAddr,
EnableUI: true,
Codec: uiconfig.Codec{
Endpoint: uiCodecEndpoint,
},
CodecEndpoint: uiCodecEndpoint,
}

opt, err := newUIOption(cfg, c.String(configFlag))
Expand Down
19 changes: 13 additions & 6 deletions cmd/temporalite/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/temporalio/temporalite"
)

func newUIOption(c *uiconfig.Config, configDir string) (temporalite.ServerOption, error) {
func newUIOption(c *uiConfig, configDir string) (temporalite.ServerOption, error) {
cfg, err := newUIConfig(
c,
configDir,
Expand All @@ -30,9 +30,16 @@ func newUIOption(c *uiconfig.Config, configDir string) (temporalite.ServerOption
return temporalite.WithUI(uiserver.NewServer(uiserveroptions.WithConfigProvider(cfg))), nil
}

func newUIConfig(cfg *uiconfig.Config, configDir string) (*uiconfig.Config, error) {
frontendAddr := cfg.TemporalGRPCAddress
enabledUi := cfg.EnableUI
func newUIConfig(c *uiConfig, configDir string) (*uiconfig.Config, error) {
cfg := &uiconfig.Config{
Host: c.Host,
Port: c.Port,
TemporalGRPCAddress: c.TemporalGRPCAddress,
EnableUI: c.EnableUI,
Codec: uiconfig.Codec{
Endpoint: c.CodecEndpoint,
},
}

if configDir != "" {
if err := provider.Load(configDir, cfg, "temporalite-ui"); err != nil {
Expand All @@ -44,8 +51,8 @@ func newUIConfig(cfg *uiconfig.Config, configDir string) (*uiconfig.Config, erro

// See https://github.com/temporalio/temporalite/pull/174/files#r1035958308
// for context about those overrides.
cfg.TemporalGRPCAddress = frontendAddr
cfg.EnableUI = enabledUi
cfg.TemporalGRPCAddress = c.TemporalGRPCAddress
cfg.EnableUI = c.EnableUI

return cfg, nil
}
8 changes: 2 additions & 6 deletions cmd/temporalite/ui_disabled.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@

package main

import (
uiconfig "github.com/temporalio/ui-server/v2/server/config"
import "github.com/temporalio/temporalite"

"github.com/temporalio/temporalite"
)

func newUIOption(c *uiconfig.Config, configDir string) (temporalite.ServerOption, error) {
func newUIOption(c *uiConfig, configDir string) (temporalite.ServerOption, error) {
return nil, nil
}
8 changes: 3 additions & 5 deletions cmd/temporalite/ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ package main
import (
"runtime/debug"
"testing"

uiconfig "github.com/temporalio/ui-server/v2/server/config"
)

// This test ensures that ui-server is a dependency of Temporalite built in non-headless mode.
Expand All @@ -29,7 +27,7 @@ func TestHasUIServerDependency(t *testing.T) {
}

func TestNewUIConfig(t *testing.T) {
c := &uiconfig.Config{
c := &uiConfig{
Host: "localhost",
Port: 8233,
TemporalGRPCAddress: "localhost:7233",
Expand All @@ -46,7 +44,7 @@ func TestNewUIConfig(t *testing.T) {
}

func TestNewUIConfigWithMissingConfigFile(t *testing.T) {
c := &uiconfig.Config{
c := &uiConfig{
Host: "localhost",
Port: 8233,
TemporalGRPCAddress: "localhost:7233",
Expand All @@ -63,7 +61,7 @@ func TestNewUIConfigWithMissingConfigFile(t *testing.T) {
}

func TestNewUIConfigWithPresentConfigFile(t *testing.T) {
c := &uiconfig.Config{
c := &uiConfig{
Host: "localhost",
Port: 8233,
TemporalGRPCAddress: "localhost:7233",
Expand Down

0 comments on commit 5432436

Please sign in to comment.