我正在使用 Firebase Cloud Functions,它在底层使用 Google Cloud,并且我使用 Google Cloud 的 Secret Manager 为我的 Web 应用程序定义了一些机密。
我在 Firebase 函数的打字稿代码中访问这些秘密,如下所示:
import {onRequest} from 'firebase-functions/v2/https';
import {defineSecret} from 'firebase-functions/params';
import * as logger from 'firebase-functions/logger';
import axios from 'axios';
import * as cors from 'cors';
import * as admin from 'firebase-admin';
const var1= defineSecret('VAR1');
const var2 = defineSecret('VAR2');
当我运行
firebase deploy --only functions
时,我收到此错误:
i functions: updating Node.js 18 (2nd Gen) function sendEmail(us-central1)...
! functions: HTTP Error: 400, Could not update Cloud Run service projects/<myproject>/locations/us-central1/services/<myapi>. spec.template.spec.containers[0].env: Secret environment variable overlaps non secret environment variable: VAR1
! functions: failed to update function projects/<myproject>/locations/us-central1/functions/<myapi>
Failed to update function projects/<myproject>/locations/us-central1/functions/<myapi>
Functions deploy had errors with the following functions:
myapi(us-central1)
i functions: cleaning up build files...
! functions: Unhandled error cleaning up build images. This could result in a small monthly bill if not corrected. You can attempt to delete these images by redeploying or you can delete them manually at https://console.cloud.google.com/gcr/images/<myproject>/us/gcf
Error: There was an error deploying functions
我尝试删除我的
.env
文件,我运行 firebase functions:config:unset VAR1 VAR2
并运行 gcloud run services describe <myapi> --format='value(spec.template.spec.containers[0].env)'
,它返回了 Google Cloud 中定义的机密。
我不知道如何识别重叠的“非秘密”和“秘密”环境变量。
我能够通过删除 Google Cloud Run 服务中定义的环境变量来解决此问题。我不确定这些是如何或为何在 Google Cloud Run Service 中定义的。