Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.idea/
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Critical Blocker: Django 6.0.5 (shown in migration file) requires Python >= 3.12, but this Dockerfile uses Python 3.10. Change to python:3.12-slim to match the Django version.

.vscode/
*.iml
.env
.DS_Store
venv/
.pytest_cache/
**__pycache__/
**db.sqlite3
media
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM python:3.10-slim
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CRITICAL: Django 6.0.5 requires Python >= 3.12, but this image uses python:3.10-slim. Change to python:3.12-slim to match the Django version in requirements.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CRITICAL BLOCKER: Python version mismatch. Django 6.0.5 (from migration file) requires Python >= 3.12, but this Dockerfile uses Python 3.10. This will cause pip install Django==6.0.5 to fail during build. Change to FROM python:3.12-slim.


ENV PYTHONUNBUFFERED=1
WORKDIR /app

COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

COPY . .
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The volume ./:/app will completely overwrite the /app directory where the application was installed by Dockerfile, making COPY operations ineffective. Consider using a subdirectory like ./app:/app/app or named volumes for data persistence.

RUN mkdir -p /app/media
RUN adduser \
--disabled-password \
--no-create-home \
my_user
RUN chown -R my_user /app/media
RUN chmod -R 755 /media
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CRITICAL: Path mismatch. Line 10 creates directory at /app/media, but line 16 chmods /media which doesn't exist. This should be chmod -R 755 /app/media to match the actual media directory location.



USER my_user
Empty file added cinema/management/__init__.py
Empty file.
Empty file.
29 changes: 29 additions & 0 deletions cinema/management/commands/wait_for_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import time
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Critical: Python/Django version mismatch - Django 6.0.5 (mentioned in migration line 1) requires Python >= 3.12, but the Dockerfile uses Python 3.10-slim. Either downgrade Django to 4.x/5.x compatible with Python 3.10, or use Python 3.12+ image.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The Dockerfile uses python:3.10-slim, but the migration files indicate Django 6.0.5 which requires Python >= 3.12. Change this to python:3.12-slim.

from django.core.management.base import BaseCommand
from django.db import connections
from django.db.utils import OperationalError
Comment on lines +1 to +4
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The docker-compose.yaml file is referenced in .dockerignore but not provided in the submitted files. This file is required to verify the complete Docker setup (services, volumes, environment variables, port mappings).

Comment on lines +1 to +4
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The .env file is required by docker-compose.yaml but not provided. Environment variables like POSTGRES_DB, POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_HOST, POSTGRES_PORT are referenced in settings.py but cannot be verified.



class Command(BaseCommand):
Comment on lines +1 to +7
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The requirements.txt file is referenced in Dockerfile line 7 (COPY requirements.txt requirements.txt) but not provided. This file is essential for pip install to work.

"""Wait for db connection"""

def handle(self, *args, **options):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Dockerfile line 10 uses COPY . . which copies everything including potential virtual environments (.venv). The .dockerignore correctly excludes .venv, but ensure all sensitive files (like .env if containing secrets) are also ignored.

self.stdout.write("Checking database connection...")

db_conn = None
attempts = 0
while not db_conn and attempts < 15:
try:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This line chmods /media but the media directory was created at /app/media on line 10. Change to RUN chmod -R 755 /app/media for consistency.

db_conn = connections["default"]
db_conn.cursor()
except OperationalError:
attempts += 1
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The Dockerfile switches to non-root user my_user at line 20, which is good for security. However, ensure the user has write permissions to any directories that need modification at runtime (like media uploads).

self.stdout.write(
f"DB is not ready(attempt {attempts}/15)... "
f"Wait for 2 seconds."
)
time.sleep(2)
else:
self.stdout.write(
self.style.SUCCESS("DB is ready, continue...")
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Generated by Django 6.0.5 on 2026-05-24 18:40
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Django 6.0.5 requires Python >= 3.12, but this Dockerfile uses python:3.10-slim. This will cause pip to fail when installing Django 6.0.5. Change to python:3.12-slim or use a Django version compatible with Python 3.10.


Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The service name 'cinema_service' doesn't match the task requirement which specifies the service should be named 'app'. Update the service name to match the task requirements.

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing static files handling. Add 'RUN python manage.py collectstatic --noinput' to properly handle static files in Docker.

('cinema', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.AlterField(
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The chmod command is targeting the wrong path. This sets permissions on /media (filesystem root) instead of /app/media where the volume is mounted. Change to RUN chmod -R 755 /app/media to match the mkdir and chown commands above.

model_name='movie',
name='actors',
field=models.ManyToManyField(blank=True, related_name='movies', to='cinema.actor'),
),
migrations.AlterField(
model_name='movie',
name='genres',
field=models.ManyToManyField(blank=True, related_name='movies', to='cinema.genre'),
),
migrations.AlterField(
model_name='moviesession',
name='cinema_hall',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='movie_sessions', to='cinema.cinemahall'),
),
migrations.AlterField(
model_name='moviesession',
name='movie',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='movie_sessions', to='cinema.movie'),
),
migrations.AlterField(
model_name='order',
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='orders', to=settings.AUTH_USER_MODEL),
),
]
13 changes: 9 additions & 4 deletions cinema_service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.0/ref/settings/
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Critical path mismatch: The Dockerfile creates directory /media at root, but docker-compose mounts volume to /app/media. These paths don't match. Either change Dockerfile to mkdir -p /app/media and chown -R my_user /app/media, or change docker-compose volume to mount at /media.

"""
import os
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The docker-compose command doesn't run python manage.py collectstatic. While DEBUG=True may serve static files directly, for production-ready Docker setup and proper STATIC_ROOT usage, consider adding collectstatic --noinput before runserver.

from datetime import timedelta
from pathlib import Path

Expand All @@ -27,8 +28,8 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

ALLOWED_HOSTS = ["127.0.0.1"]
STATIC_ROOT = BASE_DIR / "staticfiles"
INTERNAL_IPS = [
"127.0.0.1",
]
Expand Down Expand Up @@ -86,8 +87,12 @@

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
"ENGINE": "django.db.backends.postgresql",
"NAME": os.environ["POSTGRES_DB"],
"USER": os.environ["POSTGRES_USER"],
"PASSWORD": os.environ["POSTGRES_PASSWORD"],
"HOST": os.environ["POSTGRES_HOST"],
"PORT": os.environ["POSTGRES_PORT"],
}
}

Expand Down
27 changes: 27 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
services:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Django 6.0.5 (from migration file) requires Python >= 3.12. Change to python:3.12-slim.

app:
build:
context: .
env_file:
- .env
ports:
- "8000:8000"
volumes:
- my_media:/app/media
command:
sh -c "python manage.py wait_for_db && python manage.py makemigrations && python manage.py migrate && python manage.py runserver 0.0.0.0:8000"
depends_on:
- db

db:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Path mismatch - chmod targets /media (wrong) but mkdir created /app/media. Change to chmod -R 755 /app/media.

image: postgres:16.0-alpine3.17
restart: always
env_file:
- .env
ports:
- "5432:5432"
volumes:
- my_db:$PGDATA
volumes:
my_db:
my_media:
38 changes: 28 additions & 10 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
django
flake8
flake8-quotes
flake8-variables-names
pep8-naming
django-debug-toolbar
djangorestframework
djangorestframework-simplejwt
drf-spectacular
Pillow
asgiref==3.11.1
attrs==26.1.0
Django==4.2.15
django-debug-toolbar==6.3.0
djangorestframework==3.17.1
djangorestframework_simplejwt==5.5.1
drf-spectacular==0.29.0
flake8==7.3.0
flake8-quotes==3.4.0
flake8-variables-names==0.0.6
inflection==0.5.1
jsonschema==4.26.0
jsonschema-specifications==2025.9.1
mccabe==0.7.0
pep8-naming==0.15.1
pillow==12.2.0
psycopg==3.3.4
psycopg-binary==3.3.4
pycodestyle==2.14.0
pyflakes==3.4.0
PyJWT==2.13.0
PyYAML==6.0.3
referencing==0.37.0
rpds-py==0.30.0
setuptools==82.0.1
sqlparse==0.5.5
tzdata==2026.2
uritemplate==4.2.0
Loading