Skip to content

Commit 460b384

Browse files
put shell code in fences
0 parents  commit 460b384

38 files changed

+1355
-0
lines changed

.devcontainer/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM mcr.microsoft.com/devcontainers/python:3.12-bookworm

.devcontainer/devcontainer.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"build": {
3+
"dockerfile": "Dockerfile",
4+
"context": ".."
5+
},
6+
"features": {
7+
"ghcr.io/defanglabs/devcontainer-feature/defang-cli:1.0.4": {},
8+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
9+
"ghcr.io/devcontainers/features/aws-cli:1": {}
10+
}
11+
}

.github/workflows/deploy.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
environment: playground
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
id-token: write
15+
16+
steps:
17+
- name: Checkout Repo
18+
uses: actions/checkout@v4
19+
20+
- name: Deploy
21+
uses: DefangLabs/[email protected]
22+
with:
23+
config-env-vars: DJANGO_SECRET_KEY POSTGRES_PASSWORD SSL_MODE
24+
env:
25+
DJANGO_SECRET_KEY: ${{ secrets.DJANGO_SECRET_KEY }}
26+
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
27+
SSL_MODE: ${{ secrets.SSL_MODE }}

.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Python
2+
__pycache__/
3+
*.pyc
4+
*.pyo
5+
*.pyd
6+
.Python
7+
env/
8+
venv/
9+
ENV/
10+
build/
11+
develop-eggs/
12+
dist/
13+
downloads/
14+
eggs/
15+
.eggs/
16+
lib/
17+
lib64/
18+
parts/
19+
sdist/
20+
var/
21+
*.egg-info/
22+
.installed.cfg
23+
*.egg
24+
25+
# Django
26+
*.log
27+
staticfiles/
28+
media/
29+
db.sqlite3
30+
31+
# Node
32+
node_modules/
33+
.next/
34+
.env
35+
36+
# Docker
37+
pgdata/

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Crew.ai Django Sample
2+
3+
[![1-click-deploy](https://raw.githubusercontent.com/DefangLabs/defang-assets/main/Logos/Buttons/SVG/deploy-with-defang.svg)](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-crew-django-redis-postgres-template%26template_owner%3DDefangSamples)
4+
5+
This sample shows how to use Crew.ai with a Django application. It provides a simple web interface that allows users to input text and receive a summary of the text in real-time using Django Channels with a Redis broker. It uses Celery to handle the Crew.ai tasks in the background with Redis as a broker. It uses Postgres as the database for Django.
6+
7+
## Prerequisites
8+
9+
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
10+
2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
11+
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)
12+
13+
## Development
14+
15+
To run the application locally, you can use the following command:
16+
17+
```bash
18+
docker compose -f ./compose.local.yaml up --build
19+
```
20+
21+
## Configuration
22+
23+
For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration):
24+
25+
> Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
26+
27+
### `POSTGRES_PASSWORD`
28+
The password for the Postgres database.
29+
```bash
30+
defang config set POSTGRES_PASSWORD
31+
```
32+
33+
### `SSL_MODE`
34+
35+
The SSL mode for the Postgres database.
36+
```bash
37+
defang config set SSL_MODE
38+
```
39+
40+
### `DJANGO_SECRET_KEY`
41+
42+
The secret key for the Django application.
43+
```bash
44+
defang config set DJANGO_SECRET_KEY
45+
```
46+
47+
## Deployment
48+
49+
> [!NOTE]
50+
> Download [Defang CLI](https://github.com/DefangLabs/defang)
51+
52+
### Defang Playground
53+
54+
Deploy your application to the Defang Playground by opening up your terminal and typing:
55+
```bash
56+
defang compose up
57+
```
58+
59+
### BYOC
60+
61+
If you want to deploy to your own cloud account, you can [use Defang BYOC](https://docs.defang.io/docs/tutorials/deploy-to-your-cloud).
62+
63+
---
64+
65+
Title: Crew.ai Django Sample
66+
67+
Short Description: A sample application that uses Crew.ai to summarize text in a background task, streamed to the user in real-time.
68+
69+
Tags: Django, Celery, Redis, Postgres, AI, ML
70+
71+
Languages: Python

app/.dockerignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Default .dockerignore file for Defang
2+
**/__pycache__
3+
**/.direnv
4+
**/.DS_Store
5+
**/.envrc
6+
**/.git
7+
**/.github
8+
**/.idea
9+
**/.next
10+
**/.vscode
11+
**/compose.*.yaml
12+
**/compose.*.yml
13+
**/compose.yaml
14+
**/compose.yml
15+
**/docker-compose.*.yaml
16+
**/docker-compose.*.yml
17+
**/docker-compose.yaml
18+
**/docker-compose.yml
19+
**/node_modules
20+
**/Thumbs.db
21+
Dockerfile
22+
*.Dockerfile
23+
# Ignore our own binary, but only in the root to avoid ignoring subfolders
24+
defang
25+
defang.exe
26+
# Ignore our project-level state
27+
.defang

app/Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Dockerfile for Django API/Worker
2+
FROM python:3.11-slim
3+
4+
# install curl
5+
RUN apt-get update && apt-get install -y curl \
6+
&& rm -rf /var/lib/apt/lists/*
7+
8+
ENV PYTHONDONTWRITEBYTECODE 1
9+
ENV PYTHONUNBUFFERED 1
10+
WORKDIR /app
11+
12+
COPY requirements.txt ./
13+
RUN pip install --upgrade pip && pip install -r requirements.txt
14+
15+
COPY . .
16+
17+
RUN python manage.py collectstatic --noinput
18+
19+
RUN chmod +x run.sh
20+
21+
CMD ["./run.sh"]

app/config/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .celery import app as celery_app
2+
3+
__all__ = ("celery_app",)

app/config/asgi.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
ASGI config for config project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from channels.routing import ProtocolTypeRouter, URLRouter
13+
from django.core.asgi import get_asgi_application
14+
from channels.auth import AuthMiddlewareStack
15+
import os
16+
17+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
18+
19+
import core.routing
20+
21+
application = ProtocolTypeRouter({
22+
"http": get_asgi_application(),
23+
"websocket": AuthMiddlewareStack(
24+
URLRouter(
25+
core.routing.websocket_urlpatterns
26+
)
27+
),
28+
})

app/config/celery.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import os
2+
from celery import Celery
3+
4+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
5+
6+
app = Celery("config")
7+
app.config_from_object("django.conf:settings", namespace="CELERY")
8+
app.autodiscover_tasks()

0 commit comments

Comments
 (0)