Skip to content

Commit

Permalink
Use Turborepo to cache pip install for API
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
taesungh committed Jan 20, 2024
1 parent 63697be commit 0b32923
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions apps/api/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__pycache__
*.key
.coverage
lib
1 change: 1 addition & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"dev:default": "./run-docker.sh",
"test": "pytest",
"lint": "flake8 src tests && mypy src tests",
"build": "mkdir -p lib && pip install --target lib -r requirements.txt",
"format:write": "black src tests",
"format:check": "black --check src tests"
},
Expand Down
9 changes: 9 additions & 0 deletions apps/api/turbo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": ["//"],
"pipeline": {
"build": {
"inputs": ["requirements.txt"],
"outputs": ["lib/**"]
}
}
}
6 changes: 5 additions & 1 deletion apps/site/copy-api.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Copy API files from apps/api
cp -R ../api/{requirements.txt,configuration} .
cp -R ../api/configuration .
cp -R ../api/src/ src/api/
cp ../api/index.py api/index.py

# Copy Python libraries installed by during turbo build in apps/api
# instead of having Vercel install using requirements.txt
cp -R ../api/lib/* .
6 changes: 2 additions & 4 deletions apps/site/vercel-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ lib_files=(
libgpg-error.so.0.10.0
)

# These system libraries will be included in the Lambda deployment files
# and accessible from Python through LD_LIBRARY_PATH
mkdir lib
for file in "${lib_files[@]}"
do
cp /usr/lib64/$file lib/
done

echo $PWD
ls
ls lib
2 changes: 1 addition & 1 deletion apps/site/vercel.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"buildCommand": "cd ../.. && turbo run build --filter={apps/site} && cd apps/site && ./copy-api.sh && ./vercel-lib.sh",
"buildCommand": "./vercel-lib.sh && cd ../.. && turbo run build --filter={apps/site} --filter={apps/api} && cd apps/site && ./copy-api.sh",
"functions": {
"api/index.py": {
"memory": 512,
Expand Down

0 comments on commit 0b32923

Please sign in to comment.