Node.js React应用程序&x2B;用于GAE的节点Gitlab cicd管道(构建和部署)

Node.js React应用程序&x2B;用于GAE的节点Gitlab cicd管道(构建和部署),node.js,reactjs,gitlab,yaml,gcloud,Node.js,Reactjs,Gitlab,Yaml,Gcloud,如何创建两个阶段:第一个阶段构建react应用程序,然后创建一个阶段将文件部署到GAE 我目前的YML如下所示: image: 'google/cloud-sdk:slim' build-stage: stage: build image: 'node:latest' script: - 'npm install' - 'npm install --prefix ./client' - 'npm run build --pr

如何创建两个阶段:第一个阶段构建react应用程序,然后创建一个阶段将文件部署到GAE

我目前的YML如下所示:

image: 'google/cloud-sdk:slim'
build-stage:
    stage: build
    image: 'node:latest'
    script:
        - 'npm install'
        - 'npm install --prefix ./client'
        - 'npm run build --prefix ./client'
    only:
        - master
deployment-stage:
    stage: deploy
    script:
        - 'gcloud auth activate-service-account --key-file $GOOGLE_SERVICE_ACCOUNT_FILE'
        - 'gcloud app deploy app.yaml --project $GOOGLE_PROJECT_ID --set-env-vars **redacted**'
    only:
        - master
Google App Engine不会在builds选项卡上显示任何生成。我已创建具有以下权限的服务帐户:

我也在Gitlab中设置了CICD变量,下面是到目前为止作业的输出

建造阶段:

 $ npm run build --prefix ./client
 > client@0.1.0 build /builds/**redacted**/client
 > react-scripts build
 Creating an optimized production build...
 Compiled successfully.
 File sizes after gzip:
   276.17 KB  build/static/js/2.63b40945.chunk.js
   59.19 KB   build/static/css/2.2e872fcd.chunk.css
   4.3 KB     build/static/js/main.7cffe524.chunk.js
   923 B      build/static/css/main.433538f4.chunk.css
   772 B      build/static/js/runtime-main.ef76e641.js
 The project was built assuming it is hosted at /.
 You can control this with the homepage field in your package.json.
 The build folder is ready to be deployed.
 You may serve it with a static server:
   npm install -g serve
   serve -s build
 Find out more about deployment here:
   bit.ly/CRA-deploy
 Job succeeded
部署阶段:

 Fetching changes with git depth set to 50...
 Initialized empty Git repository in /builds/**redacted**/.git/
 Created fresh repository.
 From https://gitlab.com/**redacted**
  * [new ref]         refs/pipelines/124363587 -> refs/pipelines/124363587
  * [new branch]      master                   -> origin/master
 Checking out f2026f12 as master...
 Skipping Git submodules setup
$ gcloud auth activate-service-account --key-file $GOOGLE_SERVICE_ACCOUNT_FILE
00:02
 Activated service account credentials for: [**redacted**]
 $ gcloud app deploy app.yaml --project $GOOGLE_PROJECT_ID --set-env-vars **redacted**
 Job succeeded
我认为问题在于构建文件没有被上传,因为它们在一个单独的容器中

我试着在一个脚本步骤中运行它,但是google/CloudSDK:slim不包含npm来进行构建或安装


谢谢

通过尝试和错误解决了这个问题

image: python:2.7

before_script:
  - echo "deb http://packages.cloud.google.com/apt cloud-sdk-jessie main" | tee /etc/apt/sources.list.d/google-cloud-sdk.list
  - curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
  - apt-get update
  - apt-get -qq -y install google-cloud-sdk
  - apt-get -qq -y install npm
  - npm install
  - npm install --prefix ./client
  - npm run build --prefix ./client

deploy:
  stage: deploy
  environment: Production
  only:
    - master
  script:
    - gcloud auth activate-service-account --key-file $GOOGLE_SERVICE_ACCOUNT_FILE
    - gcloud app deploy app.yaml --project $GOOGLE_PROJECT_ID
已将set env VAR移动到app.yaml,因为无法根据以下文档在gloud app部署中将其设置为标志: