Niusoski
Niusoski

Reputation: 167

How to deploy a fastapi api to a digital ocean droplet?

I have built a fastapi API and I have a digital ocean droplet machine running on Ubuntu. I can't figure out how to deploy it to the server so that other users/machines can make use of the API. I couldn't find anything online specific to Droplets or servers regarding this, so any and all guidance will be much appreciated. I am unsure about how exactly to frame this question, so please comment if I need to provide any further clarifications. Thanks.

Upvotes: 1

Views: 5277

Answers (2)

Eric Kabuchanga
Eric Kabuchanga

Reputation: 1

Fork this github and run your API as an app template it has all the settings.

  1. Using Docker file as illustrated(this can run directly on the droplet and as an app)
  2. Using Procfile(this runs an app web service)

https://github.com/kabuchanga/fastapi-apptst

Upvotes: 0

Matyas Richter
Matyas Richter

Reputation: 41

I'm afraid there is no simple answer. There are lots of options when it comes to deploying your application - depending on whether you need any system dependencies, whether you application is stateless or not etc.

A relatively simple and well documented way to deploy it would be to make use of Docker and Digital Oceans' App Platform.

The steps are:

  1. Wrap your application in a Docker container, producing a Docker image - there is actually a step by step guide for this in FastAPI's documentation.
  2. Push this image to a container registry - in this case, you might want to use DO's registry (docs here)
  3. Let your provider (DO) take care of the server stuff - you give them the image, they provision servers for you. Other providers like Google Cloud Platform or Amazon AWS also provide similar solutions to this. In the Digital Ocean admin panel, you can find in under Create > App

There are, of course, other options. Since you've mentioned that you already have a DO droplet ready, you could run the container there easily. The solution I provided is just one of your options. Additionaly, if you need things like a database, a caching solution like Redis etc., you might find settings things up yourself more cost-effective. Especially since it sounds like you're new to this and your app isn't a very large project. Most importantly, don't let this answer scare you from setting up your deployment yourself on your droplet - that definitely is also a very viable solution.

Upvotes: 2

Related Questions