Merge pull request #429 from MODSetter/dev

fix: reduced docker size by 67%
This commit is contained in:
Rohan Verma 2025-10-23 15:54:07 -07:00 committed by GitHub
commit dc4fe71e77
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 75 additions and 37 deletions

View file

@ -55,43 +55,44 @@ services:
- db
- redis
celery_worker:
build: ./surfsense_backend
# image: ghcr.io/modsetter/surfsense_backend:latest
command: celery -A app.celery_app worker --loglevel=info --concurrency=1 --pool=solo
volumes:
- ./surfsense_backend:/app
- shared_temp:/tmp
env_file:
- ./surfsense_backend/.env
environment:
- DATABASE_URL=postgresql+asyncpg://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres}@db:5432/${POSTGRES_DB:-surfsense}
- CELERY_BROKER_URL=redis://redis:${REDIS_PORT:-6379}/0
- CELERY_RESULT_BACKEND=redis://redis:${REDIS_PORT:-6379}/0
- PYTHONPATH=/app
depends_on:
- db
- redis
- backend
# Run these services seperately in production
# celery_worker:
# build: ./surfsense_backend
# # image: ghcr.io/modsetter/surfsense_backend:latest
# command: celery -A app.celery_app worker --loglevel=info --concurrency=1 --pool=solo
# volumes:
# - ./surfsense_backend:/app
# - shared_temp:/tmp
# env_file:
# - ./surfsense_backend/.env
# environment:
# - DATABASE_URL=postgresql+asyncpg://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres}@db:5432/${POSTGRES_DB:-surfsense}
# - CELERY_BROKER_URL=redis://redis:${REDIS_PORT:-6379}/0
# - CELERY_RESULT_BACKEND=redis://redis:${REDIS_PORT:-6379}/0
# - PYTHONPATH=/app
# depends_on:
# - db
# - redis
# - backend
celery_beat:
build: ./surfsense_backend
# image: ghcr.io/modsetter/surfsense_backend:latest
command: celery -A app.celery_app beat --loglevel=info
volumes:
- ./surfsense_backend:/app
- shared_temp:/tmp
env_file:
- ./surfsense_backend/.env
environment:
- DATABASE_URL=postgresql+asyncpg://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres}@db:5432/${POSTGRES_DB:-surfsense}
- CELERY_BROKER_URL=redis://redis:${REDIS_PORT:-6379}/0
- CELERY_RESULT_BACKEND=redis://redis:${REDIS_PORT:-6379}/0
- PYTHONPATH=/app
depends_on:
- db
- redis
- celery_worker
# celery_beat:
# build: ./surfsense_backend
# # image: ghcr.io/modsetter/surfsense_backend:latest
# command: celery -A app.celery_app beat --loglevel=info
# volumes:
# - ./surfsense_backend:/app
# - shared_temp:/tmp
# env_file:
# - ./surfsense_backend/.env
# environment:
# - DATABASE_URL=postgresql+asyncpg://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres}@db:5432/${POSTGRES_DB:-surfsense}
# - CELERY_BROKER_URL=redis://redis:${REDIS_PORT:-6379}/0
# - CELERY_RESULT_BACKEND=redis://redis:${REDIS_PORT:-6379}/0
# - PYTHONPATH=/app
# depends_on:
# - db
# - redis
# - celery_worker
# flower:
# build: ./surfsense_backend

View file

@ -63,10 +63,14 @@ RUN pip install playwright && \
# Copy source code
COPY . .
# Copy and set permissions for entrypoint script
COPY scripts/docker/entrypoint.sh /app/scripts/docker/entrypoint.sh
RUN chmod +x /app/scripts/docker/entrypoint.sh
# Prevent uvloop compatibility issues
ENV PYTHONPATH=/app
ENV UVICORN_LOOP=asyncio
# Run
EXPOSE 8000
CMD ["python", "main.py", "--reload"]
CMD ["/app/scripts/docker/entrypoint.sh"]

View file

@ -0,0 +1,33 @@
#!/bin/bash
set -e
# Function to handle shutdown gracefully
cleanup() {
echo "Shutting down services..."
kill -TERM "$backend_pid" "$celery_worker_pid" "$celery_beat_pid" 2>/dev/null || true
wait "$backend_pid" "$celery_worker_pid" "$celery_beat_pid" 2>/dev/null || true
exit 0
}
trap cleanup SIGTERM SIGINT
echo "Starting Celery Beat..."
celery -A app.celery_app beat --loglevel=info &
celery_beat_pid=$!
echo "Starting Celery Worker..."
celery -A app.celery_app worker --loglevel=info --concurrency=1 --pool=solo &
celery_worker_pid=$!
echo "Starting FastAPI Backend..."
python main.py --reload &
backend_pid=$!
echo "All services started. PIDs: Backend=$backend_pid, Worker=$celery_worker_pid, Beat=$celery_beat_pid"
# Wait for any process to exit
wait -n
# If we get here, one process exited, so exit with its status
exit $?