简体   繁体   English

将 Angular Universal 9 部署到 Google App Engine

[英]Deploying Angular Universal 9 to Google App Engine

I am not sure the situation has been changed but it seems I got stuck with the versions I am using.我不确定情况是否已经改变,但似乎我被我正在使用的版本卡住了。 Previously, in Angular 7, we were able to generate server files for Angular Universal at the root level so we could have node main.js in app yaml and Google App Engine just found the way to run our web application. Previously, in Angular 7, we were able to generate server files for Angular Universal at the root level so we could have node main.js in app yaml and Google App Engine just found the way to run our web application. It seems this is not possible anymore for Angular 9.对于 Angular 9 来说,这似乎不再可能了。

We are using Angular SSR for our production web site.我们将 Angular SSR 用于我们的生产 web 站点。 It compiles all the server files in /dist-server folder.它编译 /dist-server 文件夹中的所有服务器文件。 There is a docker file to deploy it on Google App Engine:有一个 docker 文件可以将其部署到 Google App Engine 上:

FROM node:12-alpine as buildContainer
WORKDIR /app
COPY ./package.json ./package-lock.json /app/
RUN npm install
COPY . /app
RUN npm run build:ssr // This will create dist/ and dist-server/ folders in the docker
FROM node:12-alpine
WORKDIR /app
COPY --from=buildContainer /app/package.json /app
COPY --from=buildContainer /app/dist /app/dist
COPY --from=buildContainer /app/dist-server /app/dist-server
EXPOSE 4000
CMD ["npm", "run", "serve:ssr"]

In package.json we have:package.json我们有:

"serve:ssr": "node dist-server/main.js",

In order to start the deployment, we type gcloud app deploy in the terminal and everything works fine for this process.为了开始部署,我们在终端中输入gcloud app deploy ,这个过程一切正常。 The main problem is this takes almost 25 mins to finish.主要问题是这需要将近 25 分钟才能完成。 The main bottleneck for the time consuming part is the compiling.耗时部分的主要瓶颈是编译。

I thought we could have compiled the repo on our local dev machine, and copy only dist/ and dist-server folder to the docker and add node dist-server/main.js to run our web application in the docker file.我以为我们可以在本地开发机器上编译 repo,只将dist/dist-server文件夹复制到 docker 并添加node dist-server/main.js以在 Z05B6053C41A21340AFZDZ 文件中运行我们的 web 应用程序。 Whenever I tried to copy only dist and dist-server folder.每当我尝试仅复制distdist-server文件夹时。 I got below error message:我收到以下错误消息:

COPY failed: stat /var/lib/docker/tmp/docker-builder{random numbers}/dist: no such file or directory复制失败:stat /var/lib/docker/tmp/docker-builder{random numbers}/dist:没有这样的文件或目录

I also tried to compile the main.js which is the main server file for angular universal at the same level as app.yaml .我还尝试编译main.js ,它是 angular 通用的主服务器文件,与app.yaml处于同一级别。 I assumed this is required according to Google App Engine Node JS deployment rule since there is an example repo from Google .我假设这是根据 Google App Engine Node JS 部署规则所必需的,因为Google有一个示例 repo。 I cannot compile our main.js file into the root folder, it gives below error message:我无法将我们的 main.js 文件编译到根文件夹中,它给出以下错误消息:

An unhandled exception occurred: Output path MUST not be project root directory!发生未处理的异常:Output 路径不能是项目根目录!

So I am looking for a solution to which does not require Google App Engine to rebuild our repo (since we can do this in our dev machine and upload the compiled files for the sake of time saving) to make the deployment process faster.因此,我正在寻找一种不需要 Google App Engine 重建我们的 repo 的解决方案(因为我们可以在我们的开发机器中执行此操作并上传已编译的文件以节省时间)以加快部署过程。

Thanks for your help谢谢你的帮助

I have found that the .dockerignore file had dist and dist-server folder in it.我发现.dockerignore文件中有 dist 和 dist-server 文件夹。 I have removed those entries.我已经删除了这些条目。 I am able to compile and deploy the docker file on google app engine now.我现在可以在谷歌应用引擎上编译和部署 docker 文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM