Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.venv
docker-compose.yml
.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.

.dockerignore is missing common entries that should be excluded: .git, *.pyc, __pycache__, *.md, tests/, .github/, and the db volume name my_db shouldn't be there (volumes are not copied).

23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM python:3.11.6-alpine3.18
LABEL maineiner="yakovenkoanton2007@gmail.com"

Comment on lines +1 to +3
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 .dockerignore is minimal. Consider adding common Python/Django exclusions like __pycache__, *.pyc, .git, .env, *.log, .pytest_cache, and staticfiles to make images thinner.

ENV PYTHOUNBUFFERED=1

WORKDIR app/

COPY requirements.txt requirements.txt

RUN pip install -r requirements.txt

COPY . .
RUN mkdir -p /files/media

RUN adduser \
--disabled-password \
--no-create-home \
my_user

RUN chown -R my_user /files/media
RUN chmod 755 /files/media

USER my_user
Comment on lines +1 to +23
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 Issue: The docker-compose.yml file is missing from the submitted code. This file is explicitly required by the task to 'manage multiple services (containers) at the same time' and is essential for running docker-compose up.

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

from django.core.management.base import BaseCommand
Comment on lines +1 to +3
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 .dockerignore file is missing common patterns that should be excluded from Docker images: __pycache__, *.pyc, *.pyo, .git, and potentially migrations/ folders (except the ones needed).

from django.db import connection, OperationalError
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Typo in environment variable: PYTHOUNBUFFERED should be PYTHONUNBUFFERED. This environment variable won't work correctly with the typo, affecting real-time output logging in Docker.



class Command(BaseCommand):
def handle(self, *args, **options):
self.stdout.write("Waiting for database...")
while True:
try:
with connection.cursor() as cursor:
cursor.execute("SELECT 1")
self.stdout.write(self.style.SUCCESS("Database available!"))
break
except OperationalError:
self.stdout.write("Database unavailable, waiting 2 seconds...")
time.sleep(2)
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Generated by Django 5.2.14 on 2026-05-20 12:02

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Typo in LABEL - 'maineiner' should be 'maintainer'. While this doesn't affect functionality, it's a minor correction.

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


class Migration(migrations.Migration):
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 the Dockerfile (line 8) but not provided in the source files. This will cause the Docker image build to fail.


dependencies = [
('cinema', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
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 referenced in docker-compose.yml's env_file directive but is not provided. Without this file, the services will fail to start as environment variables like POSTGRES_DB, POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_HOST, and POSTGRES_PORT will be undefined.


operations = [
migrations.AlterField(
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),
),
]
25 changes: 19 additions & 6 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/
"""
import os
from datetime import timedelta
from pathlib import Path

Expand Down Expand Up @@ -81,13 +82,25 @@
WSGI_APPLICATION = "cinema_service.wsgi.application"


# Database
# Database SQLite
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases

# DATABASES = {
# "default": {
# "ENGINE": "django.db.backends.sqlite3",
# "NAME": BASE_DIR / "db.sqlite3",
# }
# }

# Database PostgresSQL
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
"ENGINE": "django.db.backends.postgresql",
"NAME": os.environ.get("POSTGRES_DB"),
"USER": os.environ.get("POSTGRES_USER"),
"PASSWORD": os.environ.get("POSTGRES_PASSWORD"),
"HOST": os.environ.get("POSTGRES_HOST"),
"PORT": os.environ.get("POSTGRES_PORT"),
}
}

Expand Down Expand Up @@ -134,7 +147,7 @@
STATIC_URL = "static/"

MEDIA_URL = "/media/"
MEDIA_ROOT = BASE_DIR / "media"
MEDIA_ROOT = "/files/media/"

# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
Expand All @@ -147,7 +160,7 @@
"rest_framework.throttling.AnonRateThrottle",
"rest_framework.throttling.UserRateThrottle",
],
"DEFAULT_THROTTLE_RATES": {"anon": "10/day", "user": "30/day"},
"DEFAULT_THROTTLE_RATES": {"anon": "10/day", "user": "1000/day"},
"DEFAULT_AUTHENTICATION_CLASSES": (
"rest_framework_simplejwt.authentication.JWTAuthentication",
),
Expand All @@ -167,7 +180,7 @@
}

SIMPLE_JWT = {
"ACCESS_TOKEN_LIFETIME": timedelta(minutes=5),
"ACCESS_TOKEN_LIFETIME": timedelta(minutes=60),
"REFRESH_TOKEN_LIFETIME": timedelta(days=1),
"ROTATE_REFRESH_TOKENS": False,
}
30 changes: 30 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
services:
cinema_service:
build:
context: .
image: yakovenkoanton/cinema_service
env_file:
- .env
Comment on lines +6 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 .env file is referenced in env_file (lines 6-7, 21-22) but not provided. You need to include a .env file with: POSTGRES_DB, POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_HOST, POSTGRES_PORT, and PGDATA variables for the containers to work properly.

ports:
- "8000:8000"
volumes:
- ./:/app
- my_media:/files/media/
command: >
sh -c "python manage.py wait_for_db && python manage.py migrate && python manage.py runserver 0.0.0.0:8000"
depends_on:
Comment on lines +14 to +15
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 depends_on: db without health check is insufficient. PostgreSQL container may be running but not ready to accept connections yet, causing wait_for_db to waste time retrying. Add a healthcheck to the db service and use condition: service_healthy in depends_on for proper Docker Compose service orchestration.

- db

db:
image: postgres:16.0-alpine3.17
restart: always
env_file:
- .env
ports:
- "5433:5432"
volumes:
- my_db:$PGDATA
Comment on lines +18 to +27
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 db service uses condition: service_healthy but lacks a healthcheck configuration. Docker Compose requires a healthcheck to determine when the service is healthy. Add:

healthcheck:
  test: ["CMD-SHELL", "pg_isready -U postgres"]
  interval: 5s
  timeout: 5s
  retries: 5


volumes:
my_db:
my_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 Issue: ALLOWED_HOSTS = [] will cause Django to return 400 Bad Request for all incoming requests in Docker. Add at least ALLOWED_HOSTS=['0.0.0.0', 'localhost', '127.0.0.1'] so the service can respond to requests from the mapped port 8000.

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ djangorestframework
djangorestframework-simplejwt
drf-spectacular
Pillow
psycopg2-binary
Loading