Skip to content

Commit 43e8b9f

Browse files
authored
Merge pull request #21 from charoitel/dev
Maintenance for [email protected]
2 parents 7af8874 + 3fce629 commit 43e8b9f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1896
-15
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
.idea/
2+
docs/.jekyll-cache
3+
docs/_site
4+
docs/Gemfile.lock
15
nodejs/node_modules
26
nodejs/node*/node_modules
37
nodejs/package*.json

README.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,34 @@
22

33
![GitHub](https://img.shields.io/github/license/charoitel/lambda-layer-canvas-nodejs)
44

5-
[lambda-layer-canvas-nodejs](https://github.com/charoitel/lambda-layer-canvas-nodejs) published on [AWS Serverless Application Repository](https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:990551184979:applications~lambda-layer-canvas-nodejs) packages node-canvas and its dependencies as AWS Lambda Layer.
5+
Canvas Layer for AWS Lambda is published and available on [AWS Serverless Application Repository](https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:990551184979:applications~lambda-layer-canvas-nodejs), and GitHub at [charoitel/lambda-layer-canvas-nodejs](https://github.com/charoitel/lambda-layer-canvas-nodejs). The layer aims to provide a Cairo backed Mozilla Web Canvas API implementation layer for AWS Lambda, powered by [node-canvas](https://github.com/Automattic/node-canvas).
66

77
## About node-canvas
88

9-
[node-canvas](https://github.com/Automattic/node-canvas) is a Cairo backed Canvas implementation for Node.js. It implements the [Mozilla Web Canvas API](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API) as closely as possible. For the current API compliance, please check [Compatibility Status](https://github.com/Automattic/node-canvas/wiki/Compatibility-Status).
9+
[node-canvas](https://github.com/Automattic/node-canvas) is a Cairo backed Canvas implementation for Node.js. It implements the [Mozilla Web Canvas API](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API) as closely as possible. For the latest API compliance, you may check [Compatibility Status](https://github.com/Automattic/node-canvas/wiki/Compatibility-Status).
1010

1111
## How this layer is built?
1212

13-
The Lambda Layer is built from source of node-canvas npm package on [amazonlinux](https://hub.docker.com/_/amazonlinux) dev container instance, with following native dependencies installed. Please check ``` build-layer.sh ``` for details.
13+
The layer is built from source of node-canvas npm package on [amazonlinux](https://hub.docker.com/_/amazonlinux) dev container instance, with following native dependencies installed. You may check the build layer script, ``` build-layer.sh ```, which is available in repository, for details.
1414

1515
```bash
1616
gcc-c++ cairo-devel pango-devel libjpeg-turbo-devel giflib-devel librsvg2-devel pango-devel bzip2-devel jq python3
1717
```
1818

19-
Since AWS Lambda is a secure and isolated runtime and execution environment, this layer aims to target AWS Lambda compatible build. As there are canvas libraries and frameworks relying on node-canvas running on Node.js runtime, this layer also tries to include and support these libraries and frameworks.
19+
Since AWS Lambda is a secure and isolated runtime and execution environment, the layer aims to target AWS Lambda compatible and native build. As there are canvas libraries and frameworks relying on node-canvas running on Node.js runtime, this layer may also try to include and support those libraries and frameworks. Currently, following libraries and frameworks are included when building and packaging the layer:
2020

21-
### Fabric.js support
22-
23-
[Fabric.js](https://github.com/fabricjs/fabric.js) is a framework that makes it easy to work with HTML5 canvas element. It is an interactive object model on top of canvas element. It is also an SVG-to-canvas (and canvas-to-SVG) parser.
21+
- [Chart.js](#chartjs-support)
22+
- [Fabric.js](#fabricjs-support)
23+
- [Konva](#konva-support)
2424

25-
### Konva support
25+
### Chart.js support
2626

27-
[Konva](https://github.com/konvajs/konva) is a framework that enables high performance animations, transitions, node nesting, layering, filtering, caching, event handling for desktop and mobile applications, and much more.
27+
[Chart.js](https://github.com/chartjs/chart.js) provides a set of frequently used chart types, plugins, and customization options. In addition to a reasonable set of built-in chart types, there are also community-maintained chart types.
2828

29-
> **Note:** From Canvas Layer v2.9.3 release, since konva-node package is deprecated, konva package is used directly through build script.
29+
### Fabric.js support
3030

31-
## Getting started
31+
[Fabric.js](https://github.com/fabricjs/fabric.js) provides a missing and interactive object model for canvas, as well as an SVG parser, layer of interactivity, and a whole suite of other indispensable tools.
3232

33-
To get started, please visit https://github.com/charoitel/lambda-layer-canvas-nodejs/wiki/Getting-Started
33+
### Konva support
3434

35-
Made with ❤️ by Charoite Lee and contributors. Available on the [AWS Serverless Application Repository](https://aws.amazon.com/serverless)
35+
[Konva](https://github.com/konvajs/konva) enables high performance animations, transitions, node nesting, layering, filtering, caching, event handling for desktop and mobile applications, and much more.

build-layer.sh

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ set -e
1414

1515
LAYER_NAME=canvas-nodejs
1616
LAYER_DESCRIPTION="AWS Lambda Layer with node-canvas and its dependencies packaged, provides a Cairo backed Mozilla Web Canvas API implementation with additional features."
17-
LAYER_VERSION=2.11.2
17+
LAYER_VERSION=2.11.3
1818
LAYER_AUTHOR="Charoite Lee"
1919

2020
DOT_CHAR="."
2121
NODE_VERSION=$(node -v)
2222
NODE_VERSION=${NODE_VERSION:1}
23+
SEMVER_VERSION=7.5.4
2324

2425
# Remove packaged layer if exists
2526
if [ -n "$(find . -name 'canvas-nodejs_v*.zip')" ]; then
@@ -36,13 +37,15 @@ npm init -y
3637
npm install canvas --build-from-source
3738
npm install fabric
3839
npm install konva
40+
npm install chart.js
3941
npm install mocha --save-dev
40-
jq --arg LAYER_NAME "$LAYER_NAME" --arg LAYER_DESCRIPTION "$LAYER_DESCRIPTION" --arg LAYER_VERSION "$LAYER_VERSION" --arg LAYER_AUTHOR "$LAYER_AUTHOR" '.name = $LAYER_NAME | .description = $LAYER_DESCRIPTION | .version = $LAYER_VERSION | .license = "MIT" | .author = $LAYER_AUTHOR | .scripts.test = "mocha"' package.json > package-tmp.json
42+
jq --arg LAYER_NAME "$LAYER_NAME" --arg LAYER_DESCRIPTION "$LAYER_DESCRIPTION" --arg LAYER_VERSION "$LAYER_VERSION" --arg LAYER_AUTHOR "$LAYER_AUTHOR" --arg SEMVER_VERSION "$SEMVER_VERSION" '.name = $LAYER_NAME | .description = $LAYER_DESCRIPTION | .version = $LAYER_VERSION | .license = "MIT" | .author = $LAYER_AUTHOR | .scripts.test = "mocha" | .overrides.semver = $SEMVER_VERSION ' package.json > package-tmp.json
4143
mv -f package-tmp.json package.json
4244

4345
# Test if installed modules and dependencies work fine
4446
npm test
4547
cp package-lock.json ..
48+
npm rm mocha
4649

4750
# Prepare and package layer
4851
mkdir node${NODE_VERSION%%$DOT_CHAR*}

docs/00-setup.md

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
layout: page
3+
title: Setup
4+
permalink: /setup/
5+
---
6+
7+
## Prerequisites
8+
9+
In order to start to use [lambda-layer-canvas-nodejs](https://github.com/charoitel/lambda-layer-canvas-nodejs) published on [AWS Serverless Application Repository](https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:990551184979:applications~lambda-layer-canvas-nodejs), you must have your AWS account with following services available:
10+
11+
- [AWS Serverless Application Repository](https://aws.amazon.com/serverless/serverlessrepo)
12+
- [AWS Lambda](https://aws.amazon.com/lambda)
13+
14+
## Serverless application deployment
15+
16+
Once you have your AWS account ready, there are two ways to deploy [lambda-layer-canvas-nodejs](https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:990551184979:applications~lambda-layer-canvas-nodejs) and make it available in your AWS Lambda console:
17+
18+
- [Deploy through AWS Serverless Application Repository](#deploy-through-aws-serverless-application-repository)
19+
- [Deploy through AWS Lambda console](#deploy-through-aws-lambda-console)
20+
21+
### Deploy through AWS Serverless Application Repository
22+
23+
1. Open https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:990551184979:applications~lambda-layer-canvas-nodejs
24+
2. Click **Deploy** button
25+
3. Login to your AWS account if you haven't login yet
26+
4. Edit **_Name_** (Optional)
27+
5. Click **Deploy** button
28+
6. Deployment is started and in progress
29+
7. Check your AWS Lambda console once the deployment is completed
30+
31+
### Deploy through AWS Lambda console
32+
33+
1. Login to your AWS account and open your AWS Lambda console
34+
2. Click **Create application** button
35+
3. Select **_Serverless application_**
36+
4. Input `lambda-layer-canvas-nodejs` into search box and press _Enter_ key
37+
5. Click on the title of `lambda-layer-canvas-nodejs` card
38+
6. Edit **_Name_** (Optional)
39+
7. Click **Deploy** button
40+
8. Deployment is started and in progress
41+
9. Check your AWS Lambda console once the deployment is completed
42+
43+
### Using canvas layer
44+
45+
After the deployment is completed, you may refer [usage example](/lambda-layer-canvas-nodejs/{% link 01-use.md %}) and follow the example where a Lambda function uses the canvas layer to generate PNG graphic with colored text and circle rendered.
46+
47+
## Setup environment to build the layer
48+
49+
Alternately, you may setup your own environment to build the layer according to your specific needs. When using the layer with nodejs-18.x in Amazon Linux, it requires glibc-2.28, meanwhile, compiling glibc-2.28 requires make-4.x or later[^1].
50+
51+
```console
52+
$ wget https://ftp.gnu.org/gnu/make/make-4.3.tar.gz
53+
$ tar -xzvf make-4.3.tar.gz
54+
$ cd make-4.3/
55+
$ ./configure --prefix=/usr
56+
$ make
57+
$ make install
58+
```
59+
Once make-4.x or later is ready, we may start to compiling glibc-2.28 on Amazon Linux. However, during `make install` there would be an error due to `cannot found -lnss_test2` which could be ignored[^2].
60+
61+
```console
62+
$ wget https://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz
63+
$ tar -xzvf glibc-2.28.tar.gz
64+
$ cd glibc-2.28
65+
$ mkdir build && cd build
66+
$ ../configure --prefix=/usr --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
67+
$ make
68+
$ make install
69+
...
70+
/usr/bin/ld: cannot find -lnss_test2
71+
collect2: error: ld returned 1 exit status
72+
Execution of gcc -B/usr/bin/ failed!
73+
...
74+
```
75+
76+
To test if the installation of the compiled glibc-2.28 is success or not, we may check if `GLIBC_2.28` is enabled[^1] [^2].
77+
78+
```console
79+
$ ls -l /lib64/libc.so.6
80+
lrwxrwxrwx 1 root root 12 Jul 3 15:14 /lib64/libc.so.6 -> libc-2.28.so
81+
$ strings /lib64/libc.so.6 | grep GLIBC
82+
...
83+
GLIBC_2.22
84+
GLIBC_2.23
85+
GLIBC_2.24
86+
GLIBC_2.25
87+
GLIBC_2.26
88+
GLIBC_2.27
89+
GLIBC_2.28
90+
GLIBC_PRIVATE
91+
...
92+
```
93+
94+
Once your environment is ready, you may execute the build layer script, ``` build-layer.sh ```, to build the layer and deploy through the AWS Lambda console.
95+
96+
---
97+
98+
[^1]: [Centos 7 升级 Glibc-2.28](https://cloud.tencent.com/developer/article/2021784)
99+
[^2]: [CentOS 7.6 编译安装最新版本glibc2.30 实录](https://www.jianshu.com/p/1070373a50f6)

0 commit comments

Comments
 (0)