Skip to content

Commit 56262b3

Browse files
committed
Add nginx config in docker image
1 parent f04d31b commit 56262b3

6 files changed

+103
-56
lines changed

Dockerfile

+9-5
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ RUN cd /root/docs/ \
1111
&& make build
1212

1313
FROM nginx:1.23-alpine
14+
MAINTAINER Deepfence Inc
1415
LABEL deepfence.role=system
1516

16-
WORKDIR /home/deepfence
17-
ADD nginx.conf /etc/nginx/conf.d/default.conf
18-
RUN mkdir -p /var/www/html
19-
COPY --from=build /root/docs/build /var/www/html
20-
RUN ls -alh /var/www/html
17+
ADD community.deepfence.io.conf /etc/nginx/conf.d/community.deepfence.io.conf.template
18+
ADD docs.deepfence.io.conf /etc/nginx/conf.d/docs.deepfence.io.conf
19+
ADD docker-entrypoint.sh /docker-entrypoint.d/docker-entrypoint.sh
20+
RUN apk update \
21+
&& rm /etc/nginx/conf.d/default.conf \
22+
&& mkdir -p /var/www/html \
23+
&& chmod +x /docker-entrypoint.d/docker-entrypoint.sh
24+
COPY --from=build /root/docs/build /var/www/html

README.md

+26-18
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,22 @@ Alternatively, you can build-and-serve the site as follows:
7474
yarn run serve --build --port 8000 --host 0.0.0.0
7575
```
7676

77+
## Docker image
78+
79+
```bash
80+
./bootstrap.sh
81+
docker build -f Dockerfile -t deepfenceio/deepfence_docs:latest .
82+
docker run -dit --restart=always --name=deepfence-docs -e GITHUB_USER=aaa -e GITHUB_ACCESS_TOKEN=aaa -p 80:80 deepfenceio/deepfence_docs
83+
```
84+
7785
## Hosting the site
7886

7987
The site is intended to be hosted behind two domains:
8088

8189
* `community.mydomain.com`: the primary domain to be used to serve the site
8290
* `docs.mydomain.com`: used to provide links to the docs, particularly for the enterprise product documentation where a 'community' domain would not be appropriate.
8391

84-
It's an anti pattern to serve an SPA from multiple domains, and switch domains during routing. Configuration is non-trivial and the user experience is poor as a change of domain means a full reload of the SPA. Therefore, `docs.mydomain.com/productname` redirects to `community.mydomain.com/docs/productname` to achieve this.
92+
It's an antipattern to serve an SPA from multiple domains, and switch domains during routing. Configuration is non-trivial and the user experience is poor as a change of domain means a full reload of the SPA. Therefore, `docs.mydomain.com/productname` redirects to `community.mydomain.com/docs/productname` to achieve this.
8593

8694
The following, minimal NGINX configuration is sufficient:
8795

@@ -134,24 +142,24 @@ Follow these steps if you'd like to add docs to a new Deepfence project, and to
134142

135143
### Get the Skeleton Files
136144

137-
Check out the github repo you wish to add docs to.
145+
Check out the GitHub repo you wish to add docs to.
138146

139147
Remove (back-up) any existing `/docs/` directory in the repo.
140148

141149
Copy `skel/docs` into the root of the repo, to create a new `/docs/` directory. This directory contains:
142150

143-
| Filename | Purpose |
144-
| -------- | ------- |
145-
| `docs/docusaurus.config.js` | Sample configuration for your docusaurus docs site |
146-
| `docs/sidebars.js` | Sample sidebar for your documentation tree |
147-
| `docs/README.md` | README for the docs in your new repo, with build instructions |
148-
| `docs/docs/threatmapper` | Location for your docs files (must rename first) |
149-
| `docs/docs/threatmapper/index.md` | Your first documentation file |
150-
| In `docs/static:`<br/> `css/deepfence.css`,<br/> `img/deepfence-logo-black.svg`,<br/> `img/deepfence-logo-white.svg` | Styling for the deepfence skin for the `classic` theme |
151-
| `docs/src/pages/index.md` | Default home page for Deepfence docs; no need to edit |
152-
| `docs/yarn.lock`, `docs/package.json` | NPM package list, used when initialized with `yarn` |
153-
| `docs/.gitignore` | Configuration to ignore node dependencies and temporary files |
154-
| `docs/babel.config.js` | Babel config |
151+
| Filename | Purpose |
152+
|----------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------|
153+
| `docs/docusaurus.config.js` | Sample configuration for your docusaurus docs site |
154+
| `docs/sidebars.js` | Sample sidebar for your documentation tree |
155+
| `docs/README.md` | README for the docs in your new repo, with build instructions |
156+
| `docs/docs/threatmapper` | Location for your docs files (must rename first) |
157+
| `docs/docs/threatmapper/index.md` | Your first documentation file |
158+
| In `docs/static:`<br/> `css/deepfence.css`,<br/> `img/deepfence-logo-black.svg`,<br/> `img/deepfence-logo-white.svg` | Styling for the deepfence skin for the `classic` theme |
159+
| `docs/src/pages/index.md` | Default home page for Deepfence docs; no need to edit |
160+
| `docs/yarn.lock`, `docs/package.json` | NPM package list, used when initialized with `yarn` |
161+
| `docs/.gitignore` | Configuration to ignore node dependencies and temporary files |
162+
| `docs/babel.config.js` | Babel config |
155163

156164
These are the basic skeleton files needed to create a local docs site.
157165

@@ -168,14 +176,14 @@ Rename the `docs/threatmapper` directory to be product-appropriate, e.g. `packet
168176
Edit `docusaurus.config.js` to make it product-appropriate. You'll want to replace:
169177

170178
1. config.title
171-
1. config.tagline
172-
1. config.presets.docs.editURL
173-
1. themeconfig.navbar.items[0]
179+
2. config.tagline
180+
3. config.presets.docs.editURL
181+
4. themeconfig.navbar.items[0]
174182

175183
Edit `sidebars.js`:
176184

177185
1. Replace the name of the sidebar object to the appropriate product name.
178-
1. Correct the value in the `sidebar-title`
186+
2. Correct the value in the `sidebar-title`
179187

180188
You will want to edit sidebars.js further, to define the nav structure of the documentation, but that can wait.
181189

community.deepfence.io.conf

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
proxy_cache_path /var/www/cache keys_zone=apicache:1m;
2+
3+
server {
4+
#listen 443 ssl;
5+
listen 80;
6+
server_name community.deepfence.io;
7+
8+
location /gh-cache/ {
9+
proxy_pass https://api.github.com/;
10+
proxy_set_header Host api.github.com;
11+
12+
proxy_set_header Authorization "Basic ${GITHUB_BASIC_AUTH}";
13+
14+
proxy_cache apicache;
15+
add_header X-Cache-Status $upstream_cache_status;
16+
17+
# GH responses have cache-control: private, making them uncacheable
18+
proxy_ignore_headers Cache-Control;
19+
20+
# cache 200, 301, 302 responses for 1m
21+
# errors (e.g. 403 rate limit exceeded) will not be cached
22+
proxy_cache_valid 1m;
23+
24+
# return previous valid response if we get a rate limit
25+
# error, or other error type
26+
proxy_cache_use_stale error timeout http_500 http_503 http_504 http_403 http_429;
27+
}
28+
29+
location /dh-cache/ {
30+
proxy_pass https://hub.docker.com/;
31+
proxy_set_header Host hub.docker.com;
32+
33+
proxy_cache apicache;
34+
add_header X-Cache-Status $upstream_cache_status;
35+
add_header Access-Control-Allow-Origin *;
36+
37+
# cache 200, 301, 302 responses for 1m
38+
# errors (e.g. 403 rate limit exceeded) will not be cached
39+
proxy_cache_valid 1m;
40+
41+
# return previous valid response if we get a rate limit
42+
# error, or other error type
43+
proxy_cache_use_stale error timeout http_500 http_503 http_504 http_403 http_429;
44+
}
45+
46+
location / {
47+
# the contents of the build process from Docusaurus
48+
root /var/www/html;
49+
}
50+
}

docker-entrypoint.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
# vim:sw=4:ts=4:et
3+
4+
set -e
5+
6+
export GITHUB_BASIC_AUTH=$(echo "${GITHUB_USER}:${GITHUB_ACCESS_TOKEN}" | base64)
7+
envsubst '${GITHUB_BASIC_AUTH}' < /etc/nginx/conf.d/community.deepfence.io.conf.template > /etc/nginx/conf.d/community.deepfence.io.conf
8+
rm -f /etc/nginx/conf.d/community.deepfence.io.conf.template

docs.deepfence.io.conf

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
server {
2+
#listen 443 ssl;
3+
listen 80;
4+
server_name docs.deepfence.io;
5+
#ssl_certificate /etc/nginx/certs/minica.pem;
6+
#ssl_certificate_key /etc/nginx/certs/minica-key.pem;
7+
location / {
8+
return 302 $scheme://community.deepfence.io/docs$request_uri;
9+
}
10+
}

nginx.conf

-33
This file was deleted.

0 commit comments

Comments
 (0)