Skip to content

Commit 2723daa

Browse files
committed
Added ARM support
1 parent 3cb261b commit 2723daa

File tree

5 files changed

+34
-41
lines changed

5 files changed

+34
-41
lines changed

.github/workflows/docker-workflow.yml

+2-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
- master
1010
schedule:
1111
- cron: '0 0 * * *'
12+
workflow_dispatch:
1213

1314
jobs:
1415
build:
@@ -36,14 +37,7 @@ jobs:
3637
git show-ref --tags --quiet --verify -- "refs/tags/$sharp_version" || release_exists="false"
3738
echo "release_exists=$release_exists" >> $GITHUB_OUTPUT
3839
- name: Build
39-
id: docker_build
40-
uses: docker/build-push-action@v4
41-
with:
42-
context: .
43-
file: ./Dockerfile
44-
tags: amazon-linux-sharp-layer:dev
45-
- name: Copy artifacts
46-
run: docker run -v "${{ github.workspace }}/dist":/dist amazon-linux-sharp-layer:dev
40+
run: npm ci --arch=x64 --platform=linux
4741
- name: Create release
4842
uses: svenstaro/upload-release-action@v2
4943
with:

README.md

+19-27
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,26 @@
11
# AWS Sharp layer
2-
This AWS lambda layer contains a pre-built [sharp](https://www.npmjs.com/package/sharp) npm library.
3-
It is optimized for the most frugal space usage possible.
2+
This AWS lambda layer contains a pre-built [sharp](https://www.npmjs.com/package/sharp) npm library, so that you could "just use" it in your lambda code:
43

5-
# Getting
6-
A pre-built layer zip file is available on the [Releases page](../../releases), alongside the size of the layer.
4+
```javascript
5+
import sharp from 'sharp'
6+
// ...
7+
```
78

8-
# Building
9+
It holds only necessary files to minimize its weight (16Mb).
10+
It also supports all currently supported AWS lambda node runtimes (>=`nodejs14.x`) and architectures (`x86_64` and `arm64`).
911

10-
## Dependencies
11-
* Docker
12+
# Getting
13+
A pre-built layer zip file is available on the [Releases page](../../releases).
1214

13-
## Steps
14-
1. Clone the repo:
15-
```shell script
16-
git clone git@github.com:Umkus/lambda-layer-sharp.git
17-
cd lambda-layer-sharp/
18-
```
19-
1. Install dependencies:
20-
```shell script
21-
docker run -v "$PWD":/var/task --entrypoint npm public.ecr.aws/lambda/nodejs:18 --no-audit --progress=false --arch=x64 --platform=linux ci
22-
```
23-
1. Build the layer:
15+
You can import it into your AWS account throught the Lambda console or with the following command:
2416
```shell script
25-
docker run -v "$PWD":/var/task --entrypoint node public.ecr.aws/lambda/nodejs:18 ./node_modules/webpack/bin/webpack.js
26-
```
27-
1. Perform a smoke-test:
28-
```shell script
29-
docker run -w /var/task/dist/nodejs -v "$PWD":/var/task --entrypoint node public.ecr.aws/lambda/nodejs:18 -e "console.log(require('sharp'))"
30-
```
31-
1. Import created layer into your AWS account:
32-
```shell script
33-
aws lambda publish-layer-version --layer-name sharp --description "Sharp layer" --license-info "Apache License 2.0" --zip-file fileb://dist/sharp-layer.zip --compatible-runtimes nodejs14.x nodejs16.x nodejs18.x
17+
aws lambda publish-layer-version --layer-name sharp --description "Sharp layer" --license-info "Apache License 2.0" --zip-file fileb://dist/sharp-layer.zip --compatible-runtimes nodejs14.x nodejs16.x nodejs18.x --compatible-architectures x86_64 arm64
3418
```
19+
20+
# Building
21+
Install dependencies (this will wipe your existing `node_modules/` directory):
22+
```shell script
23+
npm ci --arch=x64 --platform=linux
24+
```
25+
26+
Build will be performed automatically upon deps installation.

package-lock.json

+7-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
"dependencies": {
1515
"sharp": "^0.31.3"
1616
},
17+
"scripts": {
18+
"postinstall": "npm run install-arm && npm run build",
19+
"install-arm": "npm install --prefix /tmp/sharp --arch=arm64 --platform=linux sharp && cp -R /tmp/sharp/node_modules/sharp node_modules/",
20+
"build": "node ./node_modules/webpack/bin/webpack.js"
21+
},
1722
"engines": {
1823
"node": ">=14"
1924
},

webpack.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@ module.exports = {
4545
},
4646
externals: {
4747
'./sharp-linux-x64.node': './build/Release/sharp-linux-x64.node',
48+
'./sharp-linux-arm64v8.node': './build/Release/sharp-linux-arm64v8.node',
4849
},
4950
};

0 commit comments

Comments
 (0)