ANGULAR 使用 CloudBuild 在 Google App Engine 中部署构建 --prod 错误
ANGULAR build --prod error deploying in Google App Engine using CloudBuild
你好,
为了上下文化,我正在使用 Google App Engine (GAE) 开发 Web 应用程序。事实上,我使用三种不同的 GAE 服务。对于后端,分析和前端 Angular.
在GIT中我的架构如下:
事实上,我在根目录下写了一个全局 cloudbuild.yaml
文件,如下所示,以调用每个服务目录中的所有其他特定 cloudbuild.yaml
文件(“/api”,“/分析", "/前端"):
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
我找到了解决方案。
其实这个错误是因为部署后“./src”文件夹不存在。我的错误是,在我的 .cloudignore
文件中包含了 src
文件夹,因此我的应用程序不可能构建 src
文件夹,因为它从未导入过。
发送的错误不是很清楚,但我现在可以继续了。
感谢@DanielOcando 抽出时间。
你好,
为了上下文化,我正在使用 Google App Engine (GAE) 开发 Web 应用程序。事实上,我使用三种不同的 GAE 服务。对于后端,分析和前端 Angular.
在GIT中我的架构如下:
事实上,我在根目录下写了一个全局 cloudbuild.yaml
文件,如下所示,以调用每个服务目录中的所有其他特定 cloudbuild.yaml
文件(“/api”,“/分析", "/前端"):
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
我找到了解决方案。
其实这个错误是因为部署后“./src”文件夹不存在。我的错误是,在我的 .cloudignore
文件中包含了 src
文件夹,因此我的应用程序不可能构建 src
文件夹,因为它从未导入过。
发送的错误不是很清楚,但我现在可以继续了。
感谢@DanielOcando 抽出时间。