Skip to content

Commit

Permalink
deploy to aws as a layer
Browse files Browse the repository at this point in the history
  • Loading branch information
gojko committed May 17, 2019
1 parent cc9a342 commit 13e35ea
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
build
result
.samcli
layer.zip
output.yaml
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,23 @@ bash:

all libs:
$(DOCKER) $(MOUNTS) --entrypoint /usr/bin/make -t $(DOCKER_IMAGE) TARGET_DIR=$(TARGET) -f ../Makefile_ImageMagick $@


STACK_NAME ?= imagemagick-layer

result/bin/identify: all

layer.zip: result/bin/identify
# imagemagick has a ton of symlinks, and just using the source dir in the template
# would cause all these to get packaged as individual files.
# (https://github.com/aws/aws-cli/issues/2900)
#
# This is why we zip outside, using -y to store them as symlinks

cd result && zip -ry ../layer.zip *

output.yaml: template.yaml result/bin/identify
aws cloudformation package --template $< --s3-bucket $(DEPLOYMENT_BUCKET) --output-template-file $@

deploy: output.yaml
aws cloudformation deploy --template $< --stack-name $(STACK_NAME)
4 changes: 2 additions & 2 deletions Makefile_ImageMagick
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ LIBS:=$(CACHE_DIR)/lib/libjpeg.a \
$(CACHE_DIR)/lib/libbz2.a \
$(CACHE_DIR)/lib/libwebp.a

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

libs: $(LIBS)

all: $(CACHE_DIR)/bin/identify
all: $(TARGET_DIR)/bin/identify
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Modify the versions of libraries or ImageMagick directly in [`Makefile_ImageMagi
* `make bash` to open an interactive shell with all the build directories mounted
* `make libs` to make only the libraries, useful to test building additional libraries without building ImageMagick itself

## Bundled libraries
### Bundled libraries

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).

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

## Deploying to AWS as a layer

* `make deploy DEPLOYMENT_BUCKET=<YOUR BUCKET NAME>`

### configuring the deployment

By default, this uses imagemagick-layer as the stack name. Provide a `STACK_NAME` variable when
calling `make deploy` to use an alternative name.

## Info on scripts

For more information, check out:
Expand Down
20 changes: 20 additions & 0 deletions template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Transform: AWS::Serverless-2016-10-31
Resources:
ImageMagickLayer:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: image-magick
Description: >
Static build of ImageMagick for AWS Linux 2,
including convert, mogrify and identify tools
and support for jpeg, gif, png, tiff and webm formats.
Check out https://github.com/serverlesspub/imagemagick-aws-lambda-2
for more information.
ContentUri: layer.zip
CompatibleRuntimes:
- nodejs10.x
LicenseInfo: https://imagemagick.org/script/license.php
RetentionPolicy: Retain

0 comments on commit 13e35ea

Please sign in to comment.