|
1 |
| -# Official project releases |
| 1 | +codeorigin.jquery.com |
2 | 2 | =====================
|
3 | 3 |
|
4 |
| -This repo is used to build a Docker container that serves the codeorigin site for jQuery and related projects. It is designed to deploy easily, and includes a "break glass in case of emergency" minimal config mode should codeorigin need to be redeployed urgently. |
| 4 | +## Add new assets |
5 | 5 |
|
6 |
| -It also contains the files necessary to build and deploy releases.jquery.com on a separate host, which provides an index of the files on codeorigin. |
| 6 | +To publish a new release, project maintainers should commit new assets to the `cdn/` directory and push to the `main` branch. The jQuery CDN (code.jquery.com) and releases site (releases.jquery.com) will both automatically rebuild. |
7 | 7 |
|
8 |
| -## Build a local copy of codeorigin |
| 8 | +------- |
9 | 9 |
|
10 |
| -### Default, no restrictions (development or emergency mode) |
| 10 | +## jQuery CDN |
11 | 11 |
|
12 |
| -To build a local container (defaults to "break glass" mode): |
| 12 | +The jQuery CDN assets are served from a static file server (Nginx), provisioned through Docker. |
13 | 13 |
|
14 |
| -1. Install Docker |
15 |
| -1. Clone this repo, and `cd` into it |
16 |
| -1. Build the image: `docker build -t releases ./` |
17 |
| -1. Run the container, exposing port 80: `docker run -p 127.0.0.1:80:80/tcp releases` |
18 |
| -1. To exit the container, press `ctrl+c` |
| 14 | +Prerequisites: |
| 15 | +* Docker (see [Docker CE for Linux](https://docs.docker.com/install/#server), [Docker for Mac](https://hub.docker.com/editions/community/docker-ce-desktop-mac), or [Docker for Windows](https://docs.docker.com/docker-for-windows/install/)). |
| 16 | +* Git. |
19 | 17 |
|
20 |
| -### Redirect non-origin pulls to CDN (production mode) |
| 18 | +### Local development |
21 | 19 |
|
22 |
| -To build a local container in deployment mode (redirecting any requests without the magic header that indicates an origin pull), build the container with the header value in an environment variable: |
| 20 | +**Test the container**: |
23 | 21 |
|
24 |
| -1. Install Docker |
25 |
| -1. Clone this repo, and `cd` into it |
26 |
| -1. Generate a random string for the environment variable: ``CDN_ACCESS_KEY=`openssl rand -hex 32` `` |
27 |
| -1. Build the image: `docker build -t prod-releases --build-arg CDN_ACCESS_KEY=$CDN_ACCESS_KEY ./` |
28 |
| -1. Run the container, exposing port 80: `docker run -p 127.0.0.1:80:80/tcp prod-releases` |
29 |
| -1. To exit the container, press `ctrl+c` |
| 22 | +1. Build the image, by running in a clone of this repo: |
| 23 | + `docker build -t codeorigin-dev ./` |
| 24 | +1. Start a container, exposing port 80: |
| 25 | + `docker run --rm -p 4000:80/tcp codeorigin-dev` |
| 26 | +1. The site is now running at <http://localhost:4000/jquery-3.0.0.js>. |
| 27 | + To stop the container, press `ctrl+c` |
30 | 28 |
|
31 |
| -Note that you will need to keep track of `$CDN_ACCESS_KEY` and add it to the headers sent for origin pulls. To test whether this is working correctly, you can use `curl`: |
| 29 | +**Inspect the container**: |
32 | 30 |
|
33 |
| -* This should always redirect to `code.jquery.com`: `curl -i localhost/jquery-3.1.1.js` |
34 |
| -* This should always deliver a copy of the file (don't forget to set the environment variable in your current shell): `curl -i -H "x-cdn-access: ${CDN_ACCESS_KEY}" localhost/jquery-3.1.1.js` |
| 31 | +Run it with a shell entrypoint and set interactive/tty mode by adding the parameters `-i -t --entrypoint /bin/sh`. |
| 32 | +Note that when inspecting the container, nginx will not be started. |
35 | 33 |
|
36 |
| -## Build the production site |
| 34 | +``` |
| 35 | +docker run --rm -p 4000:80/tcp -i -t --entrypoint /bin/sh codeorigin-dev |
| 36 | +``` |
37 | 37 |
|
38 |
| -To deploy, first generate the CDN access key. Next, you'll need to configure the container host to build from the Dockerfile in this repository, and use the CDN access key as build arguments. Finally, you'll configure the CDN to send both the Host header and the access key during origin pulls. |
| 38 | +**Debug nginx**: |
39 | 39 |
|
40 |
| -1. Generate the access key: ``CDN_ACCESS_KEY=`openssl rand -hex 16` `` |
41 |
| -1. Configure the container host to build from this repo, and set this build variable: |
42 |
| - * `CDN_ACCESS_KEY=(Insert the value of $CDN_ACCESS_KEY here)` |
43 |
| -1. Add the magic header and the host header at the CDN for origin pulls: `x-cdn-access: (Insert the value of $CDN_ACCESS_KEY here)|Host: (insert URL to app container)` |
| 40 | +In `cfg/defualt.cong`, change `error_log … crit` to `error_log … debug` and then build+run as usual. |
44 | 41 |
|
45 |
| -## In case of emergency |
| 42 | +**Test the container in restricted mode**: |
46 | 43 |
|
47 |
| -If you need to deploy a codeorigin container immediately, or if there are origin pull failures and you're not sure why, deploy the container without configuring the `CDN_ACCESS_KEY` environment variable. The codeorigin server will respond to all requests without redirecting non-origin pulls to the CDN, so this should be only used in case of emergencies. |
| 44 | +There is a restricted mode, which responds to unauthorized static file requests with a redirect instead of serving files. |
48 | 45 |
|
49 |
| -## Build the releases sites |
| 46 | +1. Run `export CDN_ACCESS_KEY="$(openssl rand -hex 32)"` |
| 47 | +1. Build the image, by running in a clone of this repo: |
| 48 | + `docker build -t codeorigin-strict --build-arg "CDN_ACCESS_KEY=$CDN_ACCESS_KEY" ./` |
| 49 | +1. Start a container, exposing port 80: |
| 50 | + `docker run --rm -p 4000:80/tcp codeorigin-strict` |
| 51 | +1. The site is now running at <http://localhost:4000/jquery-3.0.0.js>. |
| 52 | + To stop the container, press `ctrl+c` |
50 | 53 |
|
51 |
| -To build and deploy your changes for previewing in a [`jquery-wp-content`](https://github.com/jquery/jquery-wp-content) instance, follow the [workflow instructions](http://contribute.jquery.org/web-sites/#workflow) from our documentation on [contributing to jQuery web sites](http://contribute.jquery.org/web-sites/). |
| 54 | +In the restricted mode: |
52 | 55 |
|
53 |
| -## Add or update project release files |
| 56 | +* Simple requests for static files redirect to `code.jquery.com/*`, e.g. `curl -i 'http://localhost/jquery-3.0.0.js'`. |
| 57 | +* Requests with the access key will respond by serving the file: `curl -i -H "x-cdn-access: $CDN_ACCESS_KEY" 'http://localhost/jquery-3.0.0.js'` |
| 58 | +* Requests with an invalid key will redirect the same as without: `curl -i -H "x-cdn-access: wrong" 'http://localhost/jquery-3.0.0.js'` |
54 | 59 |
|
55 |
| -To add a new release or update an existing one, simply commit the new file to the `cdn` directory and merge to the `main` branch. The container will rebuild automatically. |
| 60 | +### Production deployment |
| 61 | + |
| 62 | +1. First, generate a CDN access key: `openssl rand -hex 32`. |
| 63 | +1. At a hosting platform of your choosing, build a container from the Dockerfile in this repository, and pass the CDN access key as build arguments. |
| 64 | +1. Finally, configure the CDN to use the container address as its origin, with special handling to augment origin pulls with a `Host: code.jquery.com` header, and a `x-cdn-access` header with the access key. |
| 65 | + |
| 66 | +### In case of emergency |
| 67 | + |
| 68 | +If you need to deploy a standalone codeorigin site immediately, or if there are origin pull failures and you're not sure why, then deploy the container without any `CDN_ACCESS_KEY` environment variable. The codeorigin container then default to its unrestricted mode (no offload redirects). |
| 69 | + |
| 70 | +------- |
| 71 | + |
| 72 | +## WordPress build |
| 73 | + |
| 74 | +This repository is also used to update the asset catalog at <https://releases.jquery.com/>, which is an auto-generated WordPress site. |
| 75 | + |
| 76 | +To preview changes for a [`jquery-wp-content`](https://github.com/jquery/jquery-wp-content) instance, follow the [workflow instructions](http://contribute.jquery.org/web-sites/#workflow) from our documentation on [contributing to jQuery Foundation web sites](http://contribute.jquery.org/web-sites/). |
0 commit comments