Skip to content

Commit e2aa7de

Browse files
committed
Add support for purge.php
Signed-off-by: Brian Warner <brian@bdwarner.com>
1 parent db2822f commit e2aa7de

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

Dockerfile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ FROM nginx:alpine
22

33
RUN apk add vim
44
COPY cfg/vimrc /etc/vim/vimrc
5-
5+
COPY cfg/config-sample.json /usr/share/nginx/html/
66

77
ARG CDN_ACCESS_KEY=''
8+
ARG CDN_PURGE_API_TOKEN=''
9+
ARG CDN_PURGE_ACCOUNT_HASH=''
810
COPY cfg/default.conf /etc/nginx/conf.d/default.conf
911

1012
# If the CDN_ACCESS_KEY environment variable is *not* set, operate in "break glass" mode where the
@@ -16,8 +18,19 @@ RUN if [ -n "$CDN_ACCESS_KEY" ]; then \
1618
sed -i s/##PLACEHOLDER-cdn_reroute-DO_NOT_CHANGE##/"if (\$reroute_to_cdn) { return 301 \$scheme:\/\/code.jquery.com\$uri; }"/g /etc/nginx/conf.d/default.conf; \
1719
fi
1820

21+
# Load the releases into the container
22+
1923
COPY cdn/* /usr/share/nginx/html/
2024
COPY git/* /usr/share/nginx/html/
2125

26+
# If the CDN_PURGE_API_TOKEN and CDN_PURGE_ACCOUNT_HASH are defined, create the config.json file
27+
# that holds credentials used by purge.php to trigger the Highwinds purge API.
28+
29+
RUN if [ -n "$CDN_PURGE_API_TOKEN" -a -n "$CDN_PURGE_ACCOUNT_HASH" ]; then \
30+
cp /usr/share/nginx/html/config-sample.json /usr/share/nginx/html/config.json && \
31+
sed -i s/example_token/"$CDN_PURGE_API_TOKEN"/g /usr/share/nginx/html/config.json && \
32+
sed -i s/example_hash/"$CDN_PURGE_ACCOUNT_HASH"/g /usr/share/nginx/html/config.json; \
33+
fi
34+
2235
EXPOSE 80
2336

README.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ This repo is used to build a Docker container that serves the codeorigin site fo
55

66
## Build a local copy
77

8+
### Default, no restrictions
9+
810
To build a local container (defaults to "break glass" mode):
911

1012
1. Install Docker
@@ -13,6 +15,8 @@ To build a local container (defaults to "break glass" mode):
1315
1. Run the container, exposing port 80: `docker run -p 127.0.0.1:80:80/tcp releases`
1416
1. To exit the container, press `ctrl+c`
1517

18+
### Redirect non-origin pulls to CDN
19+
1620
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:
1721

1822
1. Install Docker
@@ -27,12 +31,38 @@ Note that you will need to keep track of `$CDN_ACCESS_KEY` and add it to the hea
2731
* This should always redirect to `code.jquery.org`: `curl -i localhost/jquery-3.1.1.js`
2832
* This should always deliver a copy of the file (don't forget to set the environment variable in your current shell): `curl -i -H "cdn-access: ${CDN_ACCESS_KEY}" localhost/jquery-3.1.1.js`
2933

34+
### Add support for `purge.php`
35+
36+
To build a container with support for `purge.php`, set environment variables with the CDN's API key and account hash.
37+
38+
1. Install Docker
39+
1. Clone this repo, and `cd` into it
40+
1. Set environment variables for the CDN API key and account hash: `CDN_PURGE_API_TOKEN=(jQuery secret API token) && CDN_PURGE_ACCOUNT_HASH=(jQuery account hash)`
41+
1. Build the image: `docker build -t purge-releases --build-arg CDN_PURGE_API_TOKEN=$CDN_PURGE_API_TOKEN --build-arg CDN_PURGE_ACCOUNT_HASH=$CDN_PURGE_ACCOUNT_HASH ./`
42+
1. Run the container, exposing port 80: `docker run -p 127.0.0.1:80:80/tcp purge-releases`
43+
1. To exit the container, press `ctrl+c`
44+
45+
### Production clone
46+
47+
To build a production clone, include the steps for both non-origin redirects and `purge.php`.
48+
49+
1. Install Docker
50+
1. Clone this repo, and `cd` into it
51+
1. Generate a random string for the environment variable: ``CDN_ACCESS_KEY=`openssl rand -hex 16` ``
52+
1. Set environment variables for the CDN API key and account hash: `CDN_PURGE_API_TOKEN=(jQuery secret API token) && CDN_PURGE_ACCOUNT_HASH=(jQuery account hash)`
53+
1. Build the image: `docker build -t purge-releases --build-arg CDN_ACCESS_KEY=$CDN_ACCESS_KEY --build-arg CDN_PURGE_API_TOKEN=$CDN_PURGE_API_TOKEN --build-arg CDN_PURGE_ACCOUNT_HASH=$CDN_PURGE_ACCOUNT_HASH ./`
54+
1. Run the container, exposing port 80: `docker run -p 127.0.0.1:80:80/tcp purge-releases`
55+
1. To exit the container, press `ctrl+c`
56+
3057
## Build the production site
3158

32-
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 a build argument. Finally, you'll configure the CDN to send both the Host header and the access key during origin pulls.
59+
To deploy, first generate the CDN access key and locate the CDN API token and account hashes. Next, you'll need to configure the container host to build from the Dockerfile in this repository, and use the CDN access key, CDN API token, and CDN account hash as build arguments. Finally, you'll configure the CDN to send both the Host header and the access key during origin pulls.
3360

3461
1. Generate the access key: ``CDN_ACCESS_KEY=`openssl rand -hex 16` ``
35-
1. Configure the container host to build from this repo, and set this build variable: `CDN_ACCESS_KEY=(Insert the value of $CDN_ACCESS_KEY here)`
62+
1. Configure the container host to build from this repo, and set these build variable:
63+
* `CDN_ACCESS_KEY=(Insert the value of $CDN_ACCESS_KEY here)`
64+
* `CDN_PURGE_API_TOKEN=(Insert the value of the API token here)`
65+
* `CDN_PURGE_ACCOUNT_HASH=(Insert the value of the account hash)`
3666
1. Create the magic header and the host header at the CDN: `cdn-access: (Insert the value of $CDN_ACCESS_KEY here)|Host: (insert URL to app container)`
3767

3868
## In case of emergency

config-sample.json renamed to cfg/config-sample.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
{
2-
"url": "vagrant.codeorigin.jquery.com",
3-
"username": "admin",
4-
"password": "secret",
5-
62
"highwinds": {
73
"api_url": "https://striketracker.highwinds.com",
84
"api_token": "example_token",

0 commit comments

Comments
 (0)