Skip to content

Conversation

CalvoM
Copy link
Owner

@CalvoM CalvoM commented Aug 13, 2025

Closes #14

Summary by Sourcery

Dockerize the application with container orchestration, introduce production-ready server setup, and include a new database migration

New Features:

  • Add Dockerfiles for backend and frontend builds and a .dockerignore file
  • Introduce Docker Compose setup to orchestrate PostgreSQL, Redis, RabbitMQ, Django web, Celery worker, and Nginx services

Enhancements:

  • Add a Django migration to alter TaskResult.stage field choices

Deployment:

  • Add Docker Compose configuration with volumes, networks, and service dependencies

Chores:

  • Update project description in pyproject.toml

Copy link

sourcery-ai bot commented Aug 13, 2025

Reviewer's Guide

This PR fully dockerizes the application by introducing multistage Dockerfiles for backend and frontend, a comprehensive docker-compose stack with healthchecks and Nginx proxy, container entrypoint scripts, dependency updates, and a new Django migration.

Sequence diagram for service startup and healthcheck dependencies

sequenceDiagram
  participant nginx
  participant django-web-frontend
  participant django-web-backend
  participant pg_server
  participant cache
  participant rabbitmq_server
  participant celery-worker
  nginx->>django-web-backend: Wait for healthy
  nginx->>django-web-frontend: Wait for healthy
  django-web-frontend->>django-web-backend: Wait for healthy
  django-web-backend->>pg_server: Wait for healthy
  django-web-backend->>cache: Wait for healthy
  django-web-backend->>rabbitmq_server: Wait for healthy
  celery-worker->>django-web-backend: Wait for healthy
  celery-worker->>pg_server: Wait for healthy
  celery-worker->>cache: Wait for started
  celery-worker->>rabbitmq_server: Wait for healthy
Loading

Class diagram for Dockerfile-based backend entrypoint scripts

classDiagram
  class web_entry.sh {
    +activate venv
    +makemigrations
    +migrate
    +import_chess_openings
    +start gunicorn
  }
  class celery_entry.sh {
    +activate venv
    +start celery worker
  }
Loading

File-Level Changes

Change Details Files
Enhance docker-compose setup with new services and healthchecks
  • Add healthcheck blocks for RabbitMQ and Redis
  • Define python backend and frontend services with depends_on and restart policies
  • Introduce Celery worker and Nginx services with appropriate networking and volumes
  • Declare additional named volumes for data persistence
docker-compose.yml
Add multistage Dockerfiles for backend and frontend builds
  • Configure builder and slim runtime stages with caching for Python dependencies
  • Include UV binary and optimize Python installs via uv
  • Expose application ports and define runtime healthcheck
Dockerfile
Dockerfile.frontend
Introduce container entrypoint scripts
  • Create web_entry.sh to run migrations, import data, and launch Gunicorn
  • Create celery_entry.sh to start Celery worker with optimized flags
  • Add .dockerignore to exclude unnecessary files from build contexts
web_entry.sh
celery_entry.sh
.dockerignore
Configure Nginx as reverse proxy for web services
  • Define upstream pointing to Django backend
  • Implement rewrite rules and proxy_pass for API routes
  • Serve frontend assets with try_files fallback
nginx/default.conf
Update Python project dependencies
  • Add gunicorn to requirements.txt with pinned hashes
  • Include gunicorn in pyproject.toml dependencies
  • Update project description in pyproject.toml
requirements.txt
pyproject.toml
Fix frontend build script
  • Adjust npm build script invocation syntax in package.json
frontend/package.json
Add new Django migration altering TaskResult stage field choices
  • Add migration 0014 to update stage choices and default value
style_predictor/migrations/0014_alter_taskresult_stage.py

Assessment against linked issues

Issue Objective Addressed Explanation
#14 Create a Docker image for the backend.
#14 Create a Docker image for the frontend.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • You’ve added empty .dockerignore and Dockerfile.frontend files—either populate them with the appropriate ignore rules and frontend build steps or remove them until you’re ready to avoid build failures.
  • The volumes media_files and static_files are declared but not mounted by any service—either remove them or wire them up if you intend to persist uploads and static assets.
  • The custom 'develop' section in the django-web-backend service isn’t a standard Docker Compose field; consider moving those development-specific mounts into a compose override file (docker-compose.override.yml) for better compatibility.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- You’ve added empty .dockerignore and Dockerfile.frontend files—either populate them with the appropriate ignore rules and frontend build steps or remove them until you’re ready to avoid build failures.
- The volumes media_files and static_files are declared but not mounted by any service—either remove them or wire them up if you intend to persist uploads and static assets.
- The custom 'develop' section in the django-web-backend service isn’t a standard Docker Compose field; consider moving those development-specific mounts into a compose override file (docker-compose.override.yml) for better compatibility.

## Individual Comments

### Comment 1
<location> `docker-compose.yml:30` </location>
<code_context>
       - RABBITMQ_DEFAULT_USER=${RABBITMQ_DEFAULT_USER} # Load from .env
       - RABBITMQ_DEFAULT_PASS=${RABBITMQ_DEFAULT_PASS} # Load from .env
     restart: unless-stopped
+    healthcheck:
+      test: rabbitmq-diagnostics -q ping
+      interval: 30s
+      timeout: 30s
+      retries: 3
     volumes:
       - rabbitmqdata:/var/lib/rabbitmq/
</code_context>

<issue_to_address>
Healthcheck for RabbitMQ uses rabbitmq-diagnostics, which may not be present in all images.

Verify that the image includes rabbitmq-diagnostics, or switch to a more universally available healthcheck command like rabbitmqctl or a TCP check to ensure reliability.
</issue_to_address>

### Comment 2
<location> `nginx/default.conf:14` </location>
<code_context>
+  location ^~ /server/ {
+      rewrite ^/server/(.*) /api/v1/$1 break;
+      proxy_pass http://gunicorn;
+      error_page 405   =200 $uri;
+}
+location / {
</code_context>

<issue_to_address>
Returning 200 for 405 errors may mask underlying issues.

Returning 200 for 405 errors can obscure real issues and complicate debugging. Please confirm if this behavior is intentional for all affected endpoints.
</issue_to_address>

### Comment 3
<location> `web_entry.sh:10` </location>
<code_context>
+python manage.py import_chess_openings
+
+# exec python manage.py runserver 0.0.0.0:8000
+exec gunicorn my_chess_style.wsgi -b 0.0.0.0:8000
</code_context>

<issue_to_address>
Gunicorn is used for serving Django, but no worker configuration is specified.

Specify worker count and timeout for Gunicorn to improve performance and stability under load.
</issue_to_address>

### Comment 4
<location> `celery_entry.sh:6` </location>
<code_context>
+
+. /app/.venv/bin/activate
+
+exec celery -A my_chess_style worker --loglevel=info --without-heartbeat --without-gossip --without-mingle --concurrency=4 -E
</code_context>

<issue_to_address>
Celery worker concurrency is hardcoded to 4.

Recommend using an environment variable for concurrency to allow flexibility across deployments.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@CalvoM CalvoM merged commit 1131445 into main Aug 13, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create Docker image of the project.

1 participant