-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tianshu Cheng
authored and
Tianshu Cheng
committed
Nov 27, 2024
1 parent
91f4ad9
commit 1bb5400
Showing
8 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
20 changes: 20 additions & 0 deletions
20
truss/tests/test_data/test_custom_server_truss/config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
base_image: | ||
image: baseten/fastapi-test:0.1.2 | ||
docker_server: | ||
start_command: python main.py | ||
readiness_endpoint: /health | ||
liveness_endpoint: /health | ||
predict_endpoint: /predict | ||
server_port: 8000 | ||
resources: | ||
accelerator: null | ||
cpu: '1' | ||
memory: 2Gi | ||
use_gpu: false | ||
model_name: Test Docker Server Truss | ||
secrets: | ||
hf_access_token: null | ||
environment_variables: | ||
HF_TOKEN: 123456 | ||
runtime: | ||
predict_concurrency: 1 |
17 changes: 17 additions & 0 deletions
17
truss/tests/test_data/test_custom_server_truss/test_docker_image/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM python:3.11-slim | ||
|
||
# Update package lists and install curl | ||
RUN apt-get update && apt-get install -y curl | ||
|
||
# Install pip dependencies | ||
RUN pip install fastapi[standard] | ||
|
||
# Copy the FastAPI application code | ||
COPY app.py /home/app.py | ||
COPY main.py /home/main.py | ||
|
||
# Set the working directory | ||
WORKDIR /home | ||
|
||
# Command to run FastAPI directly | ||
ENTRYPOINT ["python", "main.py"] |
10 changes: 10 additions & 0 deletions
10
truss/tests/test_data/test_custom_server_truss/test_docker_image/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
We built this minimal fastapi docker image to be used in integration test `test_custom_server_truss.py::test_custom_server_truss` | ||
|
||
Steps to update testing docker image | ||
|
||
1. run `docker login` | ||
2. cd into this directory | ||
3. update version number in VERSION file | ||
(before running the next step, make sure you meet with the [prerequisites](https://docs.docker.com/build/building/multi-platform/#prerequisites) here) | ||
4. run `sh build_upload_new_image.sh` | ||
5. update image tag to latest version in config.yaml |
1 change: 1 addition & 0 deletions
1
truss/tests/test_data/test_custom_server_truss/test_docker_image/VERSION
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.1.1 |
Empty file.
19 changes: 19 additions & 0 deletions
19
truss/tests/test_data/test_custom_server_truss/test_docker_image/app.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import os | ||
|
||
from fastapi import FastAPI | ||
|
||
app = FastAPI() | ||
|
||
|
||
@app.get("/health") | ||
async def health(): | ||
return {"message": "OK"} | ||
|
||
|
||
@app.post("/predict") | ||
async def root(): | ||
return { | ||
"message": "Hello World", | ||
"is_env_var_passed": os.environ.get("HF_TOKEN") is not None, | ||
"is_secret_mounted": os.path.exists("/secrets/hf_access_token"), | ||
} |
6 changes: 6 additions & 0 deletions
6
truss/tests/test_data/test_custom_server_truss/test_docker_image/build_upload_new_image.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Read the version from the VERSION file | ||
VERSION=$(cat VERSION) | ||
|
||
docker buildx build --platform linux/amd64,linux/arm64 -f ./Dockerfile -t fastapi-test:$VERSION . || { echo "Failed to build the Docker image"; exit 1; } | ||
docker tag fastapi-test:$VERSION baseten/fastapi-test:$VERSION || { echo "Failed to tag the Docker image."; exit 1; } | ||
docker push baseten/fastapi-test:$VERSION || { echo "Failed to push the Docker image."; exit 1; } |