-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_docker
More file actions
executable file
·97 lines (80 loc) · 2.24 KB
/
Copy path_docker
File metadata and controls
executable file
·97 lines (80 loc) · 2.24 KB
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
96
97
#!/usr/bin/env bash
#
# This script intentionally echoes the exact Docker commands it runs.
# Seeing the full command string helps keep the workflow transparent
# and avoids the "black box" feeling of wrapper scripts.
set -euo pipefail
IFS=$'\n\t'
# Enable BuildKit for faster and more efficient Docker builds.
# First run: docker buildx install
export DOCKER_BUILDKIT=1
if [[ ! -f ".env" ]]; then
echo "Missing .env file. Copy .env-template and configure required values." >&2
exit 1
fi
if ! command -v docker >/dev/null 2>&1; then
echo "Docker command not found. Install Docker and try again." >&2
exit 1
fi
highlight() {
printf '\033[1;36m%s\033[0m\n' "$1"
}
# shellcheck disable=SC1091
source .env
required_vars=(DOCKER_IMAGE_NAME DOCKER_IMAGE_TAG TF_VAR_LAMBDA_RUNTIME TF_VAR_LAMBDA_ARCHITECTURE)
for var in "${required_vars[@]}"; do
if [[ -z "${!var:-}" ]]; then
echo "${var} must be set in .env" >&2
exit 1
fi
done
lambda_arch="${TF_VAR_LAMBDA_ARCHITECTURE}"
build_platform="linux/amd64"
if [[ "${lambda_arch}" == "arm64" ]]; then
build_platform="linux/arm64"
fi
project_dir="$(pwd)"
build_cmd=(
docker build
--platform "${build_platform}"
--build-arg "LAMBDA_RUNTIME=${TF_VAR_LAMBDA_RUNTIME}"
--tag "${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}"
--file docker/Dockerfile
.
)
run_cmd=(
docker run
--rm
--memory=4g
--platform "${build_platform}"
--volume "${project_dir}:/app"
"${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}"
/app/docker/build.sh
)
format_command() {
printf '%q ' "$@"
printf '\n'
}
echo "The .env file has been sourced. Do you wish to proceed with these docker commands:"
highlight "$(format_command "${build_cmd[@]}")"
echo ""
highlight "$(format_command "${run_cmd[@]}")"
echo
read -r -p "Continue? [y/N] " confirmation
case "${confirmation}" in
[Yy]|[Yy][Ee][Ss]) ;;
*) echo "Aborted."; exit 0 ;;
esac
highlight "Executing: $(format_command "${build_cmd[@]}")"
"${build_cmd[@]}"
highlight "Executing: $(format_command "${run_cmd[@]}")"
"${run_cmd[@]}"
if [[ -f "lambda.zip" ]]; then
rm lambda.zip
fi
if [[ ! -f "lambda-deployment.zip" ]]; then
echo "Expected lambda-deployment.zip was not generated." >&2
exit 1
fi
mv lambda-deployment.zip lambda.zip
echo "Lambda package created at lambda.zip"