-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-custom-layer.sh
executable file
·70 lines (59 loc) · 1.87 KB
/
add-custom-layer.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
#!/usr/bin/env bash
set -o pipefail
basedir="$(dirname "$(readlink -f "${BASH_SOURCE}")")" || {
echo '[ERROR] Unable to resolve script directory'
return 1
} >&2
. "${basedir}/common.shrc" || {
echo '[ERROR] Unable to load common'
return 1
} >&2
function main() {
local rc=0
common.check.bin pip3 || rc=$?
[[ $rc == 0 ]] || return $rc
pip3 install virtualenv || {
echo '[ERROR] Unable to install virtualenv'
return 1
} >&2
echo "[INFO ] Preparing archive..."
local archive_dir="./lambda"
[[ -z "${APPLAMBDAACTION_SUB_PATH}" ]] || archive_dir="${archive_dir}/${APPLAMBDAACTION_SUB_PATH}"
local archive_script="${archive_dir}/prepare_archive.sh"
common.check.exe "${archive_script}" &&
"${archive_script}" &&
true || {
echo "[ERROR] Unable to prepare Lambda archive"
return 1
} >&2
local zip_fullpath="$(readlink -f "${archive_dir}/function.zip")"
[[ -f "${zip_fullpath}" ]] || {
echo "[ERROR] Missing archive file '${zip_fullpath}'"
return 1
} >&2
[[ "${APPLAMBDAACTION_INJECT_ROUTE_FILES}" != 'true' ]] || {
echo "[INFO ] Injecting route files..."
local zip_fullpath="$(readlink -f "${archive_dir}/function.zip")"
[[ -f "${zip_fullpath}" ]] || {
echo "[ERROR] Missing archive file '${zip_fullpath}'"
exit 1
} >&2
local route_dir="$(mktemp --directory)" &&
"${basedir}/fetch-routes.sh" "${route_dir}" &&
pushd "${route_dir}" &&
zip -ru "${zip_fullpath}" . &&
popd &&
true || {
echo "[ERROR] Unable to inject route files"
return 1
} >&2
[[ "${APPLAMBDAACTION_DRY_RUN}" == 'false' ]] || {
unzip -l "${zip_fullpath}"
}
}
echo "[INFO ] Copying archive file '${zip_fullpath}' to Terraform project..."
mkdir -p ./terragrunt/modules/custom/lambda_prerequisite/ &&
cp "${zip_fullpath}" './terragrunt/modules/custom/lambda_prerequisite/.' &&
true
}
main "$@"