【发布时间】:2022-10-02 01:50:54
【问题描述】:
我正在开发一个使用一些敏感 API 密钥的反应网站。
我通过容器将应用程序托管在 Google Cloud Run 上。
我想通过 Google Cloud Secret Manager 访问 API 密钥,但我不能。当我尝试访问它们时,返回的是“未定义”。
这是我的代码sn-p:
console.log(process.env.REACT_APP_API_KEY)
和 Dockerfile:
FROM node:14-alpine AS builder
WORKDIR /app
COPY package.json ./
COPY yarn.lock ./
RUN yarn install --frozen-lockfile
COPY . .
RUN yarn build
FROM nginx:1.19-alpine AS server
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=builder ./app/build /usr/share/nginx/html
我正在使用 gcloud 命令部署应用程序:
gcloud run deploy test-gcr-react \\
--image gcr.io/test-gcr-react-app/test-gcr-react \\
--region=southamerica-east1 \\
--set-secrets=REACT_APP_API_KEY=REACT_APP_API_KEY:latest \\
--allow-unauthenticated
PS:我已经授予服务帐户“默认计算服务帐户”的适当访问权限,使其成为秘密REACT_APP_API_KEY 的“秘密经理秘密顾问”。
标签: reactjs docker google-cloud-platform google-cloud-run api-key