问题
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.
- GitHook or periodic check to trigger Jenkins
- Make build
ng build
- run unit test through karma with
ng test
- run end 2 end test through protractor with
ng e2e
- 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:
- API Server Unit Test
- API Server API / E2E Tests
- API Server deployment new environment
- Depending on API strategy spawn test environment
- build for test
- ng test (unit test)
- ng e2e (end 2 end test)
- build for production
- Deploy to new environment
- Test new environment (Test + Healthcheck)
- Swap Url CNAME to new environment
- 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