Skip to content

Commit

Permalink
transparent support for nodejs10.x runtime, alixaxel#37
Browse files Browse the repository at this point in the history
  • Loading branch information
alixaxel committed Oct 13, 2019
1 parent 2ad042d commit 22fa555
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 394 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*.pem
*.pem.pub
*.zip
bin/chromium-*.br
node_modules/
nodejs/
package-lock.json
7 changes: 1 addition & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
.PHONY: inflated

%.zip:
mkdir -p nodejs/node_modules/chrome-aws-lambda/
cd nodejs/ && npm install puppeteer-core@~1.20.0 --no-bin-links --no-optional --no-package-lock --no-save --no-shrinkwrap && cd -
cd nodejs/ && npm install lambdafs@~1.3.0 puppeteer-core@~1.20.0 --no-bin-links --no-optional --no-package-lock --no-save --no-shrinkwrap && cd -
npm pack
tar --directory nodejs/node_modules/chrome-aws-lambda/ --extract --file chrome-aws-lambda-*.tgz --strip-components=1
rm chrome-aws-lambda-*.tgz
mkdir -p $(dir $@)
zip -9 --filesync --move --recurse-paths $@ nodejs/

inflated: bin/chromium-*.br
brotli --decompress --rm bin/chromium-*.br
18 changes: 5 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ If you wish to install an older version of Chromium, take a look at [Versioning]

## Usage

This package works with the `nodejs8.10` AWS Lambda runtime out of the box.

The `nodejs10.x` AWS Lambda runtime is supported, but requires a [polyfill layer](_/nodejs10.x.zip) (due to a lighter execution environment).
This package works with the `nodejs8.10` and `nodejs10.x` AWS Lambda runtimes out of the box.

```javascript
const chromium = require('chrome-aws-lambda');
Expand Down Expand Up @@ -60,7 +58,7 @@ exports.handler = async (event, context) => {
};
```

You should allocate at least 512 MB of RAM to your Lambda, 1600 MB is recommended.
You should allocate at least 512 MB of RAM to your Lambda, however 1600 MB (or more) is recommended.

### Running Locally

Expand All @@ -87,6 +85,8 @@ To use it, simply pass a **HTTPS** URL to a custom font face _before_ launching
await chromium.font('https://raw.githack.com/googlei18n/noto-emoji/master/fonts/NotoColorEmoji.ttf');
```

> The above font is needed if you want to [render emojis](https://getemoji.com/).
Fonts with the same basename will only be downloaded if they are not already cached.

> On non-serverless environments, the `font()` method is a no-op to avoid polluting the user space.
Expand Down Expand Up @@ -135,7 +135,7 @@ This package is versioned based on the underlying `puppeteer` minor version:

| `puppeteer` Version | `chrome-aws-lambda` Version | Chromium Revision |
| ------------------- | --------------------------------- | ---------------------------------------------------- |
| `1.20.*` | `npm i chrome-aws-lambda@~1.20.1` | [`686378`](https://crrev.com/686378) (`78.0.3882.0`) |
| `1.20.*` | `npm i chrome-aws-lambda@~1.20.2` | [`686378`](https://crrev.com/686378) (`78.0.3882.0`) |
| `1.19.*` | `npm i chrome-aws-lambda@~1.19.0` | [`674921`](https://crrev.com/674921) (`77.0.3844.0`) |
| `1.18.*` | `npm i chrome-aws-lambda@~1.18.1` | [`672088`](https://crrev.com/672088) (`77.0.3835.0`) |
| `1.18.*` | `npm i chrome-aws-lambda@~1.18.0` | [`669486`](https://crrev.com/669486) (`77.0.3827.0`) |
Expand Down Expand Up @@ -177,12 +177,6 @@ make chrome_aws_lambda.zip

The above will create a `chrome-aws-lambda.zip` file, which can be uploaded to your Layers console.

Alternatively, if have `brotli` installed and wish to create a layer with the Chromium binary already decompressed:

```shell
make inflated chrome_aws_lambda.zip
```

## Google Cloud Functions

Since version `1.11.2`, it's also possible to use this package on Google/Firebase Cloud Functions.
Expand Down Expand Up @@ -231,8 +225,6 @@ This allows us to get the best compression ratio and faster decompression times.
| chromium.br | Brotli | 10 | 36090087 | 34.42 | 73.65% | 0.765s |
| chromium.br | Brotli | 11 | 34820408 | **33.21** | **74.58%** | 0.712s |

For this reason, a stripped-down version of [`iltorb`](https://github.com/MayhemYDG/iltorb) is bundled as a dependency.

## License

MIT
1 change: 0 additions & 1 deletion _/.gitignore

This file was deleted.

17 changes: 1 addition & 16 deletions _/ansible/Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
.PHONY: ansible chromium iltorb
.PHONY: ansible chromium

ansible:
sudo pip install boto boto3

chromium:
ansible-playbook plays/chromium.yml -i inventory.ini

iltorb:
rm --force --recursive "$$PWD/../../node_modules/iltorb/"
rm --force --recursive "$$PWD/../../source/iltorb/"
docker run \
--rm \
--user $$(id -u "$$USER"):$$(id -g "$$USER") \
--volume "$$PWD/../../":/srv/chrome-aws-lambda \
--workdir /srv/chrome-aws-lambda node:8.10 \
npm install --no-shrinkwrap --silent
mkdir --parents "$$PWD/../../source/iltorb/build/"
mv --target-directory="$$PWD/../../source/iltorb/" \
"$$PWD/../../node_modules/iltorb/build/" \
"$$PWD/../../node_modules/iltorb/index.js" \
"$$PWD/../../node_modules/iltorb/LICENSE"
41 changes: 22 additions & 19 deletions _/ansible/plays/chromium.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
ssh-keygen -b 2048 -t rsa -f ansible.pem -q -N '' && \
chmod 0600 ansible.pem.pub
args:
chdir: ../
chdir: ..
creates: ansible.pem

- name: Creating EC2 Key Pair
Expand Down Expand Up @@ -39,12 +39,12 @@
ec2:
group: Chromium
image: "{{ image }}"
instance_type: c5d.9xlarge
instance_type: c5d.4xlarge
instance_initiated_shutdown_behavior: terminate
key_name: ansible
wait: yes
spot_type: one-time
spot_price: "1.00"
spot_price: "0.75"
spot_wait_timeout: 300
spot_launch_group: chromium
region: "{{ region }}"
Expand Down Expand Up @@ -81,7 +81,7 @@
environment:
LANG: en_US.UTF-8
LC_ALL: en_US.UTF-8
PATH: "{{ ansible_env.PATH }}:/srv/source/depot_tools"
PATH: "{{ ansible_env.PATH }}:/usr/local/bin:/srv/source/depot_tools"

tasks:
- name: Installing Packages
Expand Down Expand Up @@ -294,21 +294,12 @@

- name: Compressing Chromium
shell: |
/usr/local/bin/brotli --best --force {{ item }}
brotli --best --force {{ item }}
args:
chdir: /srv/build/chromium
with_items:
- "chromium-{{ version.stdout }}"

- name: Compressing SwiftShader
shell: |
/usr/local/bin/brotli --best --force {{ item }}
args:
chdir: /srv/source/chromium/src/out/Headless/swiftshader
with_items:
- libEGL.so
- libGLESv2.so

- name: Downloading Chromium
fetch:
src: "/srv/build/chromium/{{ item }}"
Expand All @@ -318,15 +309,27 @@
with_items:
- "chromium-{{ version.stdout }}.br"

- name: Archiving SwiftShader
shell: |
tar --directory /srv/source/chromium/src/out/Headless/swiftshader --create --file swiftshader.tar libEGL.so libGLESv2.so
args:
chdir: /srv/build/chromium
creates: /srv/build/chromium/swiftshader.tar
warn: false

- name: Compressing SwiftShader
shell: |
brotli --best --force swiftshader.tar
args:
chdir: /srv/build/chromium
creates: /srv/build/chromium/swiftshader.tar.br

- name: Downloading SwiftShader
fetch:
src: "/srv/source/chromium/src/out/Headless/swiftshader/{{ item }}"
dest: ../../../bin/swiftshader/
src: /srv/build/chromium/swiftshader.tar.br
dest: ../../../bin/
flat: yes
fail_on_missing: true
with_items:
- libEGL.so.br
- libGLESv2.so.br

- name: Teardown AWS
hosts: localhost
Expand Down
Binary file removed _/nodejs10.x.zip
Binary file not shown.
Binary file added bin/aws.tar.br
Binary file not shown.
File renamed without changes.
Binary file added bin/swiftshader.tar.br
Binary file not shown.
Binary file removed bin/swiftshader/libEGL.so.br
Binary file not shown.
Binary file removed bin/swiftshader/libGLESv2.so.br
Binary file not shown.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
"scripts": {
"postversion": "git push && git push --tags && npm publish"
},
"dependencies": {},
"dependencies": {
"lambdafs": "^1.3.0"
},
"devDependencies": {
"@types/puppeteer": "~1.20.1",
"iltorb": "^2.4.3"
"@types/puppeteer": "~1.20.1"
},
"peerDependencies": {
"puppeteer-core": "1.20.x"
Expand Down
22 changes: 0 additions & 22 deletions source/iltorb/LICENSE

This file was deleted.

Binary file removed source/iltorb/build/bindings/iltorb.node
Binary file not shown.
Loading

0 comments on commit 22fa555

Please sign in to comment.