Skip to content

Commit df8b779

Browse files
authored
Merge pull request #2 from omidcodes/002-dockerize-the-project
Add docker-compose file
2 parents dc0c3ad + e1031cf commit df8b779

8 files changed

Lines changed: 113 additions & 31 deletions

File tree

.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
__pycache__/
2+
*.pyc
3+
*.pyo
4+
*.pyd
5+
env/
6+
build/
7+
static/

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,7 @@ cython_debug/
172172

173173
# PyPI configuration file
174174
.pypirc
175+
176+
177+
# vscode
178+
.vscode

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Dockerfile
2+
3+
FROM python:3.12-slim
4+
5+
ENV PYTHONDONTWRITEBYTECODE 1
6+
ENV PYTHONUNBUFFERED 1
7+
8+
# Set work directory
9+
WORKDIR /app
10+
11+
# Install dependencies
12+
COPY requirements.txt .
13+
RUN pip install --upgrade pip && pip install -r requirements.txt
14+
15+
# Copy project files
16+
COPY . .
17+
18+
# Collect static files (optional if using admin panel)
19+
RUN mkdir -p /vol/web/static
20+
21+
CMD ["gunicorn", "taskflow_api.wsgi:application", "--bind", "0.0.0.0:8000"]

docker-compose.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
services:
2+
web:
3+
build: .
4+
command: gunicorn taskflow_api.wsgi:application --bind 0.0.0.0:8000
5+
volumes:
6+
- .:/app
7+
ports:
8+
- "8000:8000"
9+
depends_on:
10+
- db
11+
- rabbitmq
12+
environment:
13+
- DEBUG=1
14+
- DJANGO_SETTINGS_MODULE=taskflow_api.settings
15+
- POSTGRES_DB=taskflow
16+
- POSTGRES_USER=postgres
17+
- POSTGRES_PASSWORD=postgres
18+
- POSTGRES_HOST=db
19+
- POSTGRES_PORT=5432
20+
21+
db:
22+
image: postgres
23+
restart: always
24+
environment:
25+
POSTGRES_DB: taskflow
26+
POSTGRES_USER: postgres
27+
POSTGRES_PASSWORD: postgres
28+
ports:
29+
- "5432:5432"
30+
31+
rabbitmq:
32+
image: rabbitmq:management
33+
ports:
34+
- "5672:5672"
35+
- "15672:15672"

requirements.txt

80 Bytes
Binary file not shown.

run_server.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
docker compose down
2+
docker compose build --no-cache
3+
docker compose up

start-dev-services.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
echo "🔍 Checking PostgreSQL container..."
4+
POSTGRES_STATUS=$(docker compose ps --status=running db | grep 'db' || true)
5+
6+
echo "🔍 Checking RabbitMQ container..."
7+
RABBITMQ_STATUS=$(docker compose ps --status=running rabbitmq | grep 'rabbitmq' || true)
8+
9+
if [[ -z "$POSTGRES_STATUS" || -z "$RABBITMQ_STATUS" ]]; then
10+
echo "🚀 Starting db and rabbitmq services..."
11+
docker compose up -d db rabbitmq
12+
else
13+
echo "✅ db and rabbitmq are already running."
14+
fi
15+
16+
echo "🛑 Ensuring web container is stopped..."
17+
docker compose stop web >/dev/null 2>&1 || true
18+
docker compose rm -f web >/dev/null 2>&1 || true
19+
20+
python3 manage.py migrate
21+
22+
echo "✅ Ready for local development. Run: python manage.py runserver"

taskflow_api/settings.py

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
1-
"""
2-
Django settings for taskflow_api project.
3-
4-
Generated by 'django-admin startproject' using Django 5.2.1.
5-
6-
For more information on this file, see
7-
https://docs.djangoproject.com/en/5.2/topics/settings/
8-
9-
For the full list of settings and their values, see
10-
https://docs.djangoproject.com/en/5.2/ref/settings/
11-
"""
12-
1+
import os
132
from pathlib import Path
3+
from decouple import config, Csv
144

155
# Build paths inside the project like this: BASE_DIR / 'subdir'.
166
BASE_DIR = Path(__file__).resolve().parent.parent
@@ -19,14 +9,6 @@
199
# Quick-start development settings - unsuitable for production
2010
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
2111

22-
# SECURITY WARNING: keep the secret key used in production secret!
23-
SECRET_KEY = 'django-insecure-%ih9li)=no$9s=93us((337b-79ya*%psbm)=0(csy^$c*qg%^'
24-
25-
# SECURITY WARNING: don't run with debug turned on in production!
26-
DEBUG = True
27-
28-
ALLOWED_HOSTS = []
29-
3012

3113
# Application definition
3214

@@ -79,17 +61,6 @@
7961
WSGI_APPLICATION = 'taskflow_api.wsgi.application'
8062

8163

82-
# Database
83-
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
84-
85-
DATABASES = {
86-
'default': {
87-
'ENGINE': 'django.db.backends.sqlite3',
88-
'NAME': BASE_DIR / 'db.sqlite3',
89-
}
90-
}
91-
92-
9364
# Password validation
9465
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators
9566

@@ -137,3 +108,22 @@
137108
# MANUALLY ADDED
138109

139110
CORS_ALLOW_ALL_ORIGINS = True
111+
112+
113+
DEBUG = config('DEBUG', default=False, cast=bool)
114+
SECRET_KEY = config('SECRET_KEY', default='unsafe-dev-key')
115+
116+
ALLOWED_HOSTS = config('DJANGO_ALLOWED_HOSTS', cast=Csv(), default='localhost')
117+
118+
DATABASES = {
119+
'default': {
120+
'ENGINE': 'django.db.backends.postgresql',
121+
'NAME': config('POSTGRES_DB', default='taskflow'),
122+
'USER': config('POSTGRES_USER', default='postgres'),
123+
'PASSWORD': config('POSTGRES_PASSWORD', default='postgres'),
124+
'HOST': config('POSTGRES_HOST', default='localhost'),
125+
'PORT': config('POSTGRES_PORT', default='5432'),
126+
}
127+
}
128+
129+
CELERY_BROKER_URL = config('CELERY_BROKER_URL', default='amqp://guest:guest@localhost:5672//')

0 commit comments

Comments
 (0)