-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-lambda.sh
executable file
·71 lines (55 loc) · 1.66 KB
/
build-lambda.sh
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
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
source _scripto.sh
DEPLOY=
PROD=
LAMBDA=
WASM_LAYER=
for arg in "$@"; do
case "$arg" in
--deploy) DEPLOY=1 ;;
--prod) PROD=1 ;;
--all|--lambda) LAMBDA=1 ;;&
--all|--wasm-layer) WASM_LAYER=1 ;;&
esac
done
ensure_some_target LAMBDA WASM_LAYER
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT SIGINT
if [[ $PROD ]]; then
build_command=cargo
else
build_command=cross
fi
unset OPENSSL_NO_VENDOR
pids=()
if [[ $WASM_LAYER ]]; then
{
cargo run -p lambda-cache --release "$tmpdir/wasmer-cache" wasm-dist/lang-runners/*
} 2>&1 | prepend wasm-layer: &
pids+=($!)
fi
if [[ $LAMBDA ]]; then
{
$build_command build -p lambda-runner --target=x86_64-unknown-linux-musl --all-features --release
cp target/x86_64-unknown-linux-musl/release/lambda-runner "$tmpdir/bootstrap"
} 2>&1 | prepend lambda-runner: &
pids+=($!)
fi
wait_pids "${pids[@]}"
LAYER_NAME=wasmer-cache
if [[ $DEPLOY ]]; then
cd "$tmpdir"
if [[ $LAMBDA ]]; then
zip lambda.zip bootstrap
aws s3 cp lambda.zip "s3://$S3_BUCKET"
aws lambda update-function-code --function-name "$FUNCTION_NAME" --s3-bucket="$S3_BUCKET" --s3-key lambda.zip
fi
if [[ $WASM_LAYER ]]; then
zip -r wasmer-cache.zip wasmer-cache/
aws s3 cp wasmer-cache.zip "s3://$S3_BUCKET"
LAYER_ARN=$(aws lambda publish-layer-version --layer-name "$LAYER_NAME" --content=S3Bucket="$S3_BUCKET",S3Key=wasmer-cache.zip | jq -r .LayerVersionArn)
aws lambda update-function-configuration --function-name "$FUNCTION_NAME" --layers "$LAYER_ARN"
fi
fi