-
Notifications
You must be signed in to change notification settings - Fork 2
/
_make_zip.sh
executable file
·54 lines (39 loc) · 1.42 KB
/
_make_zip.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
#!/usr/bin/env bash
set -e
# AWS Lambda Layer Zip Builder for Python Libraries
# This script is executed inside a docker container by the "build_layer.sh" script
# It builds the zip file with files in lambda layers dir structure
# /python/lib/pythonX.X/site-packages
scriptname=$(basename "$0")
scriptbuildnum="1.0.1"
scriptbuilddate="2020-05-08"
### VARS
CURRENT_DIR=$(reldir=$(dirname -- "$0"; echo x); reldir=${reldir%?x}; cd -- "$reldir" && pwd && echo x); CURRENT_DIR=${CURRENT_DIR%?x}
PYTHON="python${PYTHON_VER}"
ZIP_FILE="base_${PYTHON}.zip"
echo "BUILDING ZIP: ${ZIP_FILE} for ${PYTHON}"
# Create build dir
mkdir /tmp/build
# Create virtual environment and activate it
virtualenv -p $PYTHON /tmp/build
source /tmp/build/bin/activate
# Install requirements
pip install -r /temp/build/requirements.txt --no-cache-dir
# Create staging area in dir structure req for lambda layers
mkdir -p "/tmp/base/python/lib/${PYTHON}"
# Move dependancies to staging area
mv "/tmp/build/lib/${PYTHON}/site-packages" "/tmp/base/python/lib/${PYTHON}"
# remove unused libraries
cd "/tmp/base/python/lib/${PYTHON}/site-packages"
rm -rf easy-install*
rm -rf wheel*
rm -rf setuptools*
rm -rf virtualenv*
rm -rf pip*
# Delete .pyc files from staging area
cd "/tmp/base/python/lib/${PYTHON}"
find . -name '*.pyc' -delete
# Add files from staging area to zip
cd /tmp/base
zip -r "${CURRENT_DIR}/${ZIP_FILE}" .
echo -e "\nBASE ZIP CREATION FINISHED"