From bac2b07b3612e25c45b1253129c40978aa44ce37 Mon Sep 17 00:00:00 2001 From: Wine93 Date: Mon, 29 Jan 2024 15:19:20 +0800 Subject: [PATCH] Feature(deploy): support set environment variables for service container. Signed-off-by: Wine93 --- .gitignore | 1 + internal/configure/topology/dc_get.go | 1 + internal/configure/topology/dc_item.go | 14 +++++++++++--- internal/task/task/common/create_container.go | 7 ++++++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 6ba063f29..0fc831a23 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ logs/* .vscode/ .CHANGELOG vendor/ +TODO.md diff --git a/internal/configure/topology/dc_get.go b/internal/configure/topology/dc_get.go index ee8e7c2b1..2616eb854 100644 --- a/internal/configure/topology/dc_get.go +++ b/internal/configure/topology/dc_get.go @@ -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) } diff --git a/internal/configure/topology/dc_item.go b/internal/configure/topology/dc_item.go index 24f23e972..1611ca7e1 100644 --- a/internal/configure/topology/dc_item.go +++ b/internal/configure/topology/dc_item.go @@ -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{}, @@ -129,6 +130,13 @@ var ( nil, ) + CONFIG_ENV = itemset.insert( + "env", + REQUIRE_STRING, + true, + nil, + ) + CONFIG_LISTEN_IP = itemset.insert( "listen.ip", REQUIRE_STRING, diff --git a/internal/task/task/common/create_container.go b/internal/task/task/common/create_container.go index 1a6d6676c..b29246759 100644 --- a/internal/task/task/common/create_container.go +++ b/internal/task/task/common/create_container.go @@ -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 {