Skip to content

Commit a1bf42a

Browse files
fxikf3l1x
authored andcommitted
Fix Rendertron CI builds
1 parent 083fbaa commit a1bf42a

9 files changed

Lines changed: 35 additions & 55 deletions

File tree

.github/workflows/docker.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ jobs:
2626

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

29-
continue-on-error: "${{ matrix.tag == 'tracer' }}"
30-
3129
steps:
3230
- name: Checkout
3331
uses: actions/checkout@v4

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- uses: actions/checkout@v4
2121
- uses: actions/setup-node@v4
2222
with:
23-
node-version: 15
23+
node-version: 20
2424
- run: npm ci
2525
- run: npm run lint
2626
- run: npm run build
@@ -36,7 +36,7 @@ jobs:
3636
- uses: actions/checkout@v4
3737
- uses: actions/setup-node@v4
3838
with:
39-
node-version: 15
39+
node-version: 20
4040
- run: npm ci
4141
- run: npm run test
42-
- run: npm run build
42+
- run: npm run build

rendertron/Dockerfile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
FROM node:15-slim
1+
FROM node:20-bookworm-slim
22

3-
RUN apt update && apt dist-upgrade -y && \
4-
apt install -y wget gnupg2 && \
5-
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
6-
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list && \
7-
apt-get update && apt-get -y install google-chrome-stable libxss1
3+
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
4+
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
5+
6+
RUN apt-get update && apt-get dist-upgrade -y && \
7+
apt-get install -y --no-install-recommends chromium ca-certificates && \
8+
rm -Rf /var/lib/apt/lists/*
89

910
ADD ./ /srv
1011

11-
RUN npm --prefix /srv install && \
12+
RUN npm --prefix /srv ci && \
1213
npm --prefix /srv run build && \
13-
rm -Rf /tmp/* && \
14-
rm -Rf /var/lib/apt/lists/*
14+
rm -Rf /tmp/*
1515

1616
WORKDIR /srv
1717

rendertron/middleware/src/test/middleware-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import * as rendertron from '../middleware';
2626
*/
2727
async function listen(app: express.Application): Promise<string> {
2828
return new Promise<string>((resolve: (url: string) => void) => {
29-
const server = app.listen(/* random */ 0, 'localhost', () => {
30-
resolve(`http://localhost:${(server.address() as net.AddressInfo).port}`);
29+
const server = app.listen(/* random */ 0, '127.0.0.1', () => {
30+
resolve(`http://127.0.0.1:${(server.address() as net.AddressInfo).port}`);
3131
});
3232
});
3333
}

rendertron/src/datastore-cache.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
'use strict';
2121

2222
import Koa from 'koa';
23+
import { OutgoingHttpHeaders } from 'http';
2324
import { Config, ConfigManager } from './config';
2425

2526
import { Datastore } from '@google-cloud/datastore';
@@ -57,8 +58,8 @@ export class DatastoreCache {
5758
async cacheContent(
5859
// eslint-disable-next-line @typescript-eslint/ban-types
5960
key: object,
60-
headers: Record<string, string>,
61-
payload: Buffer
61+
headers: OutgoingHttpHeaders,
62+
payload: Koa.Context['body']
6263
) {
6364
const now = new Date();
6465
// 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

rendertron/src/filesystem-cache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ export class FilesystemCache {
242242
ctx.set(response.header);
243243
ctx.set('x-rendertron-cached', content.saved.toUTCString());
244244
ctx.status = response.status;
245-
let payload: string | { type?: string } = content.payload;
245+
let payload: string | { type?: string; data?: number[] } = content.payload;
246246
try {
247247
payload = JSON.parse(content.payload);
248248
} catch (e) {
@@ -254,7 +254,7 @@ export class FilesystemCache {
254254
typeof payload === 'object' &&
255255
payload.type === 'Buffer'
256256
) {
257-
ctx.body = Buffer.from(payload);
257+
ctx.body = Buffer.from(payload.data || []);
258258
} else {
259259
ctx.body = payload;
260260
}

rendertron/src/memory-cache.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
'use strict';
2121

2222
import Koa from 'koa';
23+
import { OutgoingHttpHeaders } from 'http';
2324
import { Config, ConfigManager } from './config';
2425

2526
type CacheEntry = {
@@ -40,8 +41,8 @@ export class MemoryCache {
4041

4142
cacheContent(
4243
key: string,
43-
headers: { [key: string]: string },
44-
payload: Buffer
44+
headers: OutgoingHttpHeaders,
45+
payload: Koa.Context['body']
4546
) {
4647
// if the cache gets too big, we evict the least recently used entry (i.e. the first value in the map)
4748
if (

rendertron/src/rendertron.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export class Rendertron {
2222
private port = process.env.PORT || null;
2323
private host = process.env.HOST || null;
2424

25+
private getQueryString(value: string | string[] | undefined) {
26+
return Array.isArray(value) ? value[0] : value;
27+
}
28+
2529
async createRenderer(config: Config) {
2630
const browser = await puppeteer.launch({ args: config.puppeteerArgs });
2731

@@ -153,7 +157,7 @@ export class Rendertron {
153157
const serialized = await this.renderer.serialize(
154158
url,
155159
mobileVersion,
156-
ctx.query.timezoneId
160+
this.getQueryString(ctx.query.timezoneId)
157161
);
158162

159163
for (const key in this.config.headers) {
@@ -192,7 +196,8 @@ export class Rendertron {
192196
url,
193197
mobileVersion,
194198
dimensions,
195-
ctx.query.timezoneId
199+
undefined,
200+
this.getQueryString(ctx.query.timezoneId)
196201
);
197202

198203
for (const key in this.config.headers) {

tracer/Dockerfile

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,27 @@
1-
FROM dockette/alpine:3.9
1+
FROM php:7.4-cli-alpine
22

3-
MAINTAINER Milan Sulc <sulcmil@gmail.com>
3+
LABEL maintainer="Milan Sulc <sulcmil@gmail.com>"
44

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

87
ENV TZ=Europe/Prague
98

10-
RUN echo '@community http://nl.alpinelinux.org/alpine/edge/community' >> /etc/apk/repositories && \
11-
echo "@php https://dl.bintray.com/php-alpine/v3.9/php-7.3" >> /etc/apk/repositories && \
12-
# DEPENDENCIES #############################################################
13-
apk update && \
14-
apk upgrade && \
15-
apk --no-cache add \
9+
RUN apk --no-cache add \
1610
bash \
1711
git \
1812
ca-certificates \
1913
curl \
2014
openssh \
2115
tzdata \
2216
tini && \
23-
# PHP ######################################################################
24-
apk --no-cache add \
25-
php7@php \
26-
php7-ctype@php \
27-
php7-curl@php \
28-
php7-iconv@php \
29-
php7-intl@php \
30-
php7-json@php \
31-
php7-mbstring@php \
32-
php7-openssl@php \
33-
php7-session@php \
34-
php7-phar@php \
35-
php7-xml@php \
36-
php7-zip@php \
37-
php7-zlib@php && \
38-
ln -s /usr/bin/php7 /usr/bin/php && \
39-
# COMPOSER #################################################################
4017
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer && \
41-
composer global require "hirak/prestissimo:^0.3" && \
42-
# CLEAN UP #################################################################
4318
rm -rf /var/cache/apk/*
4419

4520
WORKDIR /srv
4621
ADD ./ /srv
4722

4823
RUN mkdir -p /srv/var && \
49-
composer install --no-suggest --prefer-dist
24+
composer install --no-dev --no-interaction --prefer-dist
5025

5126
ENTRYPOINT ["/sbin/tini", "--"]
52-
CMD ["/usr/bin/php", "/srv/bin/tracer.php"]
27+
CMD ["/usr/local/bin/php", "/srv/bin/tracer.php"]

0 commit comments

Comments
 (0)