1、当存在环境变量时,未执行替换,文件 /etc/nginx/conf.d/pcs.conf 中的变量未被替换,/config/init/change.log 中存在替换记录,如图1
2、查看容器日志,报错:sed: couldn’t open file ww/pcs/build/config.js: No such file or directory
2018/7/24 下午3:47:59PCS_CFG_NGINX_SERVER_NAME=wjdev2.chinamcloud.com 2018/7/24 下午3:47:59sed: -e expression #1, char 7: extra characters after command 2018/7/24 下午3:47:59PCS_CFG_NGINX_SERVER_NAME replace wjdev2.chinamcloud.com -> /etc/nginx/conf.d/pcs.conf 2018/7/24 下午3:47:59PCS_CFG_API_HOST_INFO=http://wjdev2.chinamcloud.com:8656 2018/7/24 下午3:47:59sed: -e expression #1, char 7: extra characters after command 2018/7/24 下午3:47:59PCS_CFG_API_HOST_INFO replace http://wjdev2.chinamcloud.com:8656 -> /etc/nginx/conf.d/pcs.conf 2018/7/24 下午3:47:59PCS_CFG_API_BASE_URL=/v1 2018/7/24 下午3:47:59sed: -e expression #1, char 7: extra characters after command 2018/7/24 下午3:47:59PCS_CFG_API_BASE_URL replace /v1 -> /etc/nginx/conf.d/pcs.conf 2018/7/24 下午3:47:59PCS_CFG_CALLBACK_LOGIN=https://cmclogin.chinamcloud.com/login/index?call_back=http://wjdev2.chinamcloud.com:8657/#/topic/add 2018/7/24 下午3:47:59sed: couldn't open file ww/pcs/build/config.js: No such file or directory 2018/7/24 下午3:47:59PCS_CFG_CALLBACK_LOGIN replace https://cmclogin.chinamcloud.com/login/index?call_back=http://wjdev2.chinamcloud.com:8657/#/topic/add -> /sobey/www/pcs/build/config.js 2018/7/24 下午3:47:59PCS_CFG_API_VERSION=0.0 2018/7/24 下午3:47:59sed: couldn't open file ww/pcs/build/config.js: No such file or directory 2018/7/24 下午3:47:59PCS_CFG_API_VERSION replace 0.0 -> /sobey/www/pcs/build/config.js 2018/7/24 下午3:47:59PCS_CFG_CMC_CONSOLE_URL=https://cmcconsole.chinamcloud.com 2018/7/24 下午3:47:59sed: couldn't open file ww/pcs/build/config.js: No such file or directory 2018/7/24 下午3:47:59PCS_CFG_CMC_CONSOLE_URL replace https://cmcconsole.chinamcloud.com -> /sobey/www/pcs/build/config.js 2018/7/24 下午3:47:59PCS_CFG_CMC_CONSOLE_HEADER_LEFT_CSS=/cmc/cmc_header_left.css 2018/7/24 下午3:47:59sed: couldn't open file ww/pcs/build/config.js: No such file or directory 2018/7/24 下午3:47:59PCS_CFG_CMC_CONSOLE_HEADER_LEFT_CSS replace /cmc/cmc_header_left.css -> /sobey/www/pcs/build/config.js 2018/7/24 下午3:47:59PCS_CFG_CMC_CONSOLE_HEADER_LEFT_JS=/cmc/cmc_header_left.js 2018/7/24 下午3:47:59sed: couldn't open file ww/pcs/build/config.js: No such file or directory 2018/7/24 下午3:47:59PCS_CFG_CMC_CONSOLE_HEADER_LEFT_JS replace /cmc/cmc_header_left.js -> /sobey/www/pcs/build/config.js 2018/7/24 下午3:47:59PCS_CFG_API_VERSION=0.0 2018/7/24 下午3:47:59sed: couldn't open file ww/pcs/build/gis/config.js: No such file or directory 2018/7/24 下午3:47:59PCS_CFG_API_VERSION replace 0.0 -> /sobey/www/pcs/build/gis/config.js 2018/7/24 下午3:47:59/config/init/cronlog.sh: line 4: LOG_NAME: unbound variable
3、PCS_CFG_CALLBACK_LOGIN=https://cmclogin.chinamcloud.com/login/index?call_back=http://wjdev2.chinamcloud.com:8657/#/topic/add ,其值中存在 #,因此为了防止冲突,需要将 # 替换为 @。且 sed -i” 替换为 sed -i “,缺少空格。
env | grep "PCS_CFG_CALLBACK_LOGIN" || export PCS_CFG_CALLBACK_LOGIN="PCS_CFG_CALLBACK_LOGIN" sed -i "s@PCS_CFG_CALLBACK_LOGIN@$PCS_CFG_CALLBACK_LOGIN@g" $BUILD_CONFIG_PATH echo "PCS_CFG_CALLBACK_LOGIN replace $PCS_CFG_CALLBACK_LOGIN -> $BUILD_CONFIG_PATH" echo "PCS_CFG_CALLBACK_LOGIN replace $PCS_CFG_CALLBACK_LOGIN -> $BUILD_CONFIG_PATH" >> $DIR/change.log
4、文件 /etc/nginx/conf.d/pcs.conf 中的变量已被成功替换,如图2
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/250425.html