Skip to content
Merged
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
4 changes: 1 addition & 3 deletions .github/workflows/docker-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build Layer ZIP
name: Build and deploy Sharp Lambda Layer

on:
push:
Expand All @@ -7,8 +7,6 @@ on:
pull_request:
branches:
- master
schedule:
- cron: '0 0 * * *'

jobs:
build:
Expand Down
23 changes: 17 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
FROM lambci/lambda:build-nodejs12.x
FROM amazonlinux:latest

WORKDIR /build
RUN touch ~/.bashrc && chmod +x ~/.bashrc

COPY * ./
# Install the dependencies
RUN yum -y install gcc44 gcc-c++ libgcc44 cmake wget findutils tar gzip zip

# Node
RUN curl --silent --location https://rpm.nodesource.com/setup_14.x | bash -
RUN yum install nodejs -y

RUN npm --no-optional --no-audit --progress=false install
# Confirm node installation
RUN node -v && npm -v

WORKDIR /build
COPY * ./

RUN node ./node_modules/webpack/bin/webpack.js
RUN npm --no-optional --no-audit --progress=false --production install

# Confirm sharp installation
RUN node -e "console.log(require('sharp'))"

# Entrypoint script will zip the node modules into an archive in dist, which can be exported out of the container
RUN mkdir /dist && \
echo "cp /build/dist/sharp-layer.zip /dist/sharp-layer.zip" > /entrypoint.sh && \
echo "zip -FS -q -r /dist/sharp-layer.zip ./node_modules/*" > /entrypoint.sh && \
chmod +x /entrypoint.sh

ENTRYPOINT "/entrypoint.sh"
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@ A pre-built layer zip file is available on the [Releases page](../../releases),
git clone git@github.com:Umkus/lambda-layer-sharp.git
cd lambda-layer-sharp/
```
1. Create build image:
```
docker build . --tag amazonlinux:nodejs-14
```
1. Install dependencies:
```shell script
docker run -v "$PWD":/var/task lambci/lambda:build-nodejs12.x npm --no-optional --no-audit --progress=false install
docker run -v "$PWD":/var/task amazonlinux:nodejs-14 npm --no-optional --no-audit --progress=false install
```
1. Build the layer:
```shell script
docker run -v "$PWD":/var/task lambci/lambda:build-nodejs12.x node ./node_modules/webpack/bin/webpack.js
docker run -v "$PWD":/var/task amazonlinux:nodejs-14 node ./node_modules/webpack/bin/webpack.js
```
1. Perform a smoke-test:
```shell script
docker run -w /var/task/dist/nodejs -v "$PWD":/var/task lambci/lambda:build-nodejs12.x node -e "console.log(require('sharp'))"
docker run -w /var/task/dist/nodejs -v "$PWD":/var/task amazonlinux:nodejs-14 node -e "console.log(require('sharp'))"
```
1. Import created layer into your AWS account:
```shell script
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 nodejs12.x
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
```
9 changes: 1 addition & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@
"repository": "git@github.com:Umkus/lambda-layer-sharp.git",
"license": "Apache License 2.0",
"module": "lambda-layer-sharp",
"devDependencies": {
"webpack-node-externals": "^3.0.0",
"copy-webpack-plugin": "^6.4.1",
"webpack": "^5.65.0",
"webpack-cli": "^4.9.1",
"zip-webpack-plugin": "^4.0.1"
},
"dependencies": {
"sharp": "^0.30.0"
"sharp": "^0.31.0"
},
"engines": {
"node": ">=14"
Expand Down
49 changes: 0 additions & 49 deletions webpack.config.js

This file was deleted.