Skip to content

Commit f531f73

Browse files
committed
Use Turborepo to cache pip install for API
- Instead of having Vercel install the Python dependencies for the API, run `pip install` with Turborepo so the library files can be cached - Run system library installation before installing API dependencies
1 parent 63697be commit f531f73

File tree

6 files changed

+19
-6
lines changed

6 files changed

+19
-6
lines changed

apps/api/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
__pycache__
22
*.key
33
.coverage
4+
lib

apps/api/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"dev:default": "./run-docker.sh",
88
"test": "pytest",
99
"lint": "flake8 src tests && mypy src tests",
10+
"build": "mkdir -p lib && pip install --target lib -r requirements.txt",
1011
"format:write": "black src tests",
1112
"format:check": "black --check src tests"
1213
},

apps/api/turbo.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": ["//"],
3+
"pipeline": {
4+
"build": {
5+
"inputs": ["requirements.txt"],
6+
"outputs": ["lib/**"]
7+
}
8+
}
9+
}

apps/site/copy-api.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Copy API files from apps/api
2-
cp -R ../api/{requirements.txt,configuration} .
2+
cp -R ../api/configuration .
33
cp -R ../api/src/ src/api/
44
cp ../api/index.py api/index.py
5+
6+
# Copy Python libraries installed by during turbo build in apps/api
7+
# instead of having Vercel install using requirements.txt
8+
cp -R ../api/lib/* .

apps/site/vercel.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"buildCommand": "cd ../.. && turbo run build --filter={apps/site} && cd apps/site && ./copy-api.sh && ./vercel-lib.sh",
2+
"buildCommand": "./vercel-lib.sh && cd ../.. && turbo run build --filter={apps/site} --filter={apps/api} && cd apps/site && ./copy-api.sh",
33
"functions": {
44
"api/index.py": {
55
"memory": 512,

apps/site/vercel-lib.sh renamed to vercel-lib.sh

+2-4
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ lib_files=(
2121
libgpg-error.so.0.10.0
2222
)
2323

24+
# These system libraries will be included in the Lambda deployment files
25+
# and accessible from Python through LD_LIBRARY_PATH
2426
mkdir lib
2527
for file in "${lib_files[@]}"
2628
do
2729
cp /usr/lib64/$file lib/
2830
done
29-
30-
echo $PWD
31-
ls
32-
ls lib

0 commit comments

Comments
 (0)