forked from kj4c/Alphas_Propex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_lambda.sh
More file actions
executable file
·59 lines (47 loc) · 1.86 KB
/
update_lambda.sh
File metadata and controls
executable file
·59 lines (47 loc) · 1.86 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
#!/bin/bash
BACKEND_DIR="./backend"
CHANGED=0
echo "🚀 Starting Lambda ZIP process..."
echo ""
for FUNCTION_DIR in "$BACKEND_DIR"/*; do
if [ -d "$FUNCTION_DIR" ]; then
FUNCTION_NAME=$(basename "$FUNCTION_DIR")
if [ "$FUNCTION_NAME" = "tests" ]; then
continue
fi
if [ "$FUNCTION_NAME" = "price_prediction" ]; then
continue
fi
ZIP_FILE="$FUNCTION_DIR/lambda.zip"
TEMP_CHECKSUM_FILE="$FUNCTION_DIR/.checksum"
NEW_CHECKSUM=$(md5sum "$FUNCTION_DIR"/handler.py "$FUNCTION_DIR"/helpers.py 2>/dev/null | md5sum | awk '{print $1}')
if [ ! -f "$TEMP_CHECKSUM_FILE" ]; then
touch "$TEMP_CHECKSUM_FILE"
fi
OLD_CHECKSUM=$(cat "$TEMP_CHECKSUM_FILE")
if [ "$NEW_CHECKSUM" != "$OLD_CHECKSUM" ]; then
echo "📦 Changes detected for $FUNCTION_NAME. Updating the zip"
echo "📦 Zipping function: $FUNCTION_NAME..."
cd "$FUNCTION_DIR" || exit
if [ "$FUNCTION_NAME" = "top_school_area" ]; then
zip -r -X lambda.zip handler.py helpers.py ../general_helpers.py schools.csv > /dev/null
else
zip -r -X lambda.zip handler.py helpers.py ../general_helpers.py > /dev/null
fi
cd - > /dev/null
# stores the new CHECKSUM FILE
echo "$NEW_CHECKSUM" | tee "$TEMP_CHECKSUM_FILE" > /dev/null
echo "✅ Created: $ZIP_FILE"
CHANGED=1
else
echo "🐼 No change detected for $FUNCTION_NAME, skipping da zip!"
fi
fi
done
if [ "$CHANGED" -eq 1 ]; then
echo "Updating variable names in variable.tf..."
python3 update_variables.py
echo "🎉 Ready for deployment! Run terraform apply only if you ready gang"
else
echo "🐻 No lambda functions updated, skipping terraform apply"
fi