【问题标题】:ANGULAR build --prod error deploying in Google App Engine using CloudBuild使用 CloudBuild 在 Google App Engine 中部署 ANGULAR build --prod 错误
【发布时间】:2021-03-01 15:58:52
【问题描述】:

你好,

为了上下文化,我正在使用 Google App Engine (GAE) 开发一个 Web 应用程序。事实上,我使用了三种不同的 GAE 服务。对于后端,分析和前端使用 Angular。

在 GIT 中,我的架构如下:

确实,我在根目录下编写了一个全局cloudbuild.yaml 文件,如下所示,以调用每个服务目录(“/api”、“/analysis”、“/frontend”)中的所有其他特定cloudbuild.yaml 文件:

steps:
- name: 'gcr.io/cloud-builders/gcloud'
  entrypoint: 'bash'
  args:
  - '-c'
  - |
    for d in */; do
      config="${d}cloudbuild.yaml"
      if [[ ! -f "${config}" ]]; then
        continue
      fi

      echo "Building $d ... "
      (
        gcloud builds submit $d --config=${config}
      ) &
    done
    wait

在部署过程中,“前端”服务步骤出现错误让我们看看他的cloudbuild.yaml文件:

steps:

  # Install Angular
  - name: 'gcr.io/cloud-builders/npm'
    args: ['install','-g','@angular/cli' ]

  # Install node packages
  - name: 'gcr.io/cloud-builders/npm'
    args: [ 'install' ]

  # Build productive files
  - name: 'node:12'
    entrypoint: npm
    args: [ 'run', 'build', '--prod', '--aot' ]

  # Deploy to google cloud app egnine
  - name: 'gcr.io/cloud-builders/gcloud'
    args: ['app', 'deploy', 'client.yaml']

第三步出现错误(在日志第2步因为从0开始):

我真的对这个错误感到困惑,因为我不明白为什么构建方法不能正常工作。其实我在本地运行npm run build --prod是没有问题的。

希望你能帮我解决这个问题。

感谢您花时间解决我的问题。我爱你社区❤️

[编辑]

添加 package.json 依赖项的小更新。

{
  "name": "frontend",
  "version": "0.0.0",
  "description": "The frontend part for the 4th year project",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~11.0.0",
    "@angular/common": "~11.0.0",
    "@angular/compiler": "~11.0.0",
    "@angular/core": "~11.0.0",
    "@angular/forms": "~11.0.0",
    "@angular/platform-browser": "~11.0.0",
    "@angular/platform-browser-dynamic": "~11.0.0",
    "@angular/router": "~11.0.0",
    "rxjs": "~6.6.0",
    "tslib": "^2.0.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.1100.1",
    "@angular/cli": "~11.0.1",
    "@angular/compiler-cli": "~11.0.0",
    "@types/jasmine": "~3.6.0",
    "@types/node": "^12.11.1",
    "codelyzer": "^6.0.0",
    "jasmine-core": "~3.6.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~5.1.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.0.3",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "protractor": "~7.0.0",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~4.0.2"
  }
}

我怀疑问题出在<base href=""> 或前端文件夹内client.yaml 中的路径

client.yaml 文件:

service: default
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /
  static_files: dist/index.html
  upload: frontend/index.html
- url: /
  static_dir: dist

还有.gcloudignore

e2e/
node_modules/
src/
coverage
^(.*/)?\..*$
^(.*/)?.*\.json$
^(.*/)?.*\.md$
^(.*/)?.*\.yaml$
^LICENSE

【问题讨论】:

  • 尽量不要发布图片,而是发布 .yaml 文件的实际代码或内容,以便更轻松地重现问题。您是否尝试过探索提到的任何选项 here 作为解决问题的附加步骤。
  • 我一直在尝试重现该问题,但未成功,因此可能是在该步骤运行时未安装依赖项,因此弹出ENOENT: no such file or directory
  • @DanielOcando 不,我不尝试这些选项,因为我在使用npm run build --prod 的本地构建中没有这个问题它仅使用 cloudbuild 进行部署。抱歉图片,我会上传我的帖子谢谢。
  • @DanielOcando 我真的很困惑,因为在部署期间,在npm run build --prod 之前我运行了npm install -g @angular/cli,所以我的新环境现在包含最新版本的@angular/cli。然后,我使用npm install 安装所有必要的依赖项。所以,我不明白为什么没有安装依赖项。谢谢你的时间。
  • 您能否发布正在使用的依赖项以尝试更好的复制?

标签: angular google-app-engine github google-cloud-platform google-cloud-build


【解决方案1】:

我找到了解决办法。

其实出现这个错误是因为部署后“./src”文件夹不存在。我的错误,在我的 .cloudignore 文件中,我包含了 src 文件夹,因此我的应用程序无法构建 src 文件夹,因为它从未导入。

发送的错误不是很清楚,但我现在可以继续。

感谢@DanielOcando 抽出宝贵时间。

【讨论】:

  • 哦!接得好!我很高兴你解决了这个问题。我想这就是我无法重现您的问题的原因:)
  • 是的,我也这么认为。再次感谢你:)
猜你喜欢
  • 2021-09-24
  • 1970-01-01
  • 2021-12-31
  • 1970-01-01
  • 2018-05-29
  • 1970-01-01
  • 2019-02-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多