Report this

What is the reason for this report?

How to use Django with Celery+Reds within DO App Platform?

Posted on March 11, 2022

On my local machine, I have a very simple proof of concept that uses docker-compose to run Django in one container, Redis in a second container, and a Celery worker in a third container. It “works on my machine”.

How do I deploy this to DigitalOcean? How do I implement blue/green deployment using DigitalOcean assets?

For a Django application, without Celery and Redis, it seems straightforward. I can build, tag, and push the Django container into the DO registry, and then use doctl to deploy my application, update environment variables, and switch the floating IP between the green and blue servers. Great.

docker build -t <container> .
docker tag <container>:latest registry.digitalocean.com/<repo>/<container>:latest
docker push registry.digitalocean.com/<repo>/<container>:latest
doctl apps create-deployment <app-id>
doctl apps update <app-id> --spec <prod.yaml>
doctl compute floating-ip-action assign <floating-ip> <new-prod-droplet-id>

Now how do I set up Celery and Redis? I know I can stand up a Redis DB cluster, but do I need a separate droplet to run the Celery worker? Or is there a way to run the Celery worker from the same compute resource as my containerized Django app? What’s the best practice here?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

This seems like a great setup. I would personally go for a managed Redis Cluster just so that you don’t have to manage it yourself on a separate Droplet.

Regarding the Celery service, as this is just a POC, you could deploy the Celery container on the same Droplet as your Django app.

If you are not deploying on a Droplet but the App Platform itself, then you could add the Celery service as a worker:

https://docs.digitalocean.com/products/app-platform/how-to/manage-workers/

To do that, you would just have to update your prod.yaml file and include the Celery service as a component to your Django App.

Hope that this helps!

Best,

Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.