#best practices for deploying FastAPI, Redis and RQ workers?

1 messages · Page 1 of 1 (latest)

heavy bone
#

I have deployed a FastAPI server and a RQ Worker in separate containers on Railway based on the same monorepo: https://github.com/kristiankauffeld/fastapi-redis

The repo is structured by separating the services into different directories where they have their own Dockerfile. The two services communicate through a Redis instance.

Currently there is some code duplication since I have copied the "utils" folder both into the "api" and the "rq-worker" folder. So if anyone perhaps could share some insight whether there is a better approach to deploy an application like this.

Thanks

GitHub

Contribute to kristiankauffeld/fastapi-redis development by creating an account on GitHub.

limber dewBOT
#

Project ID: eed3718a-5d34-41b6-87e6-0d476ca1cc53

heavy bone
#

eed3718a-5d34-41b6-87e6-0d476ca1cc53

heavy bone
#

Specifically I'm interested in knowing if it's possible for me to just have a single Dockerfile in the root of the repository instead of having almost identical dockerfiles in the "api" and "rq-worker" folders where the only difference is the last CMD instruction

#

so to reduce code duplication

heavy bone
halcyon totem
#

can you send me your two Dockerfiles

heavy bone
halcyon totem
#

why not deploy from the root of the repo, with the same dockerfile for both services just set the applicable start command in each service settings

heavy bone
#

let me try

#

so now the repo only contains a single Dockerfile in the root of the project, but Nixpacks build fails with error: "No start command could be found".

halcyon totem
#

nixpacks isnt used when theres a dockerfile, you have something misconfigured somewhere

stoic walrus
heavy bone
#

omg I just realized haha

stoic walrus
#

if you’re using a dockerfile you shouldn’t need either, but just pointing out

heavy bone
#

@stoic walrus but I am trying to figure out how to start both the FastAPI and the RQ Worker using a single Dockerfile in the root project

halcyon totem
#

a custom start command is needed for that yes

heavy bone
#

the FastAPI deploy now logs the error "Invalid value for '--port': '$PORT' is not a valid integer."

#

should I just ignore the "buildCommand is only supported for the Nixpakcs builder" warning?

halcyon totem
heavy bone
#

uvicorn api.src.main:app --host 0.0.0.0 --port $PORT

halcyon totem
#

set the start command to

/bin/sh -c "uvicorn api.src.main:app --host 0.0.0.0 --port $PORT"
heavy bone
#

thx @halcyon totem ! now the FastAPI server is up and running

halcyon totem
#

awsome

heavy bone
#

but still having issues with the RQ Worker container. The deployment logs the error: "ValueError: Redis URL must specify one of the following schemes (redis://, rediss://, unix://)".

I'm using this custom start command: rq worker --url $REDIS_URL

#

is the solution the same?

halcyon totem
#

yep

#

without wrapping the command in a shell the environment variables arent escaped so the command would see the literal string $REDIS_URL or $PORT and of course those literal strings are not a valid redis url or a valid port

heavy bone
#

that makes sense

#

now the whole application works. Thanks again @halcyon totem !

halcyon totem
#

no problem!