Skip to content

Commit e35d402

Browse files
authored
Upgrade Node to LTS (12) (#57)
Upgrades Node from version 10 to LTS, version 12. Makefile fixes. Cleanup of package.json and moved some dependencies to dev dependencies. Added tslint, prettier and precommit hook. Fixed tslint issues.
1 parent 9ec556c commit e35d402

File tree

14 files changed

+1214
-436
lines changed

14 files changed

+1214
-436
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ aliases:
1313
defaults: &defaults
1414
working_directory: ~/grafana-image-renderer
1515
docker:
16-
- image: circleci/node:10.15.3-stretch
16+
- image: circleci/node:12.13.1-stretch
1717

1818
jobs:
1919
build:

.prettierignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.git
2+
.github
3+
artifacts
4+
build
5+
dist
6+
docker
7+
docs
8+
node_modules
9+
proto
10+
scripts

.prettierrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"trailingComma": "es5",
3+
"singleQuote": true,
4+
"printWidth": 150
5+
}

Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:10-alpine AS base
1+
FROM node:12-alpine AS base
22

33
ENV CHROME_BIN="/usr/bin/chromium-browser"
44
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
@@ -10,8 +10,7 @@ RUN \
1010
echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories && \
1111
echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories && \
1212
apk --no-cache upgrade && \
13-
apk add --no-cache udev ttf-opensans chromium ca-certificates dumb-init nghttp2 openldap curl && \
14-
apk del nghttp2 openldap curl && \
13+
apk add --no-cache udev ttf-opensans chromium ca-certificates dumb-init && \
1514
rm -rf /tmp/*
1615

1716
FROM base as build

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.PHONY: all clean deps build clean_package package archive build_package
2+
13
ARCH = darwin-x64-unknown
24
SKIP_CHROMIUM =
35
OUT =
@@ -9,12 +11,12 @@ clean:
911

1012
deps: node_modules
1113

12-
node_modules: package.json yarn.lock
14+
node_modules: package.json yarn.lock ## Install node modules.
1315
@echo "install frontend dependencies"
1416
yarn install --pure-lockfile --no-progress
1517

1618
build:
17-
./node_modules/.bin/tsc
19+
yarn build
1820

1921
clean_package:
2022
./scripts/clean_target.sh ${ARCH} ${OUT}

package.json

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,62 @@
11
{
22
"name": "renderer",
33
"version": "1.0.0",
4-
"description": "",
5-
"main": "index.js",
4+
"author": "Grafana Labs",
5+
"license": "Apache-2.0",
6+
"private": true,
7+
"repository": {
8+
"type": "git",
9+
"url": "http://github.com/grafana/grafana-image-renderer.git"
10+
},
611
"scripts": {
7-
"build": "yarn run tsc",
8-
"start": "node build/app.js",
9-
"dev": "yarn run tsc-watch --onSuccess \"node build/app.js server --port=3050\""
12+
"tslint": "tslint -c tslint.json --project tsconfig.json",
13+
"typecheck": "tsc --noEmit",
14+
"prettier:check": "prettier --list-different \"**/*.ts\"",
15+
"prettier:write": "prettier --list-different \"**/*.ts\" --write",
16+
"precommit": "npm run tslint & npm run typecheck",
17+
"watch": "tsc-watch --onSuccess \"node build/app.js server --port=8080\"",
18+
"build": "tsc",
19+
"start": "node build/app.js --port=8080"
1020
},
11-
"author": "",
12-
"license": "ISC",
1321
"dependencies": {
14-
"@types/express": "^4.11.1",
15-
"@types/node": "^10.0.9",
22+
"@grpc/proto-loader": "^0.5.3",
1623
"boom": "^7.2.0",
1724
"express": "^4.16.3",
1825
"google-protobuf": "3.5.0",
19-
"grpc": "^1.11.3",
26+
"grpc": "^1.24.2",
2027
"minimist": "^1.2.0",
2128
"morgan": "^1.9.0",
2229
"mz": "^2.7.0",
2330
"puppeteer": "^1.7.0",
24-
"typescript": "^2.8.3",
2531
"unique-filename": "^1.1.0"
2632
},
2733
"devDependencies": {
28-
"husky": "^0.14.3",
29-
"lint-staged": "^6.0.0",
34+
"@types/express": "^4.11.1",
35+
"@types/node": "^10.0.9",
36+
"husky": "^3.1.0",
37+
"lint-staged": "^9.5.0",
3038
"pkg": "4.3.8",
31-
"prettier": "1.9.2",
32-
"tsc-watch": "^1.0.21"
39+
"prettier": "^1.19.1",
40+
"tsc-watch": "^1.0.21",
41+
"tslint": "^5.20.1",
42+
"typescript": "^2.8.3"
3343
},
34-
"resolutions": {
35-
"set-value": "2.0.1"
44+
"husky": {
45+
"hooks": {
46+
"pre-commit": "lint-staged && npm run precommit"
47+
}
3648
},
3749
"lint-staged": {
38-
"*.{ts,tsx}": [
50+
"*.ts": [
3951
"prettier --write",
4052
"git add"
41-
],
42-
"*.scss": [
43-
"prettier --write",
44-
"git add"
45-
],
46-
"*pkg/**/*.go": [
47-
"gofmt -w -s",
48-
"git add"
4953
]
5054
},
51-
"prettier": {
52-
"trailingComma": "es5",
53-
"singleQuote": true,
54-
"printWidth": 120
55-
},
5655
"pkg": {
5756
"assets": "proto/*"
5857
},
59-
"bin": "build/app.js"
58+
"bin": "build/app.js",
59+
"engines": {
60+
"node": ">=12 <13"
61+
}
6062
}

proto/health.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ message HealthCheckResponse {
1717

1818
service Health {
1919
rpc Check(HealthCheckRequest) returns (HealthCheckResponse);
20-
}
20+
}

src/browser.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ export class Browser {
5353
}
5454

5555
validateOptions(options) {
56-
options.width = parseInt(options.width) || 1000;
57-
options.height = parseInt(options.height) || 500;
58-
options.timeout = parseInt(options.timeout) || 30;
56+
options.width = parseInt(options.width, 10) || 1000;
57+
options.height = parseInt(options.height, 10) || 500;
58+
options.timeout = parseInt(options.timeout, 10) || 30;
5959

6060
if (options.width > 3000 || options.width < 10) {
6161
options.width = 2500;
@@ -77,7 +77,7 @@ export class Browser {
7777
// set env timezone
7878
env.TZ = options.timezone || process.env.TZ;
7979

80-
let launcherOptions: any = {
80+
const launcherOptions: any = {
8181
env: env,
8282
ignoreHTTPSErrors: this.ignoreHTTPSErrors,
8383
args: ['--no-sandbox'],
@@ -108,9 +108,8 @@ export class Browser {
108108
// wait for all panels to render
109109
await page.waitForFunction(
110110
() => {
111-
const panelCount =
112-
document.querySelectorAll('.panel').length || document.querySelectorAll('.panel-container').length;
113-
return (<any>window).panelsRendered >= panelCount;
111+
const panelCount = document.querySelectorAll('.panel').length || document.querySelectorAll('.panel-container').length;
112+
return (window as any).panelsRendered >= panelCount;
114113
},
115114
{
116115
timeout: options.timeout * 1000,

src/exit.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function registerExitCleanUp(fn) {
99

1010
export class ExitManager {
1111
constructor(private log: Logger) {
12-
process.stdin.resume();//so the program will not close instantly
12+
process.stdin.resume(); //so the program will not close instantly
1313

1414
//do something when app is closing
1515
process.on('exit', this.exitHandler.bind(this));
@@ -26,11 +26,11 @@ export class ExitManager {
2626
}
2727

2828
exitHandler(options, err) {
29-
for (let fn of cleanUpHandlers) {
29+
for (const fn of cleanUpHandlers) {
3030
try {
3131
fn();
3232
} catch (err) {
33-
this.log.info("Failed to call cleanup function " + err);
33+
this.log.info('Failed to call cleanup function ' + err);
3434
}
3535
}
3636
if (err) {
@@ -39,5 +39,3 @@ export class ExitManager {
3939
process.exit();
4040
}
4141
}
42-
43-

src/grpc-plugin.ts

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,43 @@
11
import * as grpc from 'grpc';
2+
import * as protoLoader from '@grpc/proto-loader';
23
import { Logger } from './logger';
34
import { Browser } from './browser';
45

56
const SERVER_ADDRESS = '127.0.0.1:50059';
67
const RENDERER_PROTO_PATH = __dirname + '/../proto/renderer.proto';
7-
const GRPC_HEALTH_PROTO_PATH = __dirname + '/../proto/health.proto';
8+
const HEALTH_PROTO_PATH = __dirname + '/../proto/health.proto';
89

9-
export const RENDERER_PROTO = grpc.load(RENDERER_PROTO_PATH).models;
10-
export const GRPC_HEALTH_PROTO = grpc.load(GRPC_HEALTH_PROTO_PATH).grpc.health.v1;
10+
export const renderPackageDef = protoLoader.loadSync(RENDERER_PROTO_PATH, {
11+
keepCase: true,
12+
longs: String,
13+
enums: String,
14+
defaults: true,
15+
oneofs: true,
16+
});
17+
18+
export const healthPackageDef = protoLoader.loadSync(HEALTH_PROTO_PATH, {
19+
keepCase: true,
20+
longs: String,
21+
enums: String,
22+
defaults: true,
23+
oneofs: true,
24+
});
25+
26+
export const rendererProtoDescriptor = grpc.loadPackageDefinition(renderPackageDef);
27+
export const healthProtoDescriptor = grpc.loadPackageDefinition(healthPackageDef);
1128

1229
export class GrpcPlugin {
1330
constructor(private log: Logger, private browser: Browser) {}
1431

1532
start() {
16-
var server = new grpc.Server();
33+
const server = new grpc.Server();
1734

18-
server.addService(GRPC_HEALTH_PROTO.Health.service, {
35+
const grpcHealthV1: any = healthProtoDescriptor['grpc']['health']['v1'];
36+
server.addService(grpcHealthV1.Health.service, {
1937
check: this.check.bind(this),
2038
});
21-
server.addService(RENDERER_PROTO.Renderer.service, {
39+
const models: any = rendererProtoDescriptor.models;
40+
server.addService(models.Renderer.service, {
2241
render: this.render.bind(this),
2342
});
2443

@@ -28,13 +47,7 @@ export class GrpcPlugin {
2847
console.log(`1|1|tcp|${SERVER_ADDRESS}|grpc`);
2948

3049
if (this.browser.chromeBin) {
31-
this.log.info(
32-
'Renderer plugin started',
33-
'chromeBin',
34-
this.browser.chromeBin,
35-
'ignoreHTTPSErrors',
36-
this.browser.ignoreHTTPSErrors
37-
);
50+
this.log.info('Renderer plugin started', 'chromeBin', this.browser.chromeBin, 'ignoreHTTPSErrors', this.browser.ignoreHTTPSErrors);
3851
} else {
3952
this.log.info('Renderer plugin started', 'ignoreHttpsErrors', this.browser.ignoreHTTPSErrors);
4053
}
@@ -45,9 +58,8 @@ export class GrpcPlugin {
4558
}
4659

4760
async render(call, callback) {
48-
let req = call.request;
49-
50-
let options = {
61+
const req = call.request;
62+
const options = {
5163
url: req.url,
5264
width: req.width,
5365
height: req.height,
@@ -61,7 +73,7 @@ export class GrpcPlugin {
6173

6274
try {
6375
this.log.debug('Render request received', 'url', options.url);
64-
let result = await this.browser.render(options);
76+
const result = await this.browser.render(options);
6577
callback(null, { error: '' });
6678
} catch (err) {
6779
this.log.error('Render request failed', 'url', options.url, 'error', err);

0 commit comments

Comments
 (0)