Skip to content

Commit 70c2b81

Browse files
chaptersixmichaely520yycpttdnr
authored
Update Configuration Loading (temporalio#8477)
## 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]>
1 parent e4d418c commit 70c2b81

File tree

14 files changed

+1488
-173
lines changed

14 files changed

+1488
-173
lines changed

CONTRIBUTING.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,12 @@ All PR titles should start with Upper case and have no dot at the end.
260260
## Go version update
261261
262262
1. In this repository, update `go` in `go.mod`.
263-
2. In [docker-builds](https://github.com/temporalio/docker-builds/), update the base images:
263+
2. ~~In [docker-builds](https://github.com/temporalio/docker-builds/), update the base images:
264264
[base-ci-builder](https://github.com/temporalio/docker-builds/blob/main/docker/base-images/base-ci-builder.Dockerfile)
265-
and [base-builder](https://github.com/temporalio/docker-builds/blob/main/docker/base-images/base-builder.Dockerfile)
265+
and [base-builder](https://github.com/temporalio/docker-builds/blob/main/docker/base-images/base-builder.Dockerfile)~~
266+
**Note:** The docker-builds repository is now deprecated and will be archived.
267+
268+
<!-- TODO: Remove docker/config_template.yaml after temporalio/docker-builds repository is archived -->
266269
267270
## License
268271

Makefile

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -595,44 +595,44 @@ stop-dependencies-cdc:
595595
start: start-sqlite
596596

597597
start-cass-es: temporal-server
598-
./temporal-server --env development-cass-es --allow-no-auth start
598+
./temporal-server --config-file config/development-cass-es.yaml --allow-no-auth start
599599

600600
start-cass-es-dual: temporal-server
601-
./temporal-server --env development-cass-es-dual --allow-no-auth start
601+
./temporal-server --config-file config/development-cass-es-dual.yaml --allow-no-auth start
602602

603603
start-cass-es-custom: temporal-server
604-
./temporal-server --env development-cass-es-custom --allow-no-auth start
604+
./temporal-server --config-file config/development-cass-es-custom.yaml --allow-no-auth start
605605

606606
start-es-fi: temporal-server
607-
./temporal-server --env development-cass-es-fi --allow-no-auth start
607+
./temporal-server --config-file config/development-cass-es-fi.yaml --allow-no-auth start
608608

609609
start-mysql: start-mysql8
610610

611611
start-mysql8: temporal-server
612-
./temporal-server --env development-mysql8 --allow-no-auth start
612+
./temporal-server --config-file config/development-mysql8.yaml --allow-no-auth start
613613

614614
start-mysql-es: temporal-server
615-
./temporal-server --env development-mysql-es --allow-no-auth start
615+
./temporal-server --config-file config/development-mysql-es.yaml --allow-no-auth start
616616

617617
start-postgres: start-postgres12
618618

619619
start-postgres12: temporal-server
620-
./temporal-server --env development-postgres12 --allow-no-auth start
620+
./temporal-server --config-file config/development-postgres12.yaml --allow-no-auth start
621621

622622
start-sqlite: temporal-server
623-
./temporal-server --env development-sqlite --allow-no-auth start
623+
./temporal-server --config-file config/development-sqlite.yaml --allow-no-auth start
624624

625625
start-sqlite-file: temporal-server
626-
./temporal-server --env development-sqlite-file --allow-no-auth start
626+
./temporal-server --config-file config/development-sqlite-file.yaml --allow-no-auth start
627627

628628
start-xdc-cluster-a: temporal-server
629-
./temporal-server --env development-cluster-a --allow-no-auth start
629+
./temporal-server --config-file config/development-cluster-a.yaml --allow-no-auth start
630630

631631
start-xdc-cluster-b: temporal-server
632-
./temporal-server --env development-cluster-b --allow-no-auth start
632+
./temporal-server --config-file config/development-cluster-b.yaml --allow-no-auth start
633633

634634
start-xdc-cluster-c: temporal-server
635-
./temporal-server --env development-cluster-c --allow-no-auth start
635+
./temporal-server --config-file config/development-cluster-c.yaml --allow-no-auth start
636636

637637
##### Grafana #####
638638
update-dashboards:

cmd/server/main.go

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,34 @@ func buildCLI() *cli.App {
4242
Name: "root",
4343
Aliases: []string{"r"},
4444
Value: ".",
45-
Usage: "root directory of execution environment",
45+
Usage: "root directory of execution environment (deprecated)",
4646
EnvVars: []string{config.EnvKeyRoot},
4747
},
4848
&cli.StringFlag{
4949
Name: "config",
5050
Aliases: []string{"c"},
5151
Value: "config",
52-
Usage: "config dir path relative to root",
52+
Usage: "config dir path relative to root (deprecated)",
5353
EnvVars: []string{config.EnvKeyConfigDir},
5454
},
5555
&cli.StringFlag{
5656
Name: "env",
5757
Aliases: []string{"e"},
5858
Value: "development",
59-
Usage: "runtime environment",
59+
Usage: "runtime environment (deprecated)",
6060
EnvVars: []string{config.EnvKeyEnvironment},
6161
},
6262
&cli.StringFlag{
6363
Name: "zone",
6464
Aliases: []string{"az"},
65-
Usage: "availability zone",
65+
Usage: "availability zone (deprecated)",
6666
EnvVars: []string{config.EnvKeyAvailabilityZone, config.EnvKeyAvailabilityZoneTypo},
6767
},
68+
&cli.StringFlag{
69+
Name: "config-file",
70+
Usage: "path to config file (absolute or relative to current working directory)",
71+
EnvVars: []string{config.EnvKeyConfigFile},
72+
},
6873
&cli.BoolFlag{
6974
Name: "allow-no-auth",
7075
Usage: "allow no authorizer",
@@ -105,10 +110,10 @@ func buildCLI() *cli.App {
105110
Usage: "Render server config template",
106111
ArgsUsage: " ",
107112
Action: func(c *cli.Context) error {
108-
cfg, err := config.LoadConfig(
109-
c.String("env"),
110-
c.String("config"),
111-
c.String("zone"),
113+
cfg, err := config.Load(
114+
config.WithEnv(c.String("env")),
115+
config.WithConfigDir(c.String("config")),
116+
config.WithZone(c.String("zone")),
112117
)
113118
if err != nil {
114119
return cli.Exit(fmt.Errorf("Unable to load configuration: %w", err), 1)
@@ -139,12 +144,13 @@ func buildCLI() *cli.App {
139144
if c.Args().Len() > 0 {
140145
return cli.Exit("ERROR: start command doesn't support arguments. Use --service flag instead.", 1)
141146
}
147+
148+
if c.IsSet("config-file") && (c.IsSet("config") || c.IsSet("env") || c.IsSet("zone") || c.IsSet("root")) {
149+
return cli.Exit("ERROR: can not use --config, --env, --zone, or --root with --config-file", 1)
150+
}
142151
return nil
143152
},
144153
Action: func(c *cli.Context) error {
145-
env := c.String("env")
146-
zone := c.String("zone")
147-
configDir := path.Join(c.String("root"), c.String("config"))
148154
services := c.StringSlice("service")
149155
allowNoAuth := c.Bool("allow-no-auth")
150156

@@ -154,7 +160,22 @@ func buildCLI() *cli.App {
154160
services = strings.Split(c.String("services"), ",")
155161
}
156162

157-
cfg, err := config.LoadConfig(env, configDir, zone)
163+
var cfg *config.Config
164+
var err error
165+
166+
switch {
167+
case c.IsSet("config-file"):
168+
cfg, err = config.Load(config.WithConfigFile(c.String("config-file")))
169+
case c.IsSet("config") || c.IsSet("env") || c.IsSet("zone"):
170+
cfg, err = config.Load(
171+
config.WithEnv(c.String("env")),
172+
config.WithConfigDir(path.Join(c.String("root"), c.String("config"))),
173+
config.WithZone(c.String("zone")),
174+
)
175+
default:
176+
cfg, err = config.Load(config.WithEmbedded())
177+
}
178+
158179
if err != nil {
159180
return cli.Exit(fmt.Sprintf("Unable to load configuration: %v.", err), 1)
160181
}

0 commit comments

Comments
 (0)