Skip to content

Commit 3654296

Browse files
committed
refactor: Makefile used instead of bash script to make development environment.
1 parent 4e9dbaa commit 3654296

4 files changed

Lines changed: 49 additions & 39 deletions

File tree

Makefile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
.PHONY: db wait-db ensure-db rabbit web-stop migrate dev help
2+
3+
help: ## List available targets
4+
@grep -E '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) \
5+
| awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-10s\033[0m %s\n", $$1, $$2}'
6+
7+
db: ## Remove old standalone postgres, then start Compose db
8+
@echo "🛑 Removing old 'postgres' container if it exists…"
9+
@docker ps --filter "name=postgres$$" -q | xargs -r docker rm -f >/dev/null 2>&1 || true
10+
@echo "🔍 Starting 'db' service via Compose…"
11+
@docker compose up -d db
12+
13+
wait-db: ## Wait until Postgres accepts connections
14+
@echo "⏳ Waiting for Postgres to be ready…"
15+
@until docker compose exec db pg_isready -U postgres >/dev/null 2>&1; do \
16+
sleep 1; \
17+
done
18+
@echo "✅ Postgres is accepting connections."
19+
20+
ensure-db: ## Create taskflow DB if it doesn’t already exist
21+
@echo "🔧 Ensuring database 'taskflow' exists…"
22+
@docker compose exec db \
23+
psql -U postgres -tc "SELECT 1 FROM pg_database WHERE datname='taskflow';" \
24+
| grep -q 1 \
25+
&& echo "✅ 'taskflow' already exists." \
26+
|| (echo "🚀 Creating 'taskflow'…" \
27+
&& docker compose exec db psql -U postgres -c "CREATE DATABASE taskflow;")
28+
@echo "✅ Database is ready."
29+
30+
rabbit: ## Start RabbitMQ service
31+
@echo "🔍 Starting 'rabbitmq' service…"
32+
@docker compose up -d rabbitmq
33+
34+
web-stop: ## Stop & remove the web container
35+
@echo "🛑 Stopping & removing 'web'…"
36+
@docker compose stop web >/dev/null 2>&1 || true
37+
@docker compose rm -f web >/dev/null 2>&1 || true
38+
39+
migrate: ## Run Django migrations
40+
@echo "🔄 Applying Django migrations…"
41+
@python3 manage.py migrate
42+
43+
44+
# ------------------------ RUN EVERYTHING ------------------------
45+
46+
dev: db wait-db ensure-db rabbit web-stop migrate ## Bootstrap everything
47+
@echo "✅ Ready for dev! Run: python manage.py runserver"

README.md

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,7 @@ pip install -r requirements.txt
6060
```
6161

6262
### 🔧 2. Configure Environment
63-
Edit the `.env` file:
64-
```dotenv
65-
DEBUG=True
66-
SECRET_KEY=your-secret-key
67-
DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1,[::1]
68-
69-
POSTGRES_DB=taskflow
70-
POSTGRES_USER=postgres
71-
POSTGRES_PASSWORD=postgres
72-
POSTGRES_HOST=localhost
73-
POSTGRES_PORT=5432
74-
75-
CELERY_BROKER_URL=amqp://guest:guest@localhost:5672//
76-
```
63+
Copy the `.env.example` file and rename it to `.env` .
7764

7865
---
7966

@@ -82,7 +69,7 @@ CELERY_BROKER_URL=amqp://guest:guest@localhost:5672//
8269
Run Django and Celery locally. Use Docker for DB & RabbitMQ only.
8370

8471
```bash
85-
./start-dev-services.sh # Start db + rabbitmq only
72+
make dev # using Makefile to create development envionment
8673
python manage.py runserver # Run Django locally
8774
celery -A taskflow_api worker --loglevel=info # Start Celery
8875
```

docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: '3.9'
2-
31
services:
42
web:
53
build: .

start-dev-services.sh

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)