Angular 2 continuous deployment with jenkins and seperate production server

走远了吗. 提交于 2021-02-18 19:35:36

问题


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).

What confuses me is this:

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?

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?


回答1:


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 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

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

  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

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 ...

Reading is out there

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



回答2:


you can run ng build, no need for ng serve



来源:https://stackoverflow.com/questions/40740250/angular-2-continuous-deployment-with-jenkins-and-seperate-production-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!