|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +function install_python_deps() { |
| 4 | + local input_path=$1 |
| 5 | + local output_path=$2 |
| 6 | + local package=$3 |
| 7 | + |
| 8 | + echo "Installing Python dependencies for $package" |
| 9 | + mkdir -p "${output_path}" |
| 10 | + if ! pip install -r ${input_path}/requirements.txt --target $output_path --platform manylinux2014_x86_64 --only-binary=:all: --no-deps --no-cache-dir; then |
| 11 | + echo "Failed to install Python dependencies for ${package}" |
| 12 | + exit 1 |
| 13 | + fi |
| 14 | + |
| 15 | + echo "${package} dependencies installed successfully" |
| 16 | + rsync -a "${input_path}/" "${output_path}" |
| 17 | + |
| 18 | + echo "Optimizing ${package}" |
| 19 | + find $output_path -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null |
| 20 | + find $output_path -type d -name "*.dist-info" -exec rm -rf {} + 2>/dev/null |
| 21 | + find $output_path -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null |
| 22 | + find $output_path -type f -name "*.pyc" -delete |
| 23 | + find $output_path -type f -name "*.pyo" -delete |
| 24 | + find $output_path -type f -name "*.so" -exec strip {} + 2>/dev/null |
| 25 | +} |
| 26 | + |
| 27 | +function setup_python_dist(){ |
| 28 | + cd dist |
| 29 | + |
| 30 | + # Define the layers |
| 31 | + PYTHON_VERSION="3.11" |
| 32 | + DIST="." |
| 33 | + OUTPUT_DIR="python/lib/${PYTHON_VERSION}/site-packages" |
| 34 | + |
| 35 | + # Create a virtual environment for isolation |
| 36 | + python -m venv .venv |
| 37 | + source .venv/bin/activate |
| 38 | + |
| 39 | + # # Install dependencies for each lambda layer |
| 40 | + layers=("authorizer" "common" "fastapi") |
| 41 | + layers_path="../lib/core/layers" |
| 42 | + layers_output="${DIST}/lambdaLayer" |
| 43 | + for layer in "${layers[@]}"; do |
| 44 | + # ./package-lambda-layer --src="${layers_path}/${layer}" --build="./dist/$layer" --output="${layers_output}/${layer}" |
| 45 | + layer_path="${layers_path}/${layer}" |
| 46 | + layer_output="${layers_output}/${layer}/${OUTPUT_DIR}" |
| 47 | + install_python_deps $layer_path $layer_output $layer |
| 48 | + done |
| 49 | + |
| 50 | + # Install rag layer |
| 51 | + rag_path="../lib/rag/layer" |
| 52 | + rag_output="${DIST}/rag/${OUTPUT_DIR}" |
| 53 | + rag_package="rag" |
| 54 | + install_python_deps $rag_path $rag_output $rag_package |
| 55 | + |
| 56 | + # Install lisa-sdk dependencies |
| 57 | + sdk_path="../lisa-sdk" |
| 58 | + sdk_output="${DIST}/lisa-sdk/${OUTPUT_DIR}" |
| 59 | + sdk_package="lisa-sdk" |
| 60 | + install_python_deps $sdk_path $sdk_output $sdk_package |
| 61 | + |
| 62 | + # Deactivate virtual environment |
| 63 | + deactivate |
| 64 | + rm -rf .venv |
| 65 | + echo "All Python dependencies installed successfully" |
| 66 | + cd - |
| 67 | +} |
| 68 | + |
| 69 | +function copy_dist() { |
| 70 | + mkdir -p dist/ecs_model_deployer && rsync -av ecs_model_deployer/dist/ dist/ecs_model_deployer/ && cp ecs_model_deployer/Dockerfile dist/ecs_model_deployer/ |
| 71 | + mkdir -p dist/vector_store_deployer && rsync -av vector_store_deployer/dist/ dist/vector_store_deployer/ && cp vector_store_deployer/Dockerfile dist/vector_store_deployer/ |
| 72 | + mkdir -p dist/lisa-web && rsync -av lib/user-interface/react/dist/ dist/lisa-web |
| 73 | + mkdir -p dist/docs && rsync -av lib/docs/dist/ dist/docs |
| 74 | + cp VERSION dist/ |
| 75 | +} |
| 76 | + |
| 77 | +mkdir -p dist |
| 78 | +# setup_python_dist |
| 79 | +copy_dist |
0 commit comments