diff --git a/.gitignore b/.gitignore index 24686d4..7be9e65 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ *.zip -layer \ No newline at end of file +layer +.DS_Store +__pycache__ diff --git a/README.md b/README.md index 0523109..e5318a5 100644 --- a/README.md +++ b/README.md @@ -7,16 +7,28 @@ AWS Lambda layer with GraphicsMagick binaries. Click on Layers and choose `Add a layer`, and `Provide a layer version ARN` and enter the following ARN (replace eu-west-1 with the region of your Lambda): ``` -arn:aws:lambda:eu-west-1:175033217214:layer:graphicsmagick:2 +arn:aws:lambda:eu-west-1:175033217214:layer:graphicsmagick-amzn2:1 ``` ![Provide layer ARN](img/usage.png "Provide layer ARN screenshot") -## Version ARNs +## Version ARNs for Amazon Linux 2 Runtimes -| GraphicsMagick version | ARN | -| --- | --- | -| 1.3.31 | `arn:aws:lambda::175033217214:layer:graphicsmagick:2` | +| GraphicsMagick version | ARN | +| ---------------------- | ------------------------------------------------------------------- | +| 1.3.35 | `arn:aws:lambda::175033217214:layer:graphicsmagick-amzn2:1` | + +## Version ARNs for Amazon Linux Runtimes + +| GraphicsMagick version | ARN | +| ---------------------- | ------------------------------------------------------------------ | +| 1.3.35 | `arn:aws:lambda::175033217214:layer:graphicsmagick-amzn:1` | + +## Version ARNs for Legacy Runtimes + +| GraphicsMagick version | ARN | +| ---------------------- | ------------------------------------------------------------- | +| 1.3.31 | `arn:aws:lambda::175033217214:layer:graphicsmagick:2` | ## Available Regions diff --git a/Dockerfile b/amazon-linux-2/Dockerfile similarity index 62% rename from Dockerfile rename to amazon-linux-2/Dockerfile index 61d1611..85bf041 100644 --- a/Dockerfile +++ b/amazon-linux-2/Dockerfile @@ -1,12 +1,33 @@ -FROM lambci/lambda-base:build +FROM amazonlinux:2 RUN yum update -y -RUN yum install -y libpng-devel libjpeg-devel libtiff-devel libuuid-devel gcc +RUN yum install -y \ + make \ + gcc \ + zip \ + tar \ + gzip \ + file \ + lcms2 \ + libSM \ + libXext \ + freetype \ + bzip2-devel \ + libpng-devel \ + libjpeg-devel \ + libtiff-devel \ + libuuid-devel \ + freetype-devel \ + liblcms2-devel + +RUN curl -O http://mirror.centos.org/altarch/7/os/aarch64/Packages/urw-fonts-2.4-16.el7.noarch.rpm && \ + rpm -ivh --nodeps urw-fonts-2.4-16.el7.noarch.rpm ARG GM_VERSION -RUN curl https://versaweb.dl.sourceforge.net/project/graphicsmagick/graphicsmagick/${GM_VERSION}/GraphicsMagick-${GM_VERSION}.tar.xz | tar -xJ && \ +RUN curl -O -L https://versaweb.dl.sourceforge.net/project/graphicsmagick/graphicsmagick/${GM_VERSION}/GraphicsMagick-${GM_VERSION}.tar.gz && \ + tar -xvf GraphicsMagick-${GM_VERSION}.tar.gz && \ cd GraphicsMagick-${GM_VERSION} && \ ./configure --prefix=/opt --enable-shared=no --enable-static=yes --with-gs-font-dir=/opt/share/fonts/default/Type1 && \ make && \ @@ -27,7 +48,7 @@ RUN cp /usr/lib64/liblcms2.so* /opt/lib && \ cp /usr/lib64/libjbig.so* /opt/lib && \ cp /usr/lib64/libxcb.so* /opt/lib && \ cp /usr/lib64/libXau.so* /opt/lib && \ - cp /usr/lib64/libuuid.so /opt/lib/libuuid.so.1 && \ + cp /usr/lib64/libuuid.so /opt/lib/libuuid.so.1 && \ cp /usr/lib64/libbz2.so /opt/lib/libbz2.so.1 RUN mkdir -p /opt/share/fonts/default && \ diff --git a/build.sh b/amazon-linux-2/build.sh similarity index 85% rename from build.sh rename to amazon-linux-2/build.sh index 6861108..973f7ea 100755 --- a/build.sh +++ b/amazon-linux-2/build.sh @@ -1,6 +1,6 @@ #!/bin/sh -export GM_VERSION=1.3.31 +export GM_VERSION=1.3.35 docker build --build-arg GM_VERSION -t gm-lambda-layer . docker run --rm gm-lambda-layer cat /tmp/gm-${GM_VERSION}.zip > ./layer.zip diff --git a/amazon-linux-2/publish.sh b/amazon-linux-2/publish.sh new file mode 100755 index 0000000..822b943 --- /dev/null +++ b/amazon-linux-2/publish.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +GM_VERSION=1.3.35 +LAYER_NAME='graphicsmagick-amzn2' + +REGIONS=' +ap-northeast-1 +ap-northeast-2 +ap-south-1 +ap-southeast-1 +ap-southeast-2 +ca-central-1 +eu-north-1 +eu-central-1 +eu-west-1 +eu-west-2 +eu-west-3 +sa-east-1 +us-east-1 +us-east-2 +us-west-1 +us-west-2 +' + +PROFILE='dev' + +for region in $REGIONS; do + aws lambda add-layer-version-permission --region $region --layer-name $LAYER_NAME \ + --statement-id sid1 --action lambda:GetLayerVersion --principal '*' \ + --version-number $(aws lambda publish-layer-version --region $region --layer-name $LAYER_NAME --zip-file fileb://layer.zip \ + --description "GraphicsMagick ${GM_VERSION} binaries for AmazonLinux2" --query Version --output text --profile $PROFILE) --profile $PROFILE +done diff --git a/amazon-linux-2/test.sh b/amazon-linux-2/test.sh new file mode 100755 index 0000000..6b16243 --- /dev/null +++ b/amazon-linux-2/test.sh @@ -0,0 +1,15 @@ +rm -rf layer && unzip layer.zip -d layer + +cd test + +docker run -i --rm \ + -v "$PWD":/var/task \ + -v "$PWD"/../layer:/opt \ + lambci/lambda:nodejs12.x \ + index.handler + +docker run -i --rm \ + -v "$PWD":/var/task \ + -v "$PWD"/../layer:/opt \ + lambci/lambda:python3.7 \ + main.handler diff --git a/test/image1.jpg b/amazon-linux-2/test/image1.jpg similarity index 100% rename from test/image1.jpg rename to amazon-linux-2/test/image1.jpg diff --git a/amazon-linux-2/test/index.js b/amazon-linux-2/test/index.js new file mode 100644 index 0000000..9d30a0c --- /dev/null +++ b/amazon-linux-2/test/index.js @@ -0,0 +1,13 @@ +const { execSync } = require('child_process') + +exports.handler = async (event) => { + execSync('ls -al /opt/share/fonts/default/Type1', { encoding: 'utf8', stdio: 'inherit' }) + + execSync('gm version', { encoding: 'utf8', stdio: 'inherit' }) + + execSync('gm convert -list formats', { encoding: 'utf8', stdio: 'inherit' }) + + execSync('gm convert -list fonts', { encoding: 'utf8', stdio: 'inherit' }) + + execSync('gm convert -font Courier -fill white -draw "rotate 20 text 10,10 Hello-World" image1.jpg /tmp/gm-test-output.jpg', { encoding: 'utf8', stdio: 'inherit' }) +} diff --git a/test/main.py b/amazon-linux-2/test/main.py similarity index 100% rename from test/main.py rename to amazon-linux-2/test/main.py diff --git a/amazon-linux/Dockerfile b/amazon-linux/Dockerfile new file mode 100644 index 0000000..50bdd55 --- /dev/null +++ b/amazon-linux/Dockerfile @@ -0,0 +1,60 @@ +FROM amazonlinux:1 + +RUN yum update -y + +RUN yum install -y \ + make \ + gcc \ + zip \ + tar \ + gzip \ + file \ + lcms2 \ + libSM \ + libXext \ + freetype \ + findutils \ + bzip2-devel \ + libpng-devel \ + libjpeg-devel \ + libtiff-devel \ + libuuid-devel \ + freetype-devel \ + liblcms2-devel + +RUN curl -O http://mirror.centos.org/altarch/7/os/aarch64/Packages/urw-fonts-2.4-16.el7.noarch.rpm && \ + rpm -ivh --nodeps urw-fonts-2.4-16.el7.noarch.rpm + +ARG GM_VERSION + +RUN curl -O -L https://versaweb.dl.sourceforge.net/project/graphicsmagick/graphicsmagick/${GM_VERSION}/GraphicsMagick-${GM_VERSION}.tar.gz && \ + tar -xvf GraphicsMagick-${GM_VERSION}.tar.gz && \ + cd GraphicsMagick-${GM_VERSION} && \ + ./configure --prefix=/opt --enable-shared=no --enable-static=yes --with-gs-font-dir=/opt/share/fonts/default/Type1 && \ + make && \ + make install + +RUN cp /usr/lib64/liblcms2.so* /opt/lib && \ + cp /usr/lib64/libtiff.so* /opt/lib && \ + cp /usr/lib64/libfreetype.so* /opt/lib && \ + cp /usr/lib64/libjpeg.so* /opt/lib && \ + cp /usr/lib64/libpng*.so* /opt/lib && \ + cp /usr/lib64/libXext.so* /opt/lib && \ + cp /usr/lib64/libSM.so* /opt/lib && \ + cp /usr/lib64/libICE.so* /opt/lib && \ + cp /usr/lib64/libX11.so* /opt/lib && \ + cp /usr/lib64/liblzma.so* /opt/lib && \ + cp /usr/lib64/libxml2.so* /opt/lib && \ + cp /usr/lib64/libgomp.so* /opt/lib && \ + cp /usr/lib64/libjbig.so* /opt/lib && \ + cp /usr/lib64/libxcb.so* /opt/lib && \ + cp /usr/lib64/libXau.so* /opt/lib && \ + cp /usr/lib64/libuuid.so /opt/lib/libuuid.so.1 && \ + cp /usr/lib64/libbz2.so /opt/lib/libbz2.so.1 + +RUN mkdir -p /opt/share/fonts/default && \ + cp -R /usr/share/fonts/default/Type1 /opt/share/fonts/default/Type1 + +RUN cd /opt && \ + find . ! -perm -o=r -exec chmod +400 {} \; && \ + zip -yr /tmp/gm-${GM_VERSION}.zip ./* diff --git a/amazon-linux/build.sh b/amazon-linux/build.sh new file mode 100755 index 0000000..973f7ea --- /dev/null +++ b/amazon-linux/build.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +export GM_VERSION=1.3.35 + +docker build --build-arg GM_VERSION -t gm-lambda-layer . +docker run --rm gm-lambda-layer cat /tmp/gm-${GM_VERSION}.zip > ./layer.zip diff --git a/publish.sh b/amazon-linux/publish.sh similarity index 73% rename from publish.sh rename to amazon-linux/publish.sh index 985c8f3..5c0ca29 100755 --- a/publish.sh +++ b/amazon-linux/publish.sh @@ -1,7 +1,7 @@ #!/bin/bash -GM_VERSION=1.3.31 -LAYER_NAME='graphicsmagick' +GM_VERSION=1.3.35 +LAYER_NAME='graphicsmagick-amzn' REGIONS=' ap-northeast-1 @@ -28,5 +28,5 @@ for region in $REGIONS; do aws lambda add-layer-version-permission --region $region --layer-name $LAYER_NAME \ --statement-id sid1 --action lambda:GetLayerVersion --principal '*' \ --version-number $(aws lambda publish-layer-version --region $region --layer-name $LAYER_NAME --zip-file fileb://layer.zip \ - --description "GraphicsMagick ${GM_VERSION} binaries" --query Version --output text --profile $PROFILE) --profile $PROFILE + --description "GraphicsMagick ${GM_VERSION} binaries for AmazonLinux" --query Version --output text --profile $PROFILE) --profile $PROFILE done diff --git a/test.sh b/amazon-linux/test.sh similarity index 100% rename from test.sh rename to amazon-linux/test.sh diff --git a/amazon-linux/test/image1.jpg b/amazon-linux/test/image1.jpg new file mode 100644 index 0000000..0c33bcc Binary files /dev/null and b/amazon-linux/test/image1.jpg differ diff --git a/test/index.js b/amazon-linux/test/index.js similarity index 100% rename from test/index.js rename to amazon-linux/test/index.js diff --git a/amazon-linux/test/main.py b/amazon-linux/test/main.py new file mode 100644 index 0000000..4dbd1b4 --- /dev/null +++ b/amazon-linux/test/main.py @@ -0,0 +1,7 @@ +import os + +def handler (event, context): + os.system("gm version") + os.system("gm convert -list formats") + os.system("gm convert -list fonts") + return os.system('gm convert -font Courier -fill white -draw "rotate 20 text 10,10 Hello-World" image1.jpg /tmp/gm-test-output.jpg')