
Directory Structure
Getting Started With Deployment
To deploy a service, you’ll need a workspace. If you don’t have one, you can create it using this guide: Creating a Workspace or seek assistance from your cluster administrator in case you don’t have permission to create a workspace.
- Select a workspace to deploy the service. This basically decides which cluster and environment the service will be deployed to.
- Select the Service option since this is a FastAPI service and exposed a REST API.
- We chose the Github option since the code is already pushed to a Github repository.
Repo Url
: This is the URL of the Github repository that contains the code for the service. For this example, the repo url is https://github.com/truefoundry/getting-started-examplesPath to build context
: This is the path to the directory in the Github repository that contains the code for the service. For this example, the path to the build context is./deploy-model-with-fastapi/
Command
: This is the command to run the service. For this example, the command isuvicorn server:app --host 0.0.0.0 --port 8000
Path to requirements
: This is the path to the requirements.txt file. This path is relative to the path to the build context. For this example, the path isrequirements.txt
Port
: This is the port on which the service will be exposed. Since we have mentioned port 8000 in the command above, so we need to specify the port here as 8000.
View your deployed service
Congratulations! You’ve successfully deployed your FastAPI service. Once you clickSubmit
, your deployment will be successful in a few seconds, and your service will be displayed as active (green), indicating that it’s up and running.
You can view all the information about your service following the steps below:
FAQ
How to omit certain files from being built and deployed?
How to omit certain files from being built and deployed?
It’s possible there are certain files in your repository that you don’t want to package in the docker image like like test files, etc.To exclude specific files from being built and deployed, create a .tfyignore file in the root directory of your project. The
.tfyignore
file follows the same rules as the .gitignore
file.If your repository already has a
.gitignore
file, you don’t need to create a .tfyignore
file. Truefoundry will automatically detect the files to ignore.Where is the docker image built?
Where is the docker image built?
If you are deploying from a Github repository, the docker image is built in Truefoundry control-plane and pushed to your configured container registry.If you are deploying code from your local machine, the Truefoundry SDK first checks is docker is installed on your local environment.
It tries to build using the locally installed Docker, failing which it uses the remote builder on the Truefoundry control-plane. If docker is not installed, the SDK will use the remote builder on the Truefoundry control-plane.
What changes when you deploy Streamlit / Gradio apps ?
What changes when you deploy Streamlit / Gradio apps ?
You just need to change the command and the port - the rest pretty much remains the same.
I cannot access the URL even after exposing the port
I cannot access the URL even after exposing the port
Whichever framework you are using the host the API, please make sure you bind the port to
0.0.0.0
and not localhost / 127.0.0.1.
.This is commonly manifested via command line arguments like gunicorn --bind 0.0.0.0:8000
or uvicorn --host 0.0.0.0 --port 8000
.