Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ jobs:

name: Docker (dockette/rendertron:${{ matrix.tag }})

continue-on-error: "${{ matrix.tag == 'tracer' }}"

steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 15
node-version: 20
- run: npm ci
- run: npm run lint
- run: npm run build
Expand All @@ -36,7 +36,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 15
node-version: 20
- run: npm ci
- run: npm run test
- run: npm run build
- run: npm run build
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

Ready-to-use image for SSR rendering based on headless Chrome, [a.k.a Rendertron by Google](https://github.com/GoogleChrome/rendertron).

> All credits belong to authors of GoogleChrome/rendertron.
> All credits belong to the authors of [GoogleChrome/rendertron](https://github.com/GoogleChrome/rendertron).

-----

[![Docker Stars](https://img.shields.io/docker/stars/dockette/rendertron.svg?style=flat)](https://hub.docker.com/r/dockette/rendertron/)
[![Docker Pulls](https://img.shields.io/docker/pulls/dockette/rendertron.svg?style=flat)](https://hub.docker.com/r/dockette/rendertron/)
> **Upstream status:** the [GoogleChrome/rendertron](https://github.com/GoogleChrome/rendertron) project was archived and the upstream README marks it as deprecated. The image here is kept for existing users and the demo screenshot; new projects should evaluate the alternative rendering strategies linked from the upstream README before adopting Rendertron.

## Discussion / Help
-----

[![Join the chat](https://img.shields.io/gitter/room/dockette/dockette.svg?style=flat-square)](https://gitter.im/dockette/dockette?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
<p align=center>
<a href="https://github.com/dockette/rendertron/actions"><img src="https://github.com/dockette/rendertron/actions/workflows/docker.yml/badge.svg" alt="GitHub Actions"></a>
<a href="https://hub.docker.com/r/dockette/rendertron"><img src="https://img.shields.io/docker/pulls/dockette/rendertron.svg" alt="Docker Hub pulls"></a>
<a href="https://github.com/sponsors/f3l1x"><img src="https://img.shields.io/badge/sponsor-GitHub%20Sponsors-ea4aaa" alt="GitHub Sponsors"></a>
<a href="https://github.com/orgs/dockette/discussions"><img src="https://img.shields.io/badge/support-discussions-6f42c1" alt="Support/Discussions"></a>
</p>

## Usage

Expand Down
18 changes: 9 additions & 9 deletions rendertron/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
FROM node:15-slim
FROM node:20-bookworm-slim

RUN apt update && apt dist-upgrade -y && \
apt install -y wget gnupg2 && \
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list && \
apt-get update && apt-get -y install google-chrome-stable libxss1
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium

RUN apt-get update && apt-get dist-upgrade -y && \
apt-get install -y --no-install-recommends chromium ca-certificates && \
rm -Rf /var/lib/apt/lists/*

ADD ./ /srv

RUN npm --prefix /srv install && \
RUN npm --prefix /srv ci && \
npm --prefix /srv run build && \
rm -Rf /tmp/* && \
rm -Rf /var/lib/apt/lists/*
rm -Rf /tmp/*

WORKDIR /srv

Expand Down
4 changes: 2 additions & 2 deletions rendertron/middleware/src/test/middleware-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import * as rendertron from '../middleware';
*/
async function listen(app: express.Application): Promise<string> {
return new Promise<string>((resolve: (url: string) => void) => {
const server = app.listen(/* random */ 0, 'localhost', () => {
resolve(`http://localhost:${(server.address() as net.AddressInfo).port}`);
const server = app.listen(/* random */ 0, '127.0.0.1', () => {
resolve(`http://127.0.0.1:${(server.address() as net.AddressInfo).port}`);
});
});
}
Expand Down
5 changes: 3 additions & 2 deletions rendertron/src/datastore-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
'use strict';

import Koa from 'koa';
import { OutgoingHttpHeaders } from 'http';
import { Config, ConfigManager } from './config';

import { Datastore } from '@google-cloud/datastore';
Expand Down Expand Up @@ -57,8 +58,8 @@ export class DatastoreCache {
async cacheContent(
// eslint-disable-next-line @typescript-eslint/ban-types
key: object,
headers: Record<string, string>,
payload: Buffer
headers: OutgoingHttpHeaders,
payload: Koa.Context['body']
) {
const now = new Date();
// query datastore to see if we are over the max number of allowed entries, and max entries isn't disabled with a value of -1 and remove over quota, removes oldest first
Expand Down
4 changes: 2 additions & 2 deletions rendertron/src/filesystem-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export class FilesystemCache {
ctx.set(response.header);
ctx.set('x-rendertron-cached', content.saved.toUTCString());
ctx.status = response.status;
let payload: string | { type?: string } = content.payload;
let payload: string | { type?: string; data?: number[] } = content.payload;
try {
payload = JSON.parse(content.payload);
} catch (e) {
Expand All @@ -254,7 +254,7 @@ export class FilesystemCache {
typeof payload === 'object' &&
payload.type === 'Buffer'
) {
ctx.body = Buffer.from(payload);
ctx.body = Buffer.from(payload.data || []);
} else {
ctx.body = payload;
}
Expand Down
5 changes: 3 additions & 2 deletions rendertron/src/memory-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
'use strict';

import Koa from 'koa';
import { OutgoingHttpHeaders } from 'http';
import { Config, ConfigManager } from './config';

type CacheEntry = {
Expand All @@ -40,8 +41,8 @@ export class MemoryCache {

cacheContent(
key: string,
headers: { [key: string]: string },
payload: Buffer
headers: OutgoingHttpHeaders,
payload: Koa.Context['body']
) {
// if the cache gets too big, we evict the least recently used entry (i.e. the first value in the map)
if (
Expand Down
9 changes: 7 additions & 2 deletions rendertron/src/rendertron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export class Rendertron {
private port = process.env.PORT || null;
private host = process.env.HOST || null;

private getQueryString(value: string | string[] | undefined) {
return Array.isArray(value) ? value[0] : value;
}

async createRenderer(config: Config) {
const browser = await puppeteer.launch({ args: config.puppeteerArgs });

Expand Down Expand Up @@ -153,7 +157,7 @@ export class Rendertron {
const serialized = await this.renderer.serialize(
url,
mobileVersion,
ctx.query.timezoneId
this.getQueryString(ctx.query.timezoneId)
);

for (const key in this.config.headers) {
Expand Down Expand Up @@ -192,7 +196,8 @@ export class Rendertron {
url,
mobileVersion,
dimensions,
ctx.query.timezoneId
undefined,
this.getQueryString(ctx.query.timezoneId)
);

for (const key in this.config.headers) {
Expand Down
37 changes: 6 additions & 31 deletions tracer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,52 +1,27 @@
FROM dockette/alpine:3.9
FROM php:7.4-cli-alpine

MAINTAINER Milan Sulc <sulcmil@gmail.com>
LABEL maintainer="Milan Sulc <sulcmil@gmail.com>"

ADD https://dl.bintray.com/php-alpine/key/php-alpine.rsa.pub /etc/apk/keys/php-alpine.rsa.pub
ADD .docker/php.ini /etc/php7/conf.d/999-tracer.ini
ADD .docker/php.ini /usr/local/etc/php/conf.d/999-tracer.ini

ENV TZ=Europe/Prague

RUN echo '@community http://nl.alpinelinux.org/alpine/edge/community' >> /etc/apk/repositories && \
echo "@php https://dl.bintray.com/php-alpine/v3.9/php-7.3" >> /etc/apk/repositories && \
# DEPENDENCIES #############################################################
apk update && \
apk upgrade && \
apk --no-cache add \
RUN apk --no-cache add \
bash \
git \
ca-certificates \
curl \
openssh \
tzdata \
tini && \
# PHP ######################################################################
apk --no-cache add \
php7@php \
php7-ctype@php \
php7-curl@php \
php7-iconv@php \
php7-intl@php \
php7-json@php \
php7-mbstring@php \
php7-openssl@php \
php7-session@php \
php7-phar@php \
php7-xml@php \
php7-zip@php \
php7-zlib@php && \
ln -s /usr/bin/php7 /usr/bin/php && \
# COMPOSER #################################################################
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer && \
composer global require "hirak/prestissimo:^0.3" && \
# CLEAN UP #################################################################
rm -rf /var/cache/apk/*

WORKDIR /srv
ADD ./ /srv

RUN mkdir -p /srv/var && \
composer install --no-suggest --prefer-dist
composer install --no-dev --no-interaction --prefer-dist

ENTRYPOINT ["/sbin/tini", "--"]
CMD ["/usr/bin/php", "/srv/bin/tracer.php"]
CMD ["/usr/local/bin/php", "/srv/bin/tracer.php"]
Loading