1、在 Rancher 中升级容器时,报错:CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH: unbound variable。如图1
2020/10/10 上午10:53:15 CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH_URL replace CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH_URL -> /mcloud/www/channel-pub-api/environments/dev/common/config/params-local.php 2020/10/10 上午10:53:15 /config/init/config0.sh: line 1193: CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH: unbound variable
2、查看文件:/config/init/config0.sh。
env | grep "CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH_URL" || export CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH_URL="CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH_URL" env | grep "CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH" || export CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH="CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH" sed -i "s#CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH_URL#$CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH_URL#g" $DEV_COMMON_CONFIG_PARAMS_LOCAL_PATH echo "CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH_URL replace $CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH_URL -> $DEV_COMMON_CONFIG_PARAMS_LOCAL_PATH" echo "CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH_URL replace $CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH_URL -> $DEV_COMMON_CONFIG_PARAMS_LOCAL_PATH" >> $DIR/change.log sed -i "s#CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH#$CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH#g" $DEV_COMMON_CONFIG_PARAMS_LOCAL_PATH echo "CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH replace $CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH -> $DEV_COMMON_CONFIG_PARAMS_LOCAL_PATH" echo "CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH replace $CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH -> $DEV_COMMON_CONFIG_PARAMS_LOCAL_PATH" >> $DIR/change.log
3、即使在 Rancher 中添加环境变量:CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH_URL、CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH 。仍然报同样的错误。如图2
CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH_URL=CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH_URL CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH=CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH
4、在 Rancher 中赋值环境变量:CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH 一个具体的值。升级成功。
CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH_URL=CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH_URL CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH=/webtv/wangjiedev/channel-pub-api/uploads
5、怀疑与环境变量名称的特殊性有关。编辑待替换环境变量的配置文件,删除相应的环境变量。编辑文件:/config/init/config0.sh,删除相应的环境变量:CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH_URL、CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH。
调整前:
// 渠道发布接口 'channelPubApi' => [ 'hostInfo' => 'CHANNEL_PUB_API_CFG_CHANNEL_PUB_API_HOST_INFO', // HOME URL 'baseUrl' => 'CHANNEL_PUB_API_CFG_CHANNEL_PUB_API_BASE_URL', // BASE URL 'asset' => [ // 资源 'hostInfo' => 'CHANNEL_PUB_API_CFG_CHANNEL_PUB_API_ASSET_HOST_INFO', // HOME URL 'baseUrl' => 'CHANNEL_PUB_API_CFG_CHANNEL_PUB_API_ASSET_BASE_URL', // BASE URL 'basePath' => 'CHANNEL_PUB_API_CFG_CHANNEL_PUB_API_ASSET_BASE_PATH', // BASE PATH 'image' => [ // 图片 'basePath' => 'CHANNEL_PUB_API_CFG_CHANNEL_PUB_API_ASSET_IMAGE_BASE_PATH', // BASE PATH ], 'video' => [ // 视频 'basePath' => 'CHANNEL_PUB_API_CFG_CHANNEL_PUB_API_ASSET_VIDEO_BASE_PATH', // BASE PATH ], 'audio' => [ // 音频 'basePath' => 'CHANNEL_PUB_API_CFG_CHANNEL_PUB_API_ASSET_AUDIO_BASE_PATH', // BASE PATH ], 'other' => [ // 其它 'basePath' => 'CHANNEL_PUB_API_CFG_CHANNEL_PUB_API_ASSET_OTHER_BASE_PATH', // BASE PATH ], ], ], //文件上传目录配置 'appAvatarUpload' => [ 'pathUrl' => 'CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH_URL',//上传目录的访问地址,结尾不加/ 'uploadPath' => 'CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH',//上传目录,结尾不加/ ],
$pathUrl = Yii::$app->params['appAvatarUpload']['pathUrl']; $uploadPath = Yii::$app->params['appAvatarUpload']['uploadPath'];
调整后:
// 渠道发布接口 'channelPubApi' => [ 'hostInfo' => 'CHANNEL_PUB_API_CFG_CHANNEL_PUB_API_HOST_INFO', // HOME URL 'baseUrl' => 'CHANNEL_PUB_API_CFG_CHANNEL_PUB_API_BASE_URL', // BASE URL 'asset' => [ // 资源 'hostInfo' => 'CHANNEL_PUB_API_CFG_CHANNEL_PUB_API_ASSET_HOST_INFO', // HOME URL 'baseUrl' => 'CHANNEL_PUB_API_CFG_CHANNEL_PUB_API_ASSET_BASE_URL', // BASE URL 'basePath' => 'CHANNEL_PUB_API_CFG_CHANNEL_PUB_API_ASSET_BASE_PATH', // BASE PATH 'image' => [ // 图片 'basePath' => 'CHANNEL_PUB_API_CFG_CHANNEL_PUB_API_ASSET_BASE_PATH/images', // BASE PATH ], 'video' => [ // 视频 'basePath' => 'CHANNEL_PUB_API_CFG_CHANNEL_PUB_API_ASSET_BASE_PATH/videos', // BASE PATH ], 'audio' => [ // 音频 'basePath' => 'CHANNEL_PUB_API_CFG_CHANNEL_PUB_API_ASSET_BASE_PATH/audios', // BASE PATH ], 'other' => [ // 其它 'basePath' => 'CHANNEL_PUB_API_CFG_CHANNEL_PUB_API_ASSET_BASE_PATH/others', // BASE PATH ], ], ],
$pathUrl = Yii::$app->params['channelPubApi']['asset']['image']['hostInfo'] . ['channelPubApi']['asset']['image']['baseUrl']; $uploadPath = Yii::$app->params['channelPubApi']['asset']['image']['basePath'];
6、在 Rancher 中删除环境变量:CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH_URL、CHANNEL_PUB_API_CFG_APP_AVATAR_UPLOAD_PATH。升级成功。进入容器,查看替换后的配置文件。如图3
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/webdev/181583.html