在 gcloud 中将 JSON 文件作为环境变量传递

Passing a JSON file as environment variable in gcloud

我正在尝试将秘密传递到云 运行 运行 命令中。秘密是一个 json 文件。我想将它作为环境变量传入。

它在 docker 中使用效果很好:

docker run -it -e "SECRET_ENV=$(<path/secretFile.json)" -p 8080:8080 my_image 

当我在 gcloud 上使用相同的方法时,我收到一个错误,告诉我它正在尝试 运行 json 文件的每一行:

gcloud run deploy --image gcr.io/account/project --update-env-vars "SECRET_JSON=$(<path/secretFile.json)"

干杯

感谢@Kolban 与我一起解决这个问题。

感谢@tzovourn 对 berglas secret manager

的建议

GCP gcloud 命令似乎有问题 and/or 不支持 JSON。

我最后采用的解决方案是先对json进行base 64编码,然后再将其设置为环境变量。现在 docker 和 gcloud 命令采用相同的数据和格式。

目前gcloud run deploy不支持通过json文件设置环境变量。有关 Cloud 运行 环境变量的更多信息,请参见 here.

您可能需要为此项改进提交 Feature Request