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
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.venv
__pycache__
*.pyc
.git
.idea
db.sqlite3
docker-compose.yaml
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 is listed in .dockerignore (line 7). While docker-compose reads its own yaml file (so this may not cause build failures), it could cause issues if the build context needs access to the compose file. Consider removing this entry unless there's a specific reason to exclude it from images.

26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM python:3.13-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.

The service is named 'cinema' but the task requirements explicitly state 'Two services must be running: app and db'. This naming inconsistency will cause verification to fail.

LABEL maintainer="ilchuk.cergey@gmail.com"

ENV PYTHONUNBUFFERED=1

WORKDIR /app

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

COPY . .

RUN mkdir -p /upload/media
RUN mkdir -p /upload/static

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

RUN chown -R django_user /upload/media
RUN chmod -R 755 /upload/media
RUN chown -R django_user /upload/static
RUN chmod -R 755 /upload/static

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

from django.core.management import BaseCommand
from django.db import connections

from django.db.utils import OperationalError


class Command(BaseCommand):
def handle(self, *args, **options):
db_conn = None
Comment on lines +6 to +11
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 WORKDIR is set to /app, but then COPY . . copies files to the default working directory (root /), not to /app. The Dockerfile should either: (1) Remove WORKDIR /app and let COPY . . work from root, OR (2) Use COPY . /app/ instead of COPY . . to explicitly copy to the correct directory.


while not db_conn:
try:
db_conn = connections["default"]
db_conn.cursor()
break
except OperationalError:
time.sleep(1)
14 changes: 10 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/
"""
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["POSTGRES_DB"],
"USER": os.environ["POSTGRES_USER"],
"PASSWORD": os.environ["POSTGRES_PASSWORD"],
"HOST": os.environ["POSTGRES_HOST"],
"PORT": os.environ["POSTGRES_PORT"],
}
}

Expand Down Expand Up @@ -131,10 +136,11 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/

STATIC_URL = "static/"
STATIC_URL = "/static/"
STATIC_ROOT = "/upload/static"

MEDIA_URL = "/media/"
MEDIA_ROOT = BASE_DIR / "media"
MEDIA_ROOT = "/upload/media"

# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
Expand Down
35 changes: 35 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
services:
app:
build:
context: .
env_file:
- .env
ports:
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 includes docker-compose.yaml (line 7 in .dockerignore), which means the compose file won't be copied into the image during build. While this doesn't break functionality (docker-compose reads its own yaml), it means the file won't be available inside the container at /app/docker-compose.yaml. Consider removing this entry if you need the compose file accessible within the container.

- "8000:8000"
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.

The volume mount - ./:/app overrides the Dockerfile's WORKDIR. The Dockerfile's COPY . . copies to root /, not /app. Either: (1) Remove WORKDIR from Dockerfile, or (2) Change COPY . . to COPY . /app/.

- cinema_media:/upload/media
- cinema_static:/upload/static
command: >
sh -c "python manage.py wait_for_db &&
python manage.py migrate &&
python manage.py collectstatic --noinput &&
python manage.py runserver 0.0.0.0:8000"
Comment on lines +13 to +17
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 sequence is missing 'python manage.py collectstatic --noinput'. Static files defined in settings.py (STATIC_ROOT = '/upload/static') won't be properly collected into the volume.

depends_on:
- db


db:
image: postgres:18-alpine
restart: always
env_file:
- .env
ports:
- "5433:5432"
volumes:
- cinema_db:$PGDATA

volumes:
cinema_db:
cinema_media:
cinema_static:
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