W
Wasp-lang•4mo ago
ArjunSohur

Deploying Wasp/fastapi on Digital Ocean

My project is mostly wasp (react/node), but it involves some api calls to fastapi where I have some NLP functionality built in python. I'm almost done locally, but I want to deploy on Digital Ocean because of it's flexible pricing tiers.
I've already dockerized fastapi, and I'm wondering what else I'd need to do to make deployment easier. Do I need to now dockerize both wasp and fastapi together? Is wasp already dockerized? I'm new to webdev in general to feel free to assume I know nothing.
5 Replies
kapa.ai
kapa.ai•4mo ago
Hi @ArjunSohur. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Deploying a Wasp app involves several steps, and it's great that you've already dockerized your FastAPI application. Here's a general guide on how you can proceed with deploying your Wasp app: 1. Generating Deployable Code: You can generate deployable code for your Wasp app by running the command wasp build in your terminal. This will generate the code for the whole app in the .wasp/build/ directory. Note that if you're using SQLite as a database, you'll need to switch to PostgreSQL before deploying to production [source (https://wasp-lang.dev/docs/advanced/deployment/manually#deploying-a-wasp-app)]. 2. Deploying the API Server (backend): Wasp provides a Dockerfile that defines an image for building the server in the .wasp/build directory. To run the server in production, you can deploy this Docker image to a hosting provider like Digital Ocean and ensure the required environment variables on the provider are correctly set up [source (https://wasp-lang.dev/docs/advanced/deployment/manually#deploying-a-wasp-app)]. 3. Deploying the Web Client (frontend): To build the web app, you need to position yourself in the .wasp/build/web-app directory and run npm install && REACT_APP_API_URL=<url_to_wasp_backend> npm run build. This will build the web client and put it in the build/ directory in the web-app directory. Since the app's frontend is just a bunch of static files, you can deploy it to any static hosting provider [source (https://wasp-lang.dev/docs/advanced/deployment/manually#3-deploying-the-web-client-frontend)]. 4. Deploying the Database: Any PostgreSQL database will do, as long as you provide the server with the correct DATABASE_URL env var and ensure that the database is accessible from the server [source (https://wasp-lang.dev/docs/advanced/deployment/manually#4-deploying-the-database)]. As for your FastAPI application, you can deploy it separately and have your Wasp app make API calls to it. There's a discussion on the Wasp Discord channel about running a Python program alongside a Wasp app, which might be helpful for your case [source (https://discord.com/channels/686873244791210014/1204014940512452639)]. Remember, deploying to a new environment can be tricky, so take your time to understand each step. Good luck with your deployment! ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @ArjunSohur, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
ArjunSohur
ArjunSohurOP•4mo ago
Thanks @kapa.ai , I can put the fastapi and wasp on the same DO droplet, right? Doing so might actually be neccesary for talking to each other now that I think about it...
kapa.ai
kapa.ai•4mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- Yes, you can definitely put both the Wasp and FastAPI applications on the same Digital Ocean droplet. This could indeed simplify communication between the two, especially if they need to talk to each other frequently or if the data they are exchanging is substantial. However, keep in mind that running both applications on the same droplet means they will share the droplet's resources (CPU, memory, etc.). If your applications are resource-intensive, you might need to consider scaling up your droplet or distributing your applications across multiple droplets. Also, remember to properly configure the networking and security settings to ensure that your applications can communicate with each other securely and efficiently. This might involve setting up firewalls, configuring ports, and so on. For deploying your FastAPI application, you can follow the FastAPI deployment guide (https://fastapi.tiangolo.com/deployment/). For deploying your Wasp application, you can follow the Wasp deployment guide (https://wasp-lang.dev/docs/advanced/deployment/manually). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @ArjunSohur, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
miho
miho•4mo ago
It seems like Kapa sent in the right direction. I'll add my two cents 🙂 There are many ways you can use a VPS to deploy your apps: - deploying things directly e.g. installing Python and Node.js and getting your code on the server and just running - it's fine, but it's not repeatable - using Docker (what you plan on doing) - wrap your apps in Docker containers and run them on the server like that - it's nice, you somehow get your code on the server e.g. git clone and then git pull with each change and then manually rebuild the Docker containers - you could go a step further (it's more complex, beware) and use some of the self-hosting tools to help to automate this stuff like Caprover, Coolify or Dokku. What they do: help you rebuild stuff and redeploy stuff when things change. Dokku is the most barebones one - might be a good fit, Caprover is capable, Coolify is the new cool thing. Anyho! In your case, what ever you feel comfortable with setting up will be enough IMHO. You can upgrade your setup later on. I'd probably git clone your repo on the VPS (there will be some SSH keys setting up to do to allow your VPS to get your code IIRC). Then, run wasp build, build the server Docker image in .wasp/build. Build the client Docker image using a Dockerfile like this: https://wasp-lang.dev/docs/advanced/deployment/manually#deploying-the-client Then build your Fastify Docker image. Run all of those images with proper env vars set up. Make sure all the services can communicate with each other - they should be on the same network. Now that you have the Docker containers running - there should be something in front to enable you to use a domain name instead of your VPS IP address. That something is called reverse proxy. Nginx is common, Caddy is newer and simpler. Set it up to reverse-proxy your client at your domain.com and the server at api.domain.com and ... you should be good to go 😄
Deploying Manually | Wasp
This document explains how to build and prepare your Wasp app for deployment.
ArjunSohur
ArjunSohurOP•4mo ago
Thanks, that's super helpful!
Want results from more Discord servers?
Add your server