没有不值得去解决的问题,也没有不值得去学习的技术!

How to Reference One Environment Variable Inside Another in Rancher

The Shell script is shown below.

1. Currently, there are 4 Rancher environment variables (no default values set, must be configured) whose values share a common part: dev.xxx.cn

Plaintext
PCS_API_CFG_SCMS_EDITOR_HOST_INFO=https://editor.dev.xxx.cn # HOME URL of the content management system editor
PCS_API_CFG_PCS_API_ASSET_HOST_INFO=https://web.dev.xxx.cn # HOME URL of the planning and command system interface resources
PCS_API_CFG_CPU_HOST_INFO=https://fcpu.dev.xxx.cn # HOME URL for CP uploads
PCS_API_CFG_SCMS_FRONT_HOST_INFO=https://web.dev.xxx.cn # HOME URL of the HTTP client frontend for the content management system

2. In the new phase, update the 4 Rancher environment variables (default values are now set, so configuration is optional). Add a new environment variable for the common part: RMT_MAIN_DOMAIN

Plaintext
RMT_MAIN_DOMAIN=dev.xxx.cn # Main domain of the converged media environment
PCS_API_CFG_SCMS_EDITOR_HOST_INFO=https://editor.${RMT_MAIN_DOMAIN} # HOME URL of the content management system editor
PCS_API_CFG_PCS_API_ASSET_HOST_INFO=https://web.${RMT_MAIN_DOMAIN} # HOME URL of the planning and command system interface resources
PCS_API_CFG_CPU_HOST_INFO=https://fcpu.${RMT_MAIN_DOMAIN} # HOME URL for CP uploads
PCS_API_CFG_SCMS_FRONT_HOST_INFO=https://web.${RMT_MAIN_DOMAIN} # HOME URL of the HTTP client frontend for the content management system

3. The Shell script is shown below. See Figure 1.

The Shell script is shown below.
Figure 1
ShellScript

# Rancher 环境变量(未设置默认值,必须设置)
if [[ `echo $RMT_MAIN_DOMAIN` == '' ]]
then
    echo "需要设置 RMT_MAIN_DOMAIN"
    exit 1
else
    echo "设置的 RMT_MAIN_DOMAIN 为:$RMT_MAIN_DOMAIN"
fi

# Rancher 环境变量(已设置默认值,可无需设置)
env | grep "PCS_API_CFG_SCMS_EDITOR_HOST_INFO" || export PCS_API_CFG_SCMS_EDITOR_HOST_INFO="https://editor.${RMT_MAIN_DOMAIN}"

sed -i "s#PCS_API_CFG_SCMS_EDITOR_HOST_INFO#$PCS_API_CFG_SCMS_EDITOR_HOST_INFO#g" $DEV_COMMON_CONFIG_PARAMS_LOCAL_PATH
echo "PCS_API_CFG_SCMS_EDITOR_HOST_INFO replace $PCS_API_CFG_SCMS_EDITOR_HOST_INFO -> $DEV_COMMON_CONFIG_PARAMS_LOCAL_PATH"
echo "PCS_API_CFG_SCMS_EDITOR_HOST_INFO replace $PCS_API_CFG_SCMS_EDITOR_HOST_INFO -> $DEV_COMMON_CONFIG_PARAMS_LOCAL_PATH" >> $DIR/change.log


4. When the environment variable RMT_MAIN_DOMAIN is not added in Rancher, upgrading the container throws an error. See Figure 2.

When the environment variable RMT_MAIN_DOMAIN is not added in Rancher, upgrading the container throws an error
Figure 2
Plaintext
/config/init/config0.sh: line 18: RMT_MAIN_DOMAIN: unbound variable

需要设置 RMT_MAIN_DOMAIN

5. When the environment variable RMT_MAIN_DOMAIN= is added in Rancher with an empty string value, upgrading the container throws an error. See Figure 3.

When the environment variable RMT_MAIN_DOMAIN= is added in Rancher with an empty string value, upgrading the container throws an error
Figure 3
Plaintext
需要设置 RMT_MAIN_DOMAIN

6. When the environment variable RMT_MAIN_DOMAIN=dev.xxx.cn is added in Rancher with the value dev.xxx.cn, the container upgrade succeeds and the environment variable takes effect. See Figure 4.

When the environment variable RMT_MAIN_DOMAIN=dev.xxx.cn is added in Rancher with the value dev.xxx.cn, the container upgrade succeeds and the environment variable takes effect.
Figure 4
PHP

// 内容管理系统编辑器
'scmsEditor' => [
    'hostInfo' => 'https://editor.dev.xxx.cn', // HOME URL
    'baseUrl' => '', // BASE URL
],

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系