Skip to content

Commit

Permalink
Feature(deploy): support set environment variables for service contai…
Browse files Browse the repository at this point in the history
…ner.

Signed-off-by: Wine93 <[email protected]>
  • Loading branch information
Wine93 committed Jan 29, 2024
1 parent 7577836 commit bac2b07
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ logs/*
.vscode/
.CHANGELOG
vendor/
TODO.md
1 change: 1 addition & 0 deletions internal/configure/topology/dc_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func (dc *DeployConfig) GetContainerImage() string { return dc.getString(CONFI
func (dc *DeployConfig) GetLogDir() string { return dc.getString(CONFIG_LOG_DIR) }
func (dc *DeployConfig) GetDataDir() string { return dc.getString(CONFIG_DATA_DIR) }
func (dc *DeployConfig) GetCoreDir() string { return dc.getString(CONFIG_CORE_DIR) }
func (dc *DeployConfig) GetEnv() string { return dc.getString(CONFIG_ENV) }
func (dc *DeployConfig) GetListenIp() string { return dc.getString(CONFIG_LISTEN_IP) }
func (dc *DeployConfig) GetListenPort() int { return dc.getInt(CONFIG_LISTEN_PORT) }
func (dc *DeployConfig) GetListenClientPort() int { return dc.getInt(CONFIG_LISTEN_CLIENT_PORT) }
Expand Down
14 changes: 11 additions & 3 deletions internal/configure/topology/dc_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ type (
)

// you should add config item to itemset iff you want to:
// (1) check the configuration item value, like type, valid value OR
// (2) filter out the configuration item for service config OR
// (3) set the default value for configuration item
//
// (1) check the configuration item value, like type, valid value OR
// (2) filter out the configuration item for service config OR
// (3) set the default value for configuration item
var (
itemset = &itemSet{
items: []*item{},
Expand Down Expand Up @@ -129,6 +130,13 @@ var (
nil,
)

CONFIG_ENV = itemset.insert(
"env",
REQUIRE_STRING,
true,
nil,
)

CONFIG_LISTEN_IP = itemset.insert(
"listen.ip",
REQUIRE_STRING,
Expand Down
7 changes: 6 additions & 1 deletion internal/task/task/common/create_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,14 @@ func getEnvironments(dc *topology.DeployConfig) []string {
preloads = append(preloads, "/usr/local/lib/libsmc-preload.so")
}

return []string{
envs := []string{
fmt.Sprintf("'LD_PRELOAD=%s'", strings.Join(preloads, " ")),
}
env := dc.GetEnv()
if len(env) > 0 {
envs = append(envs, strings.Split(env, " ")...)
}
return envs
}

func getMountVolumes(dc *topology.DeployConfig) []step.Volume {
Expand Down

0 comments on commit bac2b07

Please sign in to comment.