【发布时间】:2020-10-28 11:36:12
【问题描述】:
我正在编写 FastAPI 服务并部署到 Google Cloud Run。
我想在我的笔记本电脑上运行某些代码,在云端运行某些代码等。 我想根据运行的环境自定义代码。
我如何知道我是否在容器中、谷歌云运行、我的 Mac 笔记本电脑、vscode 空间、GitHub 操作...如何将这些信息添加到调试变量中?
debug,cloud,laptop,vcode = Environment()
if debug:
app.mount("/public", StaticFiles(directory="/public"), name="static")
else:
app.mount("/public", StaticFiles(directory="/debitcard/debitcard/public/static"), name="static")
}
我如何在 python 中知道代码实际上是在我的笔记本电脑上运行还是在云运行环境上运行?
【问题讨论】:
-
可以设置环境变量,据此决定运行哪些代码
-
在代码运行的所有环境中几乎都设置了 env var 呵呵。明白了。
-
这就是你在nodejs中的做法,或者使用类似java中的配置属性文件
标签: python docker containers google-cloud-run fastapi