feat(dev): Enable hot reloading and streamline local development

This commit significantly improves the local development experience by enabling hot reloading for the Django application. This is achieved by installing the project as an editable package within the Docker services.

Key changes:

- **Hot Reloading:**
    - Modified `docker-compose.yml` for `web` and `celery` services to use `uv pip install --editable . --no-deps`.
    - Mounted the project root (`./`) to `/code` in `web` and `celery` services to facilitate the editable install.
- **Docker & Build Enhancements:**
    - Added `uv` binary to stage-1 in the `Dockerfile` for faster package operations.
    - Adjusted file permissions in `Dockerfile` during the app copy.
    - Set `DEBUG=true` for the `web` service in `docker-compose.yml` for easier local debugging.
    - Changed `restart` policy to `unless-stopped` for `web` and `celery` dev services.
    - Added a healthcheck for the `redis` service in the dev `docker-compose.yml`.
- **Code & Script Cleanup:**
    - Removed the custom `HealthCheckView` from the `home` app, as health checks are now handled by django-health-checks.
    - Updated paths and commands in `scripts/entrypoint.sh`, `scripts/prebuild.sh`, and `scripts/reset-db_make-migrations_seed-data.sh` to align with the new setup and remove obsolete steps (e.g., db cache table creation; we now use redis).
This commit is contained in:
badblocks 2025-05-23 21:19:33 -07:00
parent 02f23dba28
commit 51de3c7a6d
No known key found for this signature in database
7 changed files with 28 additions and 48 deletions

View file

@ -1,30 +1,41 @@
services:
web:
build: .
#command: ["django-admin", "runserver", "0.0.0.0:8000"]
command: bash -c "cd /code && uv pip install --editable . --no-deps && python manage.py runserver 0.0.0.0:8000"
ports:
- 8000:8000
restart: always
- "8000:8000"
restart: unless-stopped
environment:
- DEBUG=true
volumes:
- ./seed:/seed:ro
# DANGEROUS DUE TO DOCKERFILE PACKAGE BUILDING/INSTALLATION
# will need to use editable package instead somehow
#- ./src/pkmntrade_club:/app/lib/python3.12/site-packages/pkmntrade_club:ro
- ./:/code
depends_on:
db:
condition: service_healthy
redis:
condition: service_started
celery:
build: .
command: ["celery", "-A", "pkmntrade_club.django_project", "worker", "-l", "INFO", "-B", "-E"]
restart: always
command: bash -c "cd /code && uv pip install --editable . --no-deps && celery -A pkmntrade_club.django_project worker -l INFO -B -E"
restart: unless-stopped
volumes:
- ./:/code
depends_on:
db:
condition: service_healthy
redis:
condition: service_started
redis:
image: redis:latest
restart: always
ports:
- 6379:6379
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
db:
image: postgres:16
restart: always
@ -37,6 +48,5 @@ services:
interval: 10s
timeout: 5s
retries: 5
volumes:
postgres_data: