2017-03-09 22:12:01 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# Overview - General
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								## Objective
							 | 
						
					
						
							
								
									
										
										
										
											2018-05-09 18:54:53 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Whenever a PR job is run on the CI infrastructure (e.g. CircleCI), we want to build `angular.io`
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-15 13:47:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								and host the build artifacts on a publicly accessible server so that collaborators (developers,
							 | 
						
					
						
							
								
									
										
										
										
											2018-05-09 18:54:53 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								designers, authors, etc) can preview the changes without having to checkout and build the app
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								locally.
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-09 22:12:01 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								## Source code
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								In order to make it easier to administer the server and version-control the setup, we are using
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								[docker](https://www.docker.com) to run a container on a VM. The Dockerfile and all other files
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								necessary for creating the docker container are stored (and versioned) along with the angular.io
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								project's source code (currently part of the angular/angular repo) in the `aio-builds-setup/`
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								directory.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								## Setup
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								The VM is hosted on [Google Compute Engine](https://cloud.google.com/compute/). The host OS is
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								debian:jessie. For more info how to set up the host VM take a look at the "Setting up the VM"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								section in [TOC](_TOC.md).
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								## Security model
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								Since we are managing a public server, it is important to take appropriate measures in order to
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								prevent abuse. For more details on the challenges and the chosen approach take a look at the
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								[security model](overview--security-model.md).
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								## The 10000 feet view
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								This section gives a brief summary of the several operations performed on CI and by the docker
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								container:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-05-09 18:54:53 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								### On CI (CircleCI)
							 | 
						
					
						
							
								
									
										
										
										
											2018-09-06 18:28:20 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								- The CI script builds the angular.io project.
							 | 
						
					
						
							
								
									
										
										
										
											2018-05-09 18:54:53 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								- The CI script gzips and stores the build artifacts in the CI infrastructure.
							 | 
						
					
						
							
								
									
										
										
										
											2018-09-06 18:28:20 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								- When the build completes, CircleCI triggers a webhook on the preview-server.
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-09 22:12:01 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								More info on how to set things up on CI can be found [here](misc--integrate-with-ci.md).
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-05-09 18:54:53 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								### Hosting build artifacts
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-15 13:47:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								- nginx receives the webhook trigger and passes it through to the preview server.
							 | 
						
					
						
							
								
									
										
										
										
											2018-09-06 18:28:20 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								- The preview-server runs several preliminary checks to determine whether the request is valid and
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  whether the corresponding PR can have a (public or non-public) preview (more details can be found
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  [here](overview--security-model.md)).
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-15 13:47:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								- The preview-server makes a request to CircleCI for the URL of the AIO build artifacts.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								- The preview-server makes a request to this URL to receive the artifact - failing if the size
							 | 
						
					
						
							
								
									
										
										
										
											2018-05-09 18:54:53 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  exceeds the specified max file size - and stores it in a temporary location.
							 | 
						
					
						
							
								
									
										
										
										
											2018-09-06 18:28:20 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								- The preview-server runs more checks to determine whether the preview should be publicly accessible
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  or stored for later verification (more details can be found [here](overview--security-model.md)).
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-15 13:47:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								- The preview-server changes the "visibility" of the associated PR, if necessary. For example, if
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-19 01:15:07 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  builds for the same PR had been previously deployed as non-public and the current build has been
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-25 22:13:03 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  automatically verified, all previous builds are made public as well.
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-15 13:47:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  If the PR transitions from "non-public" to "public", the preview-server posts a comment on the
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-19 01:15:07 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  corresponding PR on GitHub mentioning the SHAs and the links where the previews can be found.
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-15 13:47:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								- The preview-server verifies that it is not trying to overwrite an existing build.
							 | 
						
					
						
							
								
									
										
										
										
											2018-09-06 18:28:20 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								- The preview-server deploys the artifacts to a sub-directory named after the PR number and the
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  first few characters of the SHA: `<PR>/<SHA>/`
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-25 22:13:03 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  (Non-publicly accessible PRs will be stored in a different location, but again derived from the PR
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  number and SHA.)
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-15 13:47:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								- If the PR is publicly accessible, the preview-server posts a comment on the corresponding PR on
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-19 01:15:07 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  GitHub mentioning the SHA and the link where the preview can be found.
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-09 22:12:01 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-19 14:52:58 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								More info on the possible HTTP status codes and their meaning can be found
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								[here](overview--http-status-codes.md).
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-09 22:12:01 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-27 19:43:02 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								### Updating PR visibility
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								- nginx receives a natification that a PR has been updated and passes it through to the
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-15 13:47:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  preview-server. This could, for example, be sent by a GitHub webhook every time a PR's labels
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-27 19:43:02 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  change.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  E.g.: `ngbuilds.io/pr-updated` (payload: `{"number":<PR>,"action":"labeled"}`)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								- The request contains the PR number (as `number`) and optionally the action that triggered the
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  request (as `action`) in the payload.
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-15 13:47:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								- The preview-server verifies the payload and determines whether the `action` (if specified) could
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-27 19:43:02 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  have led to PR visibility changes. Only requests that omit the `action` field altogether or
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  specify an action that can affect visibility are further processed.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  (Currently, the only actions that are considered capable of affecting visibility are `labeled` and
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  `unlabeled`.)
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-15 13:47:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								- The preview-server re-checks and if necessary updates the PR's visibility.
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-27 19:43:02 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								More info on the possible HTTP status codes and their meaning can be found
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								[here](overview--http-status-codes.md).
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-09 22:12:01 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								### Serving build artifacts
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-15 13:47:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								- nginx receives a request for a hosted preview resource on a subdomain corresponding to the PR and SHA.
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-25 22:48:36 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  E.g.: `pr<PR>-<SHA>.ngbuilds.io/path/to/resource`
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								- nginx maps the subdomain to the correct sub-directory and serves the resource.
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-09 22:12:01 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  E.g.: `/<PR>/<SHA>/path/to/resource`
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-27 19:43:02 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								More info on the possible HTTP status codes and their meaning can be found
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-19 14:52:58 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								[here](overview--http-status-codes.md).
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-09 22:12:01 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								### Removing obsolete artifacts
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								In order to avoid flooding the disk with unnecessary build artifacts, there is a cronjob that runs a
							 | 
						
					
						
							
								
									
										
										
										
											2018-09-06 18:28:20 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								clean-up task once a day. The task retrieves all open PRs from GitHub and removes all directories
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								that do not correspond to an open PR.
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-09 22:12:01 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								### Health-check
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								The docker service runs a periodic health-check that verifies the running conditions of the
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								container. This includes verifying the status of specific system services, the responsiveness of
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-15 13:47:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								nginx and the preview-server and internet connectivity.
							 |