-
Notifications
You must be signed in to change notification settings - Fork 45
/
Makefile
95 lines (77 loc) · 2.62 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
NODE_VERSION=16
TEST_IMG_NAME=canvas-lambda-test
help:
@echo "Usage:"
@echo " make help — display this help"
@echo " make build — Build the layers using docker"
@echo " make publish — Upload the layer to AWS"
@echo " make test — Test the layers, test pass if data uri is output"
@echo " make clean — Remove built layers"
build: clean
docker build . \
--build-arg NODE_VERSION="${NODE_VERSION}" \
--tag node${NODE_VERSION}-canvas-layers
mkdir -p build
docker create -ti --name dummy node${NODE_VERSION}-canvas-layers bash
docker cp dummy:/root/layers/node${NODE_VERSION}_canvas_lib64_layer.zip build/
docker cp dummy:/root/layers/node${NODE_VERSION}_canvas_layer.zip build/
docker rm -f dummy
publish-lib:
aws lambda publish-layer-version \
--layer-name "node${NODE_VERSION}CanvasLib64" \
--compatible-runtimes nodejs${NODE_VERSION}.x \
--zip-file "fileb://build/node${NODE_VERSION}_canvas_lib64_layer.zip" \
--description "Node canvas lib 64"
publish-nodejs:
aws lambda publish-layer-version \
--layer-name "node${NODE_VERSION}Canvas" \
--compatible-runtimes nodejs${NODE_VERSION}.x \
--zip-file "fileb://build/node${NODE_VERSION}_canvas_layer.zip" \
--description "A Lambda Layer which includes node canvas, chart.js, chartjs-node-canvas, chartjs-plugin-datalabels"
publish: build publish-lib publish-nodejs
# This doesn't work for some reason. It would be nice to use this instead of the
# `docker build` below then we wouldn't need `test.dockerfile`
# docker run -p 9564:8080 --rm -d \
# --name ${TEST_IMG_NAME} \
# --volume "$$(pwd)":/var/task:ro,delegated \
# --volume "$$(pwd)/lib":/opt/lib:ro,delegated \
# --volume "$$(pwd)/nodejs":/opt/nodejs:ro,delegated \
# public.ecr.aws/lambda/nodejs:16 \
# test.handler
test: unzip-layers
docker run \
-p 9564:8080 \
-d \
--rm \
--name ${TEST_IMG_NAME} \
$$( docker build \
--no-cache \
--build-arg NODE_VERSION=${NODE_VERSION} \
--file test.dockerfile \
-q \
. \
)
echo $$(curl \
-s \
-XPOST "http://localhost:9564/2015-03-31/functions/function/invocations" \
-d '{"message":"Test was successful!"}' \
| jq '.body' );
docker stop ${TEST_IMG_NAME}
debug: build unzip-layers
docker run \
--rm \
-it \
--volume "$$(pwd)":/var/task:ro,delegated \
--volume "$$(pwd)/lib":/opt/lib:ro,delegated \
--volume "$$(pwd)/nodejs":/opt/nodejs:ro,delegated \
node${NODE_VERSION}-canvas-layers \
/bin/bash
unzip-layers: build
unzip-layers: nodejs
unzip-layers: lib
nodejs:
unzip build/node${NODE_VERSION}_canvas_layer.zip
lib:
unzip build/node${NODE_VERSION}_canvas_lib64_layer.zip
clean:
rm -rf build lib nodejs