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
3 changes: 3 additions & 0 deletions .github/scripts/chmod note.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
From https://github.community/t/action-showing-permission-denied/134957

git update-index --chmod=+x ./.github/scripts/<xxx>.sh
4 changes: 4 additions & 0 deletions .github/scripts/install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Invoke-WebRequest "http://ftp.gnome.org/pub/GNOME/binaries/win64/gtk+/2.22/gtk+-bundle_2.22.1-20101229_win64.zip" -OutFile "gtk.zip"
Expand-Archive gtk.zip -DestinationPath "C:\GTK"
Invoke-WebRequest "https://downloads.sourceforge.net/project/libjpeg-turbo/2.0.4/libjpeg-turbo-2.0.4-vc64.exe" -OutFile "libjpeg.exe" -UserAgent NativeHost
.\libjpeg.exe /S
1 change: 1 addition & 0 deletions .github/scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sudo apt-get install build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev
22 changes: 11 additions & 11 deletions scripts/publish.sh → .github/scripts/publish.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/bash

packageName=$(node -p "require('./package.json').name")
packageVersion=$(node -p "require('./package.json').version")
publishVersion=$(npm view "$packageName" version)
if [ "$packageVersion" != "$publishVersion" ]
then
npm config set //registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN
npm publish
else
echo "Existing version $packageVersion for $packageName is already published...skipping"
#!/bin/bash
packageName=$(node -p "require('./package.json').name")
packageVersion=$(node -p "require('./package.json').version")
publishVersion=$(npm view "$packageName" version)
if [ "$packageVersion" != "$publishVersion" ]
then
npm config set //registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN
npm publish
else
echo "Existing version $packageVersion for $packageName is already published...skipping"
fi
28 changes: 20 additions & 8 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,28 @@ on:

jobs:
build-and-test:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
node-version: ['10.x', '12.x', '14.x', '16.x']
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Install Cairo dependencies
run: |
Invoke-WebRequest "http://ftp.gnome.org/pub/GNOME/binaries/win64/gtk+/2.22/gtk+-bundle_2.22.1-20101229_win64.zip" -OutFile "gtk.zip"
Expand-Archive gtk.zip -DestinationPath "C:\GTK"
Invoke-WebRequest "https://downloads.sourceforge.net/project/libjpeg-turbo/2.0.4/libjpeg-turbo-2.0.4-vc64.exe" -OutFile "libjpeg.exe" -UserAgent NativeHost
.\libjpeg.exe /S
- name: Install Cairo dependencies (Windows)
if: matrix.os == 'windows-latest'
shell: powershell
run: ./.github/scripts/install.ps1
- name: Install Cairo dependencies (Linux)
if: matrix.os == 'ubuntu-latest'
shell: bash
run: ./.github/scripts/install.sh
- name: Add msbuild to PATH
if: matrix.os == 'windows-latest'
uses: microsoft/setup-msbuild@v1.1
with:
vs-version: '15.0'
Expand All @@ -53,6 +58,13 @@ jobs:
# with:
# name: Node v${{ matrix.node-version }}
# path: '*.tgz'
- name: 'Upload Test Data Artifact'
if: failure()
uses: actions/upload-artifact@v3
with:
name: test-data
path: ./testData/
retention-days: 5
publish:
if: github.ref == 'refs/heads/master'
needs: build-and-test
Expand All @@ -74,7 +86,7 @@ jobs:
run: npm run-script package-size
- name: Publish
shell: bash
run: ./scripts/publish.sh
run: ./.github/scripts/publish.sh
env:
CI: true
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
111 changes: 64 additions & 47 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,64 @@
version: "3"

services:
base:
image: chartjs-node-canvas-base
build:
context: .
dockerfile: docker/base/Dockerfile
container_name: chartjs-node-canvas-base
build:
image: chartjs-node-canvas-build
depends_on:
- base
build:
context: .
dockerfile: docker/build/Dockerfile
container_name: chartjs-node-canvas-build
test:
image: chartjs-node-canvas-build
container_name: chartjs-node-canvas-test
depends_on:
- build
environment:
- NODE_ENV=test
- FONTCONFIG_PATH=/etc/fonts
command: npm run test
production:
image: chartjs-node-canvas
depends_on:
- test
build:
context: .
dockerfile: docker/production/Dockerfile
container_name: chartjs-node-canvas
environment:
- NODE_ENV=production

#<< Docker Commands >>

# Build Images
#docker-compose build

# Run Containers
#docker-compose up

# Run Tests specifically
#docker-compose up test
version: "3"

services:
base-slim:
image: chartjs-node-canvas-base-slim
build:
context: .
dockerfile: docker/slim/base.Dockerfile
container_name: chartjs-node-canvas-base-slim
build-slim:
image: chartjs-node-canvas-build-slim
depends_on:
- base-slim
build:
context: .
dockerfile: docker/slim/build.Dockerfile
container_name: chartjs-node-canvas-build-slim
test-slim:
image: chartjs-node-canvas-build-slim
container_name: chartjs-node-canvas-test-slim
volumes:
- ./testData:/usr/server/testData
depends_on:
- build-slim
environment:
- NODE_ENV=test
- FONTCONFIG_PATH=/etc/fonts
command: npm run test
production-slim:
image: chartjs-node-canvas-slim
depends_on:
- test-slim
build:
context: .
dockerfile: docker/slim/production.Dockerfile
container_name: chartjs-node-canvas-slim
environment:
- NODE_ENV=production

base-ubuntu:
image: chartjs-node-canvas-base-ubuntu
build:
context: .
dockerfile: docker/ubuntu/base.Dockerfile
container_name: chartjs-node-canvas-base-ubuntu
build-ubuntu:
image: chartjs-node-canvas-build-ubuntu
depends_on:
- base-ubuntu
build:
context: .
dockerfile: docker/ubuntu/build.Dockerfile
container_name: chartjs-node-canvas-build-ubuntu
test-ubuntu:
image: chartjs-node-canvas-build-ubuntu
container_name: chartjs-node-canvas-test-ubuntu
volumes:
- ./testData:/usr/server/testData
depends_on:
- build-ubuntu
environment:
- NODE_ENV=test
- FONTCONFIG_PATH=/etc/fonts
command: npm run test
11 changes: 11 additions & 0 deletions docker.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#<< Docker Commands >>

# Build Images
docker-compose build

# Run Containers
docker-compose up

# Run Tests specifically
docker-compose up test-slim
docker-compose up test-ubuntu
2 changes: 1 addition & 1 deletion docker/base/Dockerfile → docker/slim/base.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:14.18.0-slim
FROM node:16.15.0-slim

LABEL maintainer = "sean.m.sobey@gmail.com"

Expand Down
24 changes: 12 additions & 12 deletions docker/build/Dockerfile → docker/slim/build.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
FROM chartjs-node-canvas-base

LABEL maintainer = "sean.m.sobey@gmail.com"

WORKDIR /usr/server

RUN npm ci --no-color

COPY . .

RUN npm run build

FROM chartjs-node-canvas-base-slim
LABEL maintainer = "sean.m.sobey@gmail.com"
WORKDIR /usr/server
RUN npm ci --no-color
COPY . .
RUN npm run build
CMD ["/bin/bash", "-c", "echo base image complete"]
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM chartjs-node-canvas-base

LABEL maintainer = "sean.m.sobey@gmail.com"

WORKDIR /usr/server

COPY --from=chartjs-node-canvas-build /usr/server/dist/ ./dist/

FROM chartjs-node-canvas-base-slim
LABEL maintainer = "sean.m.sobey@gmail.com"
WORKDIR /usr/server
COPY --from=chartjs-node-canvas-build-slim /usr/server/dist/ ./dist/
CMD ["/bin/bash", "-c", "echo production image complete"]
37 changes: 37 additions & 0 deletions docker/ubuntu/base.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM ubuntu:22.10

LABEL maintainer = "sean.m.sobey@gmail.com"

RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev

# TODO: move into above...
RUN apt-get install --yes curl

# nvm environment variables
ENV NVM_DIR /usr/local/nvm
#TODO read from .nvmrc
ENV NODE_VERSION 16.13.0

# install nvm
# https://github.com/creationix/nvm#install-script
RUN mkdir -p $NVM_DIR \
&& curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

# install node and npm
RUN . ~/.bashrc $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default

# add node and npm to path so the commands are available
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH

WORKDIR /usr/server

COPY package.json package-lock.json ./

RUN npm ci --production --no-color

CMD ["/bin/bash", "-c", "echo base image complete"]
13 changes: 13 additions & 0 deletions docker/ubuntu/build.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM chartjs-node-canvas-base-ubuntu

LABEL maintainer = "sean.m.sobey@gmail.com"

WORKDIR /usr/server

RUN npm ci --no-color

COPY . .

RUN npm run build

CMD ["/bin/bash", "-c", "echo base image complete"]
32 changes: 19 additions & 13 deletions src/index.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AssertionError } from 'assert';
import { promises as fs } from 'fs';
import { platform, EOL } from 'os';
import { join } from 'path';
import os, { platform, EOL } from 'os';
import path, { join } from 'path';
import { Readable } from 'stream';
import { describe, it } from 'mocha';
import { Stream } from 'stream';
Expand Down Expand Up @@ -81,7 +81,7 @@ describe(ChartJSNodeCanvas.name, () => {
const extension = '.txt';
const fileName = 'render-to-data-URL';
const fileNameWithExtension = fileName + extension;
const expectedDataPath = join(process.cwd(), 'testData', platform(), fileName + extension);
const expectedDataPath = join(getTestDataPath(), fileName + extension);
const expected = await fs.readFile(expectedDataPath, 'utf8');
// const result = actual === expected;
const compareData = await compareImages(actual, expected, { output: { useCrossOrigin: false } });
Expand Down Expand Up @@ -374,10 +374,16 @@ describe(ChartJSNodeCanvas.name, () => {
}
*/

function getTestDataPath(): string {

const paths = [process.cwd(), 'testData', platform()];
return path.join(...paths);
}

async function assertImage(actual: Buffer, fileName: string): Promise<void> {
const extension = '.png';
const fileNameWithExtension = fileName + extension;
const testDataPath = join(process.cwd(), 'testData', platform(), fileNameWithExtension);
const testDataPath = join(getTestDataPath(), fileNameWithExtension);
const exists = await pathExists(testDataPath);
if (!exists) {
console.error(`Warning: expected image path does not exist!, creating '${testDataPath}'`);
Expand Down Expand Up @@ -416,16 +422,16 @@ describe(ChartJSNodeCanvas.name, () => {
// resemblejs/compareImages
//function compareImages(image1: string | Buffer, image2: string | Buffer, options?: ResembleSingleCallbackComparisonOptions): Promise<ResembleSingleCallbackComparisonResult> {
function compareImages(image1: string | Buffer, image2: string | Buffer, options?: any): Promise<any> {
return new Promise((resolve, reject) => {
//resemble.compare(image1, image2, options || {}, (err, data) => {
resemble.compare(image1, image2, options || {}, (err: any, data: any) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
return new Promise((resolve, reject) => {
//resemble.compare(image1, image2, options || {}, (err, data) => {
resemble.compare(image1, image2, options || {}, (err: any, data: any) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}

function streamToBuffer(stream: Readable): Promise<Buffer> {
Expand Down
Binary file added testData/linux/background-color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified testData/linux/chartjs-plugin-annotation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified testData/linux/chartjs-plugin-datalabels.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified testData/linux/font.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added testData/linux/no-background-color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added testData/linux/render-to-buffer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions testData/linux/render-to-data-URL.txt

Large diffs are not rendered by default.

Binary file added testData/linux/render-to-stream.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.