0

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
    The angular cli generates a dist folder with the ng build -prod command. The content of dist folder must be placed into your server – AMagyar Nov 22 '16 at 11:27
  • Yes but it isn't possible to run a server with just the dist folder and some form of webserver, or have you found a way? – Anton Steenvoorden Nov 22 '16 at 11:45
  • I've done it with TeamCity and Octopus Deploy and what I do is exactly what AMagyar said. In TeamCity a run "ng build -prod" then pack the dist folder with OctoPack and send it over to Octopus Deploy. Octopus pushes the folder into Azure. I've also done the same but pushing into a location where I had IIS configured. – Thiago Passos Nov 23 '16 at 02:45

2 Answers2

4

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

Manuel
  • 9,112
  • 13
  • 70
  • 110
1

you can run ng build, no need for ng serve

Daniel Fanica
  • 433
  • 1
  • 4
  • 11