From 31fe69535c9226a33db055da6dfab908f8203dac Mon Sep 17 00:00:00 2001 From: yuangyaa Date: Sun, 17 Aug 2025 02:46:54 +0800 Subject: [PATCH] Support docker --- docker-compose.yml | 139 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..95893b1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,139 @@ +version: '3.8' + +services: + # PostgreSQL数据库 + db: + image: postgres:15 + environment: + POSTGRES_DB: green_classroom + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + volumes: + - postgres_data:/var/lib/postgresql/data + ports: + - "5432:5432" + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 30s + timeout: 10s + retries: 3 + + # Redis缓存和消息队列 + redis: + image: redis:7-alpine + ports: + - "6379:6379" + volumes: + - redis_data:/data + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 30s + timeout: 10s + retries: 3 + + # Django Web应用 + web: + build: . + command: runserver + environment: + - DEBUG=False + - DB_ENGINE=django.db.backends.postgresql + - DB_NAME=green_classroom + - DB_USER=postgres + - DB_PASSWORD=postgres + - DB_HOST=db + - DB_PORT=5432 + - REDIS_URL=redis://redis:6379/0 + - CELERY_BROKER_URL=redis://redis:6379/0 + - CELERY_RESULT_BACKEND=redis://redis:6379/0 + - SECRET_KEY=your-production-secret-key-here + - ALLOWED_HOSTS=localhost,127.0.0.1 + volumes: + - ./date/media:/app/date/media + - ./logs:/app/logs + ports: + - "8000:8000" + depends_on: + db: + condition: service_healthy + redis: + condition: service_healthy + restart: unless-stopped + + # Celery Worker + celery: + build: . + command: celery + environment: + - DEBUG=False + - DB_ENGINE=django.db.backends.postgresql + - DB_NAME=green_classroom + - DB_USER=postgres + - DB_PASSWORD=postgres + - DB_HOST=db + - DB_PORT=5432 + - REDIS_URL=redis://redis:6379/0 + - CELERY_BROKER_URL=redis://redis:6379/0 + - CELERY_RESULT_BACKEND=redis://redis:6379/0 + - SECRET_KEY=your-production-secret-key-here + volumes: + - ./date/media:/app/date/media + - ./logs:/app/logs + depends_on: + db: + condition: service_healthy + redis: + condition: service_healthy + restart: unless-stopped + + # Celery Beat (定时任务) + celery-beat: + build: . + command: celery-beat + environment: + - DEBUG=False + - DB_ENGINE=django.db.backends.postgresql + - DB_NAME=green_classroom + - DB_USER=postgres + - DB_PASSWORD=postgres + - DB_HOST=db + - DB_PORT=5432 + - REDIS_URL=redis://redis:6379/0 + - CELERY_BROKER_URL=redis://redis:6379/0 + - CELERY_RESULT_BACKEND=redis://redis:6379/0 + - SECRET_KEY=your-production-secret-key-here + volumes: + - ./date/media:/app/date/media + - ./logs:/app/logs + depends_on: + db: + condition: service_healthy + redis: + condition: service_healthy + restart: unless-stopped + + # Flower (Celery监控) + flower: + build: . + command: flower + environment: + - DEBUG=False + - DB_ENGINE=django.db.backends.postgresql + - DB_NAME=green_classroom + - DB_USER=postgres + - DB_PASSWORD=postgres + - DB_HOST=db + - DB_PORT=5432 + - REDIS_URL=redis://redis:6379/0 + - CELERY_BROKER_URL=redis://redis:6379/0 + - CELERY_RESULT_BACKEND=redis://redis:6379/0 + - SECRET_KEY=your-production-secret-key-here + ports: + - "5555:5555" + depends_on: + - redis + restart: unless-stopped + +volumes: + postgres_data: + redis_data: