devsapp / fc

阿里云函数计算(FC)组件
MIT License
139 stars 40 forks source link

s deploy 自动添加的环境变量规则细化调整 #762

Closed rsonghuster closed 2 years ago

rsonghuster commented 2 years ago

为了防止用户可能运行函数出现问题, 之前 s deploy 自动加环境变量基本没有规则,所有runtime 全部暴力添加相同的 env, 如下:

{
    "LD_LIBRARY_PATH": "/code/.s/root/usr/local/lib:/code/.s/root/usr/lib:/code/.s/root/usr/lib/x86_64-linux-gnu:/code/.s/root/usr/lib64:/code/.s/root/lib:/code/.s/root/lib/x86_64-linux-gnu:/code/.s/root/python/lib/python2.7/site-packages:/code/.s/root/python/lib/python3.6/site-packages:/code:/code/lib:/usr/local/lib",

    "NODE_PATH": "/opt/node_modules:/opt/nodejs/node_modules:/code/node_modules:/usr/local/lib/node_modules",

    "PATH": /code/.s/root/usr/local/bin:/code/.s/root/usr/local/sbin:/code/.s/root/usr/bin:/code/.s/root/usr/sbin:/code/.s/root/sbin:/code/.s/root/bin:/code:/code/node_modules/.bin:/code/.s/python/bin:/code/.s/node_modules/.bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/sbin:/bin",

    "PYTHONUSERBASE": "/code/.s/python",
}

我们这里细化出如下规则:

这次把 layer 也考虑进来

python runtime

{
    "LD_LIBRARY_PATH": "/code/.s/root/usr/local/lib:/code/.s/root/usr/lib:/code/.s/root/usr/lib/x86_64-linux-gnu:/code/.s/root/usr/lib64:/code/.s/root/lib:/code/.s/root/lib/x86_64-linux-gnu:/code/.s/root/python/lib/python3.9/site-packages:/code:/code/lib:/usr/local/lib:/opt/lib",
    "PATH": /code/.s/root/usr/local/bin:/code/.s/root/usr/local/sbin:/code/.s/root/usr/bin:/code/.s/root/usr/sbin:/code/.s/root/sbin:/code/.s/root/bin:/code:/code/.s/python/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/sbin:/bin:/opt/bin",
    "PYTHONUSERBASE": "/code/.s/python",
}

上面示例是 python3.9 runtime, 其他 python runtime 只需要修改 LD_LIBRARY_PATH 中的 python3.9 改成自己的即可, 比如 python3.6

nodejs runtime

{
    "LD_LIBRARY_PATH": "/code/.s/root/usr/local/lib:/code/.s/root/usr/lib:/code/.s/root/usr/lib/x86_64-linux-gnu:/code/.s/root/usr/lib64:/code/.s/root/lib:/code/.s/root/lib/x86_64-linux-gnu:/code:/code/lib:/usr/local/lib:/opt/lib",

    "NODE_PATH": "/opt/node_modules:/opt/nodejs/node_modules:/code/node_modules:/usr/local/lib/node_modules",

    "PATH": /code/.s/root/usr/local/bin:/code/.s/root/usr/local/sbin:/code/.s/root/usr/bin:/code/.s/root/usr/sbin:/code/.s/root/sbin:/code/.s/root/bin:/code:/code/node_modules/.bin:/code/.s/node_modules/.bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/sbin:/bin:/opt/bin",

}

custom runtime

{
    "LD_LIBRARY_PATH": "/code/.s/root/usr/local/lib:/code/.s/root/usr/lib:/code/.s/root/usr/lib/x86_64-linux-gnu:/code/.s/root/usr/lib64:/code/.s/root/lib:/code/.s/root/lib/x86_64-linux-gnu:/code/.s/root/python/lib/python3.7/site-packages:/code:/code/lib:/usr/local/lib:/opt/lib",
    "NODE_PATH": "/opt/node_modules:/opt/nodejs/node_modules:/code/node_modules:/usr/local/lib/node_modules",
    "PATH": /code/.s/root/usr/local/bin:/code/.s/root/usr/local/sbin:/code/.s/root/usr/bin:/code/.s/root/usr/sbin:/code/.s/root/sbin:/code/.s/root/bin:/code:/code/node_modules/.bin:/code/.s/python/bin:/code/.s/node_modules/.bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/sbin:/bin:/opt/bin",
    "PYTHONUSERBASE": "/code/.s/python",
}

其他 runtime

{
    "LD_LIBRARY_PATH": "/code/.s/root/usr/local/lib:/code/.s/root/usr/lib:/code/.s/root/usr/lib/x86_64-linux-gnu:/code/.s/root/usr/lib64:/code/.s/root/lib:/code/.s/root/lib/x86_64-linux-gnu:/code:/code/lib:/usr/local/lib:/opt/lib",

    "PATH": /code/.s/root/usr/local/bin:/code/.s/root/usr/local/sbin:/code/.s/root/usr/bin:/code/.s/root/usr/sbin:/code/.s/root/sbin:/code/.s/root/bin:/code:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/sbin:/bin:/opt/bin",
}

还有, 之前如果你配置了 PATH:/opt/mybin, s deploy , PATH 是 append 行为,以python runtime 为例,最后函数的 PATH 为 /opt/mybin:/code/.s/root/usr/local/bin:/code/.s/root/usr/local/sbin:/code/.s/root/usr/bin:/code/.s/root/usr/sbin:/code/.s/root/sbin:/code/.s/root/bin:/code:/code/.s/python/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/sbin:/bin:/opt/bin

这个行为继续保持, 但是希望最好能做到去重(可选)

wss-git commented 2 years ago

已支持

pengshuangbao commented 11 months ago

你好,为什么使用 fc build --use-docker --custom-env {"myenv":"${env(pip_password)}"} --script-file install.sh 这种脚本执行的方式就不会自动加上面的 环境变量,而只是使用 fc build --use-docker 就会自动加