Skip to content

Commit 4b6e3b5

Browse files
committed
First release
0 parents  commit 4b6e3b5

File tree

6 files changed

+267
-0
lines changed

6 files changed

+267
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#
2+
name: Create and publish a Docker image with tags
3+
4+
# Configures this workflow to run every time a change is pushed and have tags
5+
on:
6+
push:
7+
tags:
8+
- '*'
9+
10+
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
11+
env:
12+
REGISTRY: ghcr.io
13+
IMAGE_NAME: ${{ github.repository }}
14+
#IMAGE_NAME: ghcr.io/justcoded/plopjs
15+
16+
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
17+
jobs:
18+
build-and-push-image:
19+
runs-on: ubuntu-latest
20+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
21+
permissions:
22+
contents: read
23+
packages: write
24+
#
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
29+
- name: Log in to the Container registry
30+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
31+
with:
32+
registry: ${{ env.REGISTRY }}
33+
username: ${{ github.actor }}
34+
password: ${{ secrets.GITHUB_TOKEN }}
35+
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
36+
37+
38+
- name: Extract metadata (tags, labels) for Docker
39+
id: meta
40+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
41+
with:
42+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
43+
44+
45+
46+
- name: Set Versions
47+
uses: actions/github-script@v4
48+
id: set_version
49+
with:
50+
script: |
51+
const tag = context.ref.substring(10)
52+
const no_v = tag.replace('v', '')
53+
const dash_index = no_v.lastIndexOf('-')
54+
const no_dash = (dash_index > -1) ? no_v.substring(0, dash_index) : no_v
55+
core.setOutput('tag', tag)
56+
core.setOutput('no-v', no_v)
57+
core.setOutput('no-dash', no_dash)
58+
59+
- name: Build and Push
60+
uses: docker/build-push-action@v2
61+
with:
62+
context: .
63+
push: true
64+
tags: |
65+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
66+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}::${{steps.set_version.outputs.no-dash}}

Dockerfile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
FROM node:20-bullseye-slim
2+
3+
RUN apt-get update && apt-get install -y \
4+
ca-certificates \
5+
fonts-liberation \
6+
libasound2 \
7+
libatk-bridge2.0-0 \
8+
libatk1.0-0 \
9+
libc6 \
10+
libcairo2 \
11+
libcups2 \
12+
libdbus-1-3 \
13+
libexpat1 \
14+
libfontconfig1 \
15+
libgbm1 \
16+
libgcc1 \
17+
libglib2.0-0 \
18+
libgtk-3-0 \
19+
libnspr4 \
20+
libnss3 \
21+
libpango-1.0-0 \
22+
libpangocairo-1.0-0 \
23+
libstdc++6 \
24+
libx11-6 \
25+
libx11-xcb1 \
26+
libxcb1 \
27+
libxcomposite1 \
28+
libxcursor1 \
29+
libxdamage1 \
30+
libxext6 \
31+
libxfixes3 \
32+
libxi6 \
33+
libxrandr2 \
34+
libxrender1 \
35+
libxshmfence1 \
36+
libxtst6 \
37+
lsb-release \
38+
wget \
39+
xdg-utils \
40+
chromium \
41+
--no-install-recommends && rm -rf /var/lib/apt/lists/*
42+
43+
44+
WORKDIR /app
45+
RUN npm install prerender prerender-memory-cache
46+
47+
COPY server.js .
48+
49+
CMD ["node", "server.js"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 JustCoded
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Prerender Service (Dockerized)
2+
3+
This project provides a **Dockerized prerender service** based on `prerender` with an in-memory cache. It is designed to render JavaScript-heavy pages (e.g., for SEO or bots) using headless Chromium.
4+
5+
## 🚀 Features
6+
7+
- Headless Chromium rendering
8+
- In-memory caching (`prerender-memory-cache`)
9+
- Configurable cache TTL and size
10+
- Lightweight Docker image (`node:20-bullseye-slim`)
11+
- Ready to use with Docker Compose
12+
13+
14+
## 📦 Project Structure
15+
16+
├── Dockerfile
17+
18+
├── server.js
19+
20+
└── docker-compose.yml
21+
22+
## ⚙️ Configuration
23+
24+
### Environment Variables
25+
26+
| Variable | Default | Description |
27+
|------------------|--------|-----------------------------------|
28+
| `PORT` | `3000` | Port the service listens on |
29+
| `CACHE_MAXSIZE` | `1000` | Maximum number of cached entries |
30+
| `CACHE_TTL` | `86400`| Cache lifetime in seconds (1 day) |
31+
32+
---
33+
34+
## 🐳 Docker
35+
36+
### Build Image
37+
38+
```bash
39+
docker build -t prerender-service .
40+
```
41+
or check our repository
42+
43+
```
44+
path to docker image*****
45+
```
46+
47+
48+
## 🧩 Docker Compose
49+
50+
Example docker-compose.yml:
51+
52+
```
53+
services:
54+
webapp-prerender:
55+
build:
56+
context: .
57+
dockerfile: Dockerfile
58+
ports:
59+
- "3000:3000"
60+
shm_size: 512mb
61+
restart: unless-stopped
62+
environment:
63+
- PORT=3000
64+
```
65+
66+
or
67+
68+
```
69+
services:
70+
image: prerender-image:latest
71+
ports:
72+
- "3000:3000"
73+
shm_size: 512mb
74+
restart: unless-stopped
75+
environment:
76+
- PORT=3000
77+
```
78+
79+
80+
Run:
81+
82+
```bash
83+
docker-compose up -d
84+
```
85+
86+
### 🧠 How It Works
87+
The service runs a prerender server using headless Chromium.
88+
Incoming requests are rendered as fully loaded HTML pages.
89+
Responses are cached in memory using prerender-memory-cache.
90+
Cache settings are controlled via environment variables.
91+
92+
### 🔧 Chromium Notes
93+
Uses system-installed Chromium (/usr/bin/chromium)
94+
Required dependencies are installed in the Docker image
95+
--no-sandbox is enabled for compatibility inside containers
96+
97+
### 📈 Use Cases
98+
SEO for SPA (React, Vue, Angular)
99+
Social media previews (Open Graph rendering)
100+
Rendering pages for bots/crawlers
101+
102+
### 🛠 Tips
103+
Increase shm_size if Chromium crashes
104+
Tune CACHE_MAXSIZE based on memory limits
105+
Use a reverse proxy (e.g., Nginx) in production

docker-compose.example.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
services:
2+
3+
webapp-prerender:
4+
ports:
5+
- '3000:3000'
6+
build:
7+
context: .
8+
dockerfile: Dockerfile
9+
restart: unless-stopped
10+
shm_size: 512mb
11+
environment:
12+
- PORT=3000

server.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const prerender = require('prerender');
2+
process.env.CACHE_MAXSIZE = process.env.CACHE_MAXSIZE || 1000;
3+
process.env.CACHE_TTL = process.env.CACHE_TTL || 86400;
4+
5+
const server = prerender({
6+
chromeLocation: '/usr/bin/chromium',
7+
chromeFlags: ['--no-sandbox', '--headless', '--disable-gpu', '--remote-debugging-port=9222', '--hide-scrollbars']
8+
});
9+
10+
server.use(require('prerender-memory-cache'))
11+
12+
console.log(`Prerender start`);
13+
14+
server.start();

0 commit comments

Comments
 (0)