Skip to content

Commit 13e35ea

Browse files
committed
deploy to aws as a layer
1 parent cc9a342 commit 13e35ea

File tree

5 files changed

+55
-3
lines changed

5 files changed

+55
-3
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
build
22
result
3+
.samcli
4+
layer.zip
5+
output.yaml

Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,23 @@ bash:
2121

2222
all libs:
2323
$(DOCKER) $(MOUNTS) --entrypoint /usr/bin/make -t $(DOCKER_IMAGE) TARGET_DIR=$(TARGET) -f ../Makefile_ImageMagick $@
24+
25+
26+
STACK_NAME ?= imagemagick-layer
27+
28+
result/bin/identify: all
29+
30+
layer.zip: result/bin/identify
31+
# imagemagick has a ton of symlinks, and just using the source dir in the template
32+
# would cause all these to get packaged as individual files.
33+
# (https://github.com/aws/aws-cli/issues/2900)
34+
#
35+
# This is why we zip outside, using -y to store them as symlinks
36+
37+
cd result && zip -ry ../layer.zip *
38+
39+
output.yaml: template.yaml result/bin/identify
40+
aws cloudformation package --template $< --s3-bucket $(DEPLOYMENT_BUCKET) --output-template-file $@
41+
42+
deploy: output.yaml
43+
aws cloudformation deploy --template $< --stack-name $(STACK_NAME)

Makefile_ImageMagick

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ LIBS:=$(CACHE_DIR)/lib/libjpeg.a \
129129
$(CACHE_DIR)/lib/libbz2.a \
130130
$(CACHE_DIR)/lib/libwebp.a
131131

132-
$(CACHE_DIR)/bin/identify: $(IMAGE_MAGICK_SOURCE) $(LIBS)
132+
$(TARGET_DIR)/bin/identify: $(IMAGE_MAGICK_SOURCE) $(LIBS)
133133
tar xf $<
134134
cd ImageMa*
135135
PKG_CONFIG_PATH=$(CACHE_DIR)/lib/pkgconfig \
@@ -152,4 +152,4 @@ $(CACHE_DIR)/bin/identify: $(IMAGE_MAGICK_SOURCE) $(LIBS)
152152

153153
libs: $(LIBS)
154154

155-
all: $(CACHE_DIR)/bin/identify
155+
all: $(TARGET_DIR)/bin/identify

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Modify the versions of libraries or ImageMagick directly in [`Makefile_ImageMagi
3434
* `make bash` to open an interactive shell with all the build directories mounted
3535
* `make libs` to make only the libraries, useful to test building additional libraries without building ImageMagick itself
3636

37-
## Bundled libraries
37+
### Bundled libraries
3838

3939
This is not a full-blown ImageMagick setup you can expect on a regular Linux box, it's a slimmed down version to save space that works with the most common formats. You can add more formats by including another library into the build process in [`Makefile_ImageMagick`](Makefile_ImageMagick).
4040

@@ -44,6 +44,15 @@ This is not a full-blown ImageMagick setup you can expect on a regular Linux box
4444
* openjpeg2
4545
* libwebp
4646

47+
## Deploying to AWS as a layer
48+
49+
* `make deploy DEPLOYMENT_BUCKET=<YOUR BUCKET NAME>`
50+
51+
### configuring the deployment
52+
53+
By default, this uses imagemagick-layer as the stack name. Provide a `STACK_NAME` variable when
54+
calling `make deploy` to use an alternative name.
55+
4756
## Info on scripts
4857

4958
For more information, check out:

template.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Transform: AWS::Serverless-2016-10-31
2+
Resources:
3+
ImageMagickLayer:
4+
Type: AWS::Serverless::LayerVersion
5+
Properties:
6+
LayerName: image-magick
7+
Description: >
8+
9+
Static build of ImageMagick for AWS Linux 2,
10+
including convert, mogrify and identify tools
11+
and support for jpeg, gif, png, tiff and webm formats.
12+
13+
Check out https://github.com/serverlesspub/imagemagick-aws-lambda-2
14+
for more information.
15+
16+
ContentUri: layer.zip
17+
CompatibleRuntimes:
18+
- nodejs10.x
19+
LicenseInfo: https://imagemagick.org/script/license.php
20+
RetentionPolicy: Retain

0 commit comments

Comments
 (0)