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

View file

@ -63,10 +63,14 @@ RUN pip install playwright && \
# Copy source code # Copy source code
COPY . . 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 # Prevent uvloop compatibility issues
ENV PYTHONPATH=/app ENV PYTHONPATH=/app
ENV UVICORN_LOOP=asyncio ENV UVICORN_LOOP=asyncio
# Run # Run
EXPOSE 8000 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 $?