將 Nx 工作區部署到 Google App Engine (Deploying Nx workspace to Google App Engine)


問題描述

將 Nx 工作區部署到 Google App Engine (Deploying Nx workspace to Google App Engine)

我的 Nx 應用在本地運行良好,但部署到 GAE 時失敗並出現以下錯誤:

sh: 1: exec: nx: not found

它找不到 dependencies 下列出的 nx(不是 devDependencies),因為 GAE 沒有安裝這些。

我的 package.json 裡面有這個:

  "scripts": {
    "start": "nx serve api",

所以當 GAE 運行 npm run start 時它會失敗。我嘗試直接指定 nx 的路徑,但嘗試使用 node_modules/nx/bin/nx 來引用它,但這也失敗了。

I'我想知道如何讓 GAE 使用 nx 為應用程序提供服務。

這是一個如此簡單和基本的用例,我很困惑,它沒有一個簡單的解決方案。我一定錯過了一些非常簡單的東西。


參考解法

方法 1:

I am using Nx@13, here are steps to deploy to GAE:

  1. Add "generatePackageJson": true, to production executor, it will generate a package.json in dist/apps/serviceA/package.json

  2. GAE will look for scripts:{"start:"your way to start nodejs app "} or server.js if the start script not found. You will have to write a script to add scripts:{"start:"node main.js"} into the generated package.json in #1

  3. In cloudbuild we will have to execute GAE deploy command in dist/apps/serviceA folder, luckily cloudbuild step supports dir


  4. </ol>

    cloudbuild.yaml

    steps:
      ‑ name: node:16‑bullseye
        entrypoint: npm
        args: ['install']
    
      ‑ name: node:16‑bullseye
        entrypoint: npm
        args: ['run', 'lint', '${_SERVICE_NAME}']
    
      ‑ name: node:16‑bullseye
        entrypoint: npm
        args: ['run', 'test', '${_SERVICE_NAME}']
    
      ‑ name: node:16‑bullseye
        entrypoint: npm
        args:
          ['run', 'build', '${_SERVICE_NAME}', '‑‑', '‑‑configuration=production']
    
      ‑ name: node:16‑bullseye
        entrypoint: bash
        args:
          [
            '‑c',
            'node tools/prepare‑gcp‑app‑engine.js ‑‑serviceName=${_SERVICE_NAME}',
          ]
    
      ‑ name: gcr.io/google.com/cloudsdktool/cloud‑sdk:376.0.0‑slim
        dir: dist/apps/${_SERVICE_NAME}
        entrypoint: gcloud
        args:
          ‑ app
          ‑ deploy
          ‑ app‑engine.yaml
          ‑ ‑‑version=$SHORT_SHA
          ‑ ‑‑promote
          ‑ ‑‑stop‑previous‑version
          ‑ ‑‑quiet
    
    substitutions:
      _SERVICE_NAME: game‑api
    
    

    Source code demo

    (by Nightwolfvanduc1102)

    參考文件

    1. Deploying Nx workspace to Google App Engine (CC BY‑SA 2.5/3.0/4.0)

#nrwl #node.js #nrwl-nx #google-app-engine






相關問題

Ng add @nrwl/workspace throws Cannot read property 'paths' of undefined (Ng add @nrwl/workspace throws Cannot read property 'paths' of undefined)

如何為非js框架創建原理圖? (How to create a schematic for non js framework?)

禁止在 Nrwl Nx 的同一庫中導入桶文件 (Disallow barrel file imports within the same library in Nrwl Nx)

如何強制 nrwl nx 尊重標籤更新? (How can I force nrwl nx to respect tag updates?)

將 Nx 工作區部署到 Google App Engine (Deploying Nx workspace to Google App Engine)

如何讓 Jest 正確轉換 node_modules/@nativescript/core?Jest + NativeScript + Angular + Nx (How can I get Jest to transpile node_modules/@nativescript/core properly? Jest + NativeScript + Angular + Nx)

使用 Nx 在 Jenkins 中進行 CI/CD 的最佳方式 (Best way for CI/CD in Jenkins with Nx)

如何使用短路徑在 Nx Workspace 中導入? (How to use short paths for importing in Nx Workspace?)

將 nx 與 angular.json 一起使用時使用哪個構建器 (Which builder to use when using nx with angular.json)







留言討論