- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.sh
More file actions
Latest commit
executable file
·112 lines (84 loc) · 3.84 KB
/
Copy pathpackage.sh
File metadata and controls
executable file
·112 lines (84 loc) · 3.84 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash
set -e
ARCH=$(uname -m)
PYTHON_VERSION=$(python3 --version | awk '{print $2}'| cut -d. -f1,2)
echo"Building packages for Python ${PYTHON_VERSION} on ${ARCH}"
# Check if requirements.txt is provided
if [ -f"/input/requirements.txt" ];then
# Check if SINGLE_FILE mode is enabled
if [ "${SINGLE_FILE}"="true" ];then
echo"Processing requirements.txt - creating single combined archive"
# Create temp directory for all packages
mkdir -p /temp
# Install all packages at once
echo"Installing all packages from requirements.txt..."
python3 -m pip install -r /input/requirements.txt -t /temp --no-cache-dir
# Create combined archive with Lambda Layer structure
OUTPUT_FILE="/package/combined-python${PYTHON_VERSION}-${ARCH}.zip"
cd /temp
# Create python/lib/pythonX.Y/site-packages structure for Lambda layers
mkdir -p python/lib/python${PYTHON_VERSION}/site-packages
mv * python/lib/python${PYTHON_VERSION}/site-packages/ 2>/dev/null ||true
zip -r -q "${OUTPUT_FILE}" python/
echo"✓ Created: ${OUTPUT_FILE}"
# Cleanup
cd /
rm -rf /temp
echo""
echo"========================================="
echo"Combined package built successfully!"
echo"========================================="
else
echo"Processing requirements.txt - creating individual archives for each package"
# Read each line from requirements.txt
while IFS= read -r line || [ -n"$line" ];do
# Skip empty lines and comments
[[ -z"$line"||"$line"=~ ^[[:space:]]*# ]] && continue
# Extract package name (remove version specifiers)
PACKAGE=$(echo "$line"| sed 's/[<>=!].*//'| tr -d '')
echo""
echo"========================================="
echo"Building package: ${PACKAGE}"
echo"========================================="
# Create temp directory for this package
mkdir -p /temp
# Install the package
python3 -m pip install "$line"-t /temp --no-cache-dir
# Create archive with Lambda Layer structure
OUTPUT_FILE="/package/${PACKAGE}-python${PYTHON_VERSION}-${ARCH}.zip"
cd /temp
# Create python/lib/pythonX.Y/site-packages structure for Lambda layers
mkdir -p python/lib/python${PYTHON_VERSION}/site-packages
mv * python/lib/python${PYTHON_VERSION}/site-packages/ 2>/dev/null ||true
zip -r -q "${OUTPUT_FILE}" python/
echo"✓ Created: ${OUTPUT_FILE}"
# Cleanup for next package
cd /
rm -rf /temp
done< /input/requirements.txt
echo""
echo"========================================="
echo"All packages built successfully!"
echo"========================================="
fi
else
# Single package mode (backward compatibility)
if [ -z"$1" ];then
echo"Usage: docker run --rm -v \$(pwd):/package lambdazipper PACKAGE_NAME"
echo" or: docker run --rm -v \$(pwd)/requirements.txt:/input/requirements.txt -v \$(pwd):/package lambdazipper"
exit 1
fi
PACKAGE=$1
echo"Building single package: ${PACKAGE}"
mkdir -p /temp
python3 -m pip install ${PACKAGE}-t /temp --no-cache-dir
OUTPUT_FILE="/package/${PACKAGE}-python${PYTHON_VERSION}-${ARCH}.zip"
cd /temp
# Create python/lib/pythonX.Y/site-packages structure
mkdir -p python/lib/python${PYTHON_VERSION}/site-packages
mv * python/lib/python${PYTHON_VERSION}/site-packages/ 2>/dev/null ||true
zip -r -q "${OUTPUT_FILE}" python/
echo"✓ Created: ${OUTPUT_FILE}"
# Cleanup
rm -rf /temp
fi