REACT APP 无法访问谷歌云运行环境变量

Usa*_*han 5 javascript mongodb node.js reactjs google-cloud-run

我使用 GitLab ci 作为我的 CI/CD 工具。我正在将 dockerized react 应用程序部署到 cloud run,但我无法访问在 cloud run 上声明的环境变量。谢谢!

文件

# build environment
FROM node:8-alpine as react-build

WORKDIR /app
COPY . ./

RUN npm install
RUN npm run build

# server environment
FROM nginx: alpine
COPY nginx.conf /etc/nginx/conf.d/configfile.template

COPY --from=react-build /app/build /usr/share/nginx/html

ENV PORT 8080
ENV HOST 0.0.0.0
EXPOSE 8080
CMD sh -c "envsubst '\$PORT' < /etc/nginx/conf.d/configfile.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
Run Code Online (Sandbox Code Playgroud)

gitlab-ci.yml

default:
  image: google/cloud-sdk:alpine
  before_script:
    - gcloud config set project PROJECTID
    - gcloud auth activate-service-account --key-file $GCP_SERVICE_CREDS
stages:
  - staging
  - production

staging:
  stage: staging
  environment:
    name: staging
  only:
    variables:
      - $DEPLOY_ENV == "staging"
  script:
    - gcloud builds submit --tag gcr.io/PROJECTID/REPOSITORY
    - gcloud run deploy REPOSITORY --image gcr.io/PROJECTID/REPOSITORY --platform managed --region us-central1 --allow-unauthenticated 

production:
  stage: production
  environment:
    name: production
  only:
    variables:
      - $DEPLOY_ENV == "production"
  script:
    - gcloud builds submit --tag gcr.io/PROJECTID/REPOSITORY
    - gcloud run deploy REPOSITORY --image gcr.io/PROJECTID/REPOSITORY --platform managed --region us-central1 --allow-unauthenticated --set-env-vars NODE_ENV=production
Run Code Online (Sandbox Code Playgroud)

Eze*_*OVE 0

据我了解,您希望访问 GCP 上声明的环境变量,例如 $GCP_SERVICE_CREDS、$PROJECTID、$REPOSITORY 以及 Gitlab 管道上的其他变量。

为此,请转到 Gitlab 设置,然后单击 CI/CD。到达那里后,单击“变量”前面的“展开”按钮,然后添加各种 GCP 变量及其值。