mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What Changed This PR introduces a new `--config-file` flag (and the `TEMPORAL_SERVER_CONFIG_FILE_PATH ` environment variable) to remove the dependency on `dockerize` in the Temporal server Docker image. When a configuration file is specified using either the CLI flag or the environment variable, the server will load configuration **only** from that file. Users who want templating behavior similar to `dockerize` can enable it by adding the comment `# enable-template` at the top of the configuration file. --- ### Key Changes 1. **New `--config-file` flag:** * Adds a global `--config-file` flag that accepts a path to a single configuration file (absolute or relative to the project root). * Can also be set via the `TEMPORAL_SERVER_CONFIG_FILE_PATH ` environment variable. 2. **Deprecated legacy flags:** * The `--config`, `--env`, and `--zone` flags are now marked as **deprecated** in CLI help text. * These flags still work for backward compatibility. 3. **Embedded config template:** * The `config_template.yaml` file is now embedded in the binary to support loading configuration from environment variables. * Templating is supported if the file includes the `# enable-template` comment at the top. 4. **Templating support:** * Configuration files can use templating by including `# enable-template` at the beginning of the YAML file. --- ### Configuration Loading Priority (Highest to Lowest) 1. **`--config-file` specified** → Load that specific file 2. **`--config`, `--env`, or `--zone` specified** → Load from configuration directory (**deprecated**) 3. **No configuration specified** → Load from embedded template using environment variables (default) --- ### Expected Behavior The following examples illustrate how the new configuration loading logic behaves: * **Default behavior:** Running `temporal start` without flags loads configuration from environment variables only using the embedded template. * **Using `--config-file`:** `temporal --config-file=/path/to/config.yaml start` loads configuration from the specified file path. * **Using `TEMPORAL_SERVER_CONFIG_FILE_PATH`:** Setting `TEMPORAL_SERVER_CONFIG_FILE_PATH=/path/to/config.yaml temporal start` has the same effect as using the flag. * **Validation and error handling:** The CLI returns clear error messages when conflicting flags or environment variables are used, or when a specified file does not exist. --- ## Breaking Change The default behavior of `temporal start` has changed. It now loads configuration **from environment variables** instead of using a default template path. --------- Co-authored-by: Alex Stanfield <[email protected]> Co-authored-by: michaely520 <[email protected]> Co-authored-by: Yichao Yang <[email protected]> Co-authored-by: David Reiss <[email protected]>
133 lines
3.5 KiB
Go
133 lines
3.5 KiB
Go
package temporal
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
"slices"
|
|
|
|
"go.temporal.io/server/client"
|
|
"go.temporal.io/server/common/authorization"
|
|
"go.temporal.io/server/common/config"
|
|
"go.temporal.io/server/common/dynamicconfig"
|
|
"go.temporal.io/server/common/log"
|
|
"go.temporal.io/server/common/membership/static"
|
|
"go.temporal.io/server/common/metrics"
|
|
persistenceClient "go.temporal.io/server/common/persistence/client"
|
|
"go.temporal.io/server/common/persistence/visibility"
|
|
"go.temporal.io/server/common/primitives"
|
|
"go.temporal.io/server/common/resolver"
|
|
"go.temporal.io/server/common/rpc/encryption"
|
|
"go.temporal.io/server/common/searchattribute"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
type (
|
|
synchronizationModeParams struct {
|
|
blockingStart bool
|
|
interruptCh <-chan interface{}
|
|
}
|
|
|
|
serverOptions struct {
|
|
serviceNames map[primitives.ServiceName]struct{}
|
|
|
|
config *config.Config
|
|
configDir string
|
|
env string
|
|
zone string
|
|
configFilePath string
|
|
hostsByService map[primitives.ServiceName]static.Hosts
|
|
|
|
startupSynchronizationMode synchronizationModeParams
|
|
|
|
logger log.Logger
|
|
namespaceLogger log.Logger
|
|
authorizer authorization.Authorizer
|
|
tlsConfigProvider encryption.TLSConfigProvider
|
|
claimMapper authorization.ClaimMapper
|
|
audienceGetter authorization.JWTAudienceMapper
|
|
persistenceServiceResolver resolver.ServiceResolver
|
|
elasticsearchHttpClient *http.Client
|
|
dynamicConfigClient dynamicconfig.Client
|
|
customDataStoreFactory persistenceClient.AbstractDataStoreFactory
|
|
customVisibilityStoreFactory visibility.VisibilityStoreFactory
|
|
clientFactoryProvider client.FactoryProvider
|
|
searchAttributesMapper searchattribute.Mapper
|
|
customFrontendInterceptors []grpc.UnaryServerInterceptor
|
|
metricHandler metrics.Handler
|
|
}
|
|
)
|
|
|
|
func newServerOptions(opts []ServerOption) *serverOptions {
|
|
so := &serverOptions{
|
|
// Set defaults here.
|
|
persistenceServiceResolver: resolver.NewNoopResolver(),
|
|
}
|
|
for _, opt := range opts {
|
|
opt.apply(so)
|
|
}
|
|
|
|
return so
|
|
}
|
|
|
|
func (so *serverOptions) loadAndValidate() error {
|
|
for serviceName := range so.serviceNames {
|
|
if !slices.Contains(Services, string(serviceName)) {
|
|
return fmt.Errorf("invalid service %q in service list %v", serviceName, so.serviceNames)
|
|
}
|
|
}
|
|
|
|
if so.config == nil {
|
|
err := so.loadConfig()
|
|
if err != nil {
|
|
return fmt.Errorf("unable to load config: %w", err)
|
|
}
|
|
}
|
|
|
|
err := so.validateConfig()
|
|
if err != nil {
|
|
return fmt.Errorf("config validation error: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (so *serverOptions) loadConfig() error {
|
|
if so.configFilePath != "" {
|
|
if so.env != "" || so.configDir != "" || so.zone != "" {
|
|
return errors.New("env, config, zone can not be set if configFilePath is set")
|
|
}
|
|
cfg, err := config.Load(
|
|
config.WithConfigFile(so.configFilePath),
|
|
)
|
|
if err != nil {
|
|
return fmt.Errorf("could not load config file: %w", err)
|
|
}
|
|
so.config = cfg
|
|
return nil
|
|
}
|
|
cfg, err := config.Load(
|
|
config.WithEnv(so.env),
|
|
config.WithConfigDir(so.configDir),
|
|
config.WithZone(so.zone),
|
|
)
|
|
if err != nil {
|
|
return fmt.Errorf("could not load config file: %w", err)
|
|
}
|
|
so.config = cfg
|
|
return nil
|
|
}
|
|
|
|
func (so *serverOptions) validateConfig() error {
|
|
if err := so.config.Validate(); err != nil {
|
|
return err
|
|
}
|
|
|
|
for name := range so.serviceNames {
|
|
if _, ok := so.config.Services[string(name)]; !ok {
|
|
return fmt.Errorf("%q service is missing in config", name)
|
|
}
|
|
}
|
|
return nil
|
|
}
|