Gcloud Angular 6 个应用程序部署耗时极长

Gcloud Angular 6 app deployment taking extremely long

我正在尝试将我的 angular 项目部署到 gCloud 并按照此处提到的步骤进行操作 https://medium.com/@st_yuri/how-to-deploy-an-angular-8-application-and-a-python-3-flask-restplus-api-on-google-cloud-using-ebbed60e665f 和 运行 以下命令。

 gcloud app deploy 

我的应用程序开始部署,但速度非常慢,出于某种原因,我看到有 32000 个文件正在上传。这是第一次部署,这是正常现象还是我错过了什么。已经 运行 3 个小时了,进展甚微。

我的app.yaml文件如下

runtime: python37
api_version: 1
handlers:
- url: /.*
  static_files: dist/index.html
  upload: dist/index.html

至于您的指南,您必须在 app.yaml 中添加 skip_files 部分。类似于:

skip_files:
  - node_modules/
  - ^(.*/)?app\.yaml

我建议你使用我最近使用的指南https://dev.to/marwan01/deploy-an-angular-app-using-google-cloud-run-3p4a

您在 Google 云上使用 Cloud Run

您必须创建 Dockerfile

FROM node:12-slim
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install -g @angular/cli
RUN npm install
COPY . ./
RUN npm run build
EXPOSE 8080
CMD [ "node", "server.js" ]

server.js

var express = require('express');
var app = express();
app.use(express.static('dist/PROJECT-NAME'));
app.get('/', function (req, res,next) {
res.redirect('/');
});
app.listen(8080)

然后用https://cloud.google.com/sdk/install

gcloud builds submit --tag gcr.io/PROJECT-ID/SERVICE-NAME
gcloud run deploy --image gcr.io/PROJECT-ID/PROJECT-NAME --platform managed

就是它。

node_modules 是你的 32000 个文件。 查看该指南中的第 5 节。上面有带有 node_modules 的 .dockerignore。这意味着您不会将其上传到云端。

如果您使用该指南并有任何问题,我可以提供帮助。