Skip to content

Commit 1640615

Browse files
committed
initial commit, v0.32.1
0 parents  commit 1640615

File tree

6 files changed

+2453
-0
lines changed

6 files changed

+2453
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Build Layer ZIP
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
schedule:
11+
- cron: '0 0 * * *'
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v2
19+
with:
20+
fetch-depth: 0
21+
- name: Read version
22+
id: package_lock_json
23+
run: |
24+
content=$(cat ./package-lock.json)
25+
content="${content//'%'/'%25'}"
26+
content="${content//$'\n'/'%0A'}"
27+
content="${content//$'\r'/'%0D'}"
28+
echo "::set-output name=packageLockJson::$content"
29+
- name: Variables
30+
id: vars
31+
run: |
32+
sharp_version="${{ fromJSON(steps.package_lock_json.outputs.packageLockJson).dependencies.sharp.version }}"
33+
echo "::set-output name=sharp_version::$sharp_version"
34+
35+
release_exists="true"
36+
git show-ref --tags --quiet --verify -- "refs/tags/$sharp_version" || release_exists="false"
37+
echo "::set-output name=release_exists::$release_exists"
38+
- name: Build
39+
id: docker_build
40+
uses: docker/build-push-action@v2
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
47+
- name: Create release
48+
uses: svenstaro/upload-release-action@v2
49+
with:
50+
repo_token: ${{ secrets.GITHUB_TOKEN }}
51+
tag: ${{ steps.vars.outputs.sharp_version }}
52+
file: dist/sharp-layer.zip
53+
overwrite: true

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM public.ecr.aws/sam/build-nodejs18.x:latest
2+
3+
WORKDIR /build
4+
5+
COPY * ./
6+
7+
RUN npm --no-optional --no-audit --progress=false install
8+
9+
RUN node ./node_modules/webpack/bin/webpack.js
10+
11+
RUN node -e "console.log(require('sharp'))"
12+
13+
RUN mkdir /dist && \
14+
echo "cp /build/dist/sharp-layer.zip /dist/sharp-layer.zip" > /entrypoint.sh && \
15+
chmod +x /entrypoint.sh
16+
17+
ENTRYPOINT "/entrypoint.sh"

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# AWS Sharp layer
2+
3+
This AWS lambda layer contains a pre-built [sharp](https://www.npmjs.com/package/sharp) **v0.32 (Flow)** npm library.
4+
It is optimized for the most frugal space usage possible. Includes support for Node 16 and Node 18.
5+
6+
## Dependencies
7+
8+
- Docker
9+
10+
## AWS Server - Installs
11+
12+
```sh
13+
sudo yum install docker git wget curl
14+
sudo systemctl start docker
15+
```
16+
17+
# AWS Repository Description
18+
19+
This serverless application provides a Lambda Layer that includes the [sharp](https://sharp.pixelplumbing.com/) image processing library for Node.js. The original work is from Paul Spencer, this is a fork of his work but with Node16.x, Node 18.x & v0.32 (flow)
20+
21+
The motivation for this layer is two-fold:
22+
23+
You need to bundle the x86 binaries for libvips with sharp when installing it, this is difficult on MacOS
24+
The library size is big enough to make the function not editable in the Lambda console. To use this layer in a Node.js lambda function, simply add this layer to your stack. The published version of this layer will track the version of sharp that is available.
25+
26+
# AWS Repository License
27+
28+
http://www.apache.org/licenses/LICENSE-2.0
29+
30+
# Getting
31+
32+
A pre-built layer zip file is available on the [Releases page](../../releases), alongside the size of the layer.
33+
34+
# Building
35+
36+
## Steps
37+
38+
1. Clone the repo:
39+
```shell script
40+
git clone git@github.com:cbschuld/sharp-aws-lambda-layer.git
41+
cd sharp-aws-lambda-layer/
42+
```
43+
1. Install dependencies:
44+
```shell script
45+
docker run -v "$PWD":/var/task public.ecr.aws/sam/build-nodejs18.x:latest npm --no-optional --no-audit --progress=false install
46+
```
47+
1. Build the layer:
48+
```shell script
49+
docker run -v "$PWD":/var/task public.ecr.aws/sam/build-nodejs18.x:latest node ./node_modules/webpack/bin/webpack.js
50+
```
51+
1. Perform a smoke-test:
52+
```shell script
53+
docker run -w /var/task/dist/nodejs -v "$PWD":/var/task public.ecr.aws/sam/build-nodejs18.x:latest node -e "console.log(require('sharp'))"
54+
```
55+
1. Import created layer into your AWS account:
56+
```shell script
57+
aws --profile=tintable lambda publish-layer-version --layer-name sharp-v0-32 --description "Sharp layer - v0.32 (Flow)" --license-info "Apache License 2.0" --zip-file fileb://sharp-layer-v0-32.zip --compatible-runtimes nodejs16.x nodejs18.x --compatible-architectures x86_64
58+
```

0 commit comments

Comments
 (0)