使用Jenkins和独立的生产服务器进行Angular 2连续部署 [英] Angular 2 continuous deployment with jenkins and seperate production server

查看:82
本文介绍了使用Jenkins和独立的生产服务器进行Angular 2连续部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在生产中运行Angular 2的最佳实践.我被要求建立一个软件工厂(持续集成,自动化构建,自动化部署).

I would like to know what is best practice for running Angular 2 in production. I am asked to build a software factory (continuous integration, automated build, automated deployment).

让我感到困惑的是:

我们不使用开发服务器.我们期望将应用程序及其依赖项部署到实际的生产服务器上. https://angular.io/docs/ts/Latest/guide/webpack.html#!#production-configuration

We don't use a development server. We're expected to deploy the application and its dependencies to a real production server. https://angular.io/docs/ts/latest/guide/webpack.html#!#production-configuration

为什么必须在同一服务器上运行该应用程序?

Why do I have to run the application on the same server?

目前,我已经设置了一个詹金斯服务器.这个想法是,当发生更改时(每15分钟轮询一次git),它将测试该软件,并在成功启动构建后将其自动部署到另一台服务器.但是使用Angular CLI,build命令不会生成可部署的dist文件夹.您仍然必须通过服务来运行它.

Currently I have set-up a jenkins server. The idea is that when changes occur (it polls git every 15 min) it tests the software and on succeeding starts a build and automatically deploys this to another server. But with the Angular CLI the build command doesn't generate a deployable dist folder. You still have to run it through ng serve.

我仅在生产服务器上构建它的问题是,如果测试失败,则不应继续进行测试.

The issue I have with just building it on the production server is that upon failing the test it should not proceed.

有人有没有实现类似的东西或有一个想法来设置它?

Has anyone implemented something simular or have an idea how to set this up?

推荐答案

取决于您的应用程序结构,测试和部署策略. Angular实施了各种测试策略,例如角度测试实用程序,茉莉,用于单元测试的业力和/或用于2端测试的量角器.有关详细信息,请参见角度测试上的文档.

Depends on your application structure, testing and deployment strategy. Angular implements various testing strategies like angular testing utilities, jasmin, karma for unit tests and / or protractor for end 2 end test. For details see the docs on angular testing.

  1. GitHook或定期检查以触发Jenkins
  2. 进行构建ng build
  3. 使用ng test
  4. 通过业力运行单元测试
  5. 使用ng e2e通过量角器运行第2端最终测试
  6. 将Angular 2 App部署到例如. github页面
  1. GitHook or periodic check to trigger Jenkins
  2. Make build ng build
  3. run unit test through karma with ng test
  4. run end 2 end test through protractor with ng e2e
  5. Deploy Angular 2 App to eg. github pages

根据您的设置,您还拥有一个API服务器,但我的工作流程可能如下所示:

Depending on your setup you also have an API-Server, than my workflow may look something like this:

  1. API服务器单元测试
  2. API服务器API/端到端测试
  3. API Server部署新环境
  4. 取决于API策略生成测试环境
  5. 构建测试
  6. ng测试(单元测试)
  7. ng e2e(第2项最终测试)
  8. 为生产而建造
  9. 部署到新环境
  10. 测试新环境(测试+运行状况检查)
  11. 将网址CNAME交换到新环境
  12. 终止旧的API
  1. API Server Unit Test
  2. API Server API / E2E Tests
  3. API Server deployment new environment
  4. Depending on API strategy spawn test environment
  5. build for test
  6. ng test (unit test)
  7. ng e2e (end 2 end test)
  8. build for production
  9. Deploy to new environment
  10. Test new environment (Test + Healthcheck)
  11. Swap Url CNAME to new environment
  12. Terminate old API

或者您可以通过将应用程序捆绑并构建到服务器中并仅仅扮演新服务器版本的角色来完成此任务,那么您的API和SPA始终保持同步,并且您不必担心API版本控制,交叉脚本. ..

Or you simplyfy this by bundling and building your application into your server and just role out a new server version, then your API and SPA is allways in sync and you do not have to worry about API Versioning, Cross-Side Scripting ...

在那里读书

  • Using Testacular with Jenkins for AngularJS e2e Testing
  • Karma
  • NodeJS continious integration

这篇关于使用Jenkins和独立的生产服务器进行Angular 2连续部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆