Skip to content

Commit

Permalink
bumped versions; added in-memory-cache plugin; updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
bgadrian committed Oct 6, 2018
1 parent e187ff2 commit 6459aae
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 25 deletions.
12 changes: 7 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
FROM node:9.4-alpine
FROM node:10.11.0-alpine

ENV CHROMIUM_VERSION 63.0.3239.108-r0
ENV PRERENDER_VERSION 5.2.0
ENV CHROMIUM_VERSION 68.0.3440.106-r0
ENV PRERENDER_VERSION 5.4.4
ENV PRERENDER_MEMORY_VERSION 1.0.2
ENV DISPLAY :99.0

WORKDIR /app

RUN addgroup -S prerender && adduser -S -g prerender prerender && \
apk add --no-cache ca-certificates && \
apk add chromium=$CHROMIUM_VERSION --no-cache --repository http://nl.alpinelinux.org/alpine/edge/community && \
npm install [email protected] && \
apk add chromium=${CHROMIUM_VERSION} --no-cache --repository http://nl.alpinelinux.org/alpine/edge/community && \
npm install prerender@${PRERENDER_VERSION} && \
npm install prerender-memory-cache@${PRERENDER_MEMORY_VERSION} && \
rm -rf /var/cache/apk/*

COPY server.js /app/server.js
Expand Down
58 changes: 40 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,51 @@
Docker Image for Prerender
==========================
# Docker Image for Prerender

Dockerized Prerender + Chrome Headless (chromium-browser on Alpine Linux)

Example
-------
https://prerender.io is an open-source nodeJS based web server that servers HTML for web crawlers like Google, Twitter, Slack preview bots and so on. It is used to make SEO for single page web apps built with any framework: React, Angular, VueJS ...

You can secure prerender in 3 ways:
* make it public and use the whitelist/blacklist options
* expose the port to the localhost but binding it only to local interface: `-p 127.0.0.1:3000:3000`
* do not expose the port and put it in a docker network

Docker run: https://docs.docker.com/engine/reference/run/
Prerender: https://prerender.io/documentation
In-memory cache plugin: https://github.com/prerender/prerender-memory-cache

### Examples

Run it with default settings, and expose the port to public:
```bash
docker run --detach \
--name prerender \
-it \
-p 3000:3000
bgadrian/docker-prerender
```
docker container run --name prerender --rm -it -p 3000:3000 ball6847/prerender

Run it with 7 days cache, 10.000 pages limit and in a docker network, the instance can be accesed by its container name by any other container running in the same network.

```bash
docker run --detach \
--name prerender \
-it \
--network my-net
-e "CACHE_MAXSIZE=10000" \
-e "CACHE_TTL=604800" \
bgadrian/docker-prerender
```

To run with docker-compose
### Cache

```yml
version: '3'
You can see the cache in action by reading the logs, eg from multiple calls of `curl localhost:3000/https://twitter.com` you may get <15ms subsequent responses:

services:
prerender:
image: ball6847/prerender:latest
restart: unless-stopped
ports:
- 3000:3000
```bash
2018-10-06T19:58:42.354Z got 200 in 2910ms for https://twitter.com/
2018-10-06T19:59:08.905Z getting https://twitter.com/
2018-10-06T19:59:08.917Z got 200 in 12ms for https://twitter.com/
2018-10-06T19:59:11.551Z getting https://twitter.com/
2018-10-06T19:59:11.557Z got 200 in 6ms for https://twitter.com/
```

Author
------
Porawit Poboonma <[email protected]>
Because the cache is in memory, to purge it (for example at each big release) you can just restart the container: `docker restart prerender`
7 changes: 5 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env node
var prerender = require("prerender");
const prerender = require("prerender");
const cache = require('prerender-memory-cache');

//got from https://github.com/ball6847/docker-prerender who
// borrow from https://github.com/prerender/prerender/blob/master/server.js
var server = prerender({
const server = prerender({
chromeLocation: "/usr/lib/chromium/chrome",
chromeFlags: [
"--headless",
Expand All @@ -17,5 +19,6 @@ server.use(prerender.sendPrerenderHeader());
server.use(prerender.blockResources());
server.use(prerender.removeScriptTags());
server.use(prerender.httpHeaders());
server.use(cache);

server.start();

0 comments on commit 6459aae

Please sign in to comment.