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
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.venv
Dockerfile
README.md
.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.

Typo in environment variable name: PYTHOUNNBUFFERED should be PYTHONUNBUFFERED. This environment variable is used to ensure Python output is not buffered, making Docker logs work properly.

13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM python:3.13.13-alpine3.23
LABEL maintainer="vovakucin082@gmail.com"

ENV PYTHONUNBUFFERED 1

WORKDIR /app

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

COPY . .

RUN mkdir -p /app/files/media
Comment on lines +1 to +13
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 security best practice. Consider adding a non-root user for the Docker container instead of running as root. Add: RUN addgroup -S appgroup && adduser -S appuser -G appgroup && chown -R appuser:appgroup /app and USER appuser before running the application.

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

from django.core.management import BaseCommand
from django.db import connections
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 name: PYTHOUNNBUFFERED should be PYTHONUNBUFFERED for proper output buffering in Docker.

from django.db.utils import 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.

Path inconsistency: WORKDIR app/ uses relative path but line 13 uses absolute path /app/files/media. These should match - consider using WORKDIR /app for consistency.


class Command(BaseCommand):

def handle(self, *args, **options):
self.stdout.write("Waiting for database...")
db_conn = None
while not db_conn:
try:
db_conn = connections["default"]
db_conn.ensure_connection()
self.stdout.write(self.style.SUCCESS("Database available"))
except OperationalError:
self.stdout.write("Database unavailable, waiting 1 second...")
time.sleep(1)
return
12 changes: 9 additions & 3 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 @@ -86,8 +87,12 @@

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 +139,8 @@
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 Down
27 changes: 27 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
services:
cinema:
build:
context: .
env_file:
- .env
ports:
- "8001:8000"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Port mismatch: The service exposes port 8000 as 8001 on the host (8001:8000), but the task verification expects access at 127.0.0.1:8000/api/. Either change to 8000:8000 or note that users must access 127.0.0.1:8001/api/ instead.

volumes:
- ./:/app
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 volume mounts at /files/media but the Django app's MEDIA_ROOT is files/media/ which resolves to /app/files/media (due to WORKDIR app/ in Dockerfile). The volume should be my_media:/app/files/media to match where the application writes files.

- my_media:/app/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:
- db
db:
image: postgres:16.0-alpine3.17
restart: always
env_file:
- .env
Comment on lines +15 to +19
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 timezone configuration: The db service should have POSTGRES_TZ environment variable set to UTC to match Django's TIME_ZONE = 'UTC' setting, preventing timezone-related issues with database timestamps.

ports:
- "5432:5432"
volumes:
- my_db:/var/lib/postgresql/data

volumes:
my_db:
my_media:
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ djangorestframework
djangorestframework-simplejwt
drf-spectacular
Pillow
psycopg==3.3.4
psycopg-binary==3.3.4
Loading