diff --git a/truss/tests/test_data/test_custom_server_truss/__init__.py b/truss/tests/test_data/test_custom_server_truss/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/truss/tests/test_data/test_custom_server_truss/config.yaml b/truss/tests/test_data/test_custom_server_truss/config.yaml new file mode 100644 index 000000000..473c74c0e --- /dev/null +++ b/truss/tests/test_data/test_custom_server_truss/config.yaml @@ -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 diff --git a/truss/tests/test_data/test_custom_server_truss/test_docker_image/Dockerfile b/truss/tests/test_data/test_custom_server_truss/test_docker_image/Dockerfile new file mode 100644 index 000000000..5daa79755 --- /dev/null +++ b/truss/tests/test_data/test_custom_server_truss/test_docker_image/Dockerfile @@ -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"] diff --git a/truss/tests/test_data/test_custom_server_truss/test_docker_image/README.md b/truss/tests/test_data/test_custom_server_truss/test_docker_image/README.md new file mode 100644 index 000000000..428c77848 --- /dev/null +++ b/truss/tests/test_data/test_custom_server_truss/test_docker_image/README.md @@ -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 diff --git a/truss/tests/test_data/test_custom_server_truss/test_docker_image/VERSION b/truss/tests/test_data/test_custom_server_truss/test_docker_image/VERSION new file mode 100644 index 000000000..17e51c385 --- /dev/null +++ b/truss/tests/test_data/test_custom_server_truss/test_docker_image/VERSION @@ -0,0 +1 @@ +0.1.1 diff --git a/truss/tests/test_data/test_custom_server_truss/test_docker_image/__init__.py b/truss/tests/test_data/test_custom_server_truss/test_docker_image/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/truss/tests/test_data/test_custom_server_truss/test_docker_image/app.py b/truss/tests/test_data/test_custom_server_truss/test_docker_image/app.py new file mode 100644 index 000000000..1d4d34be2 --- /dev/null +++ b/truss/tests/test_data/test_custom_server_truss/test_docker_image/app.py @@ -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"), + } diff --git a/truss/tests/test_data/test_custom_server_truss/test_docker_image/build_upload_new_image.sh b/truss/tests/test_data/test_custom_server_truss/test_docker_image/build_upload_new_image.sh new file mode 100644 index 000000000..7eac7df78 --- /dev/null +++ b/truss/tests/test_data/test_custom_server_truss/test_docker_image/build_upload_new_image.sh @@ -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; }