-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_docker
More file actions
executable file
·77 lines (61 loc) · 2.14 KB
/
Copy path_docker
File metadata and controls
executable file
·77 lines (61 loc) · 2.14 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
#!/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_NODE_VERSION 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 NODE_VERSION=\"${TF_VAR_NODE_VERSION}\" --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"
echo "The .env file has been sourced. Do you wish to proceed with these docker commands:"
highlight "${build_cmd}"
echo ""
highlight "${run_cmd}"
echo
read -r -p "Continue? [y/N] " confirmation
case "${confirmation}" in
[Yy]|[Yy][Ee][Ss]) ;;
*) echo "Aborted."; exit 0 ;;
esac
highlight "Executing: ${build_cmd}"
eval "${build_cmd}"
highlight "Executing: ${run_cmd}"
eval "${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"