-
Notifications
You must be signed in to change notification settings - Fork 945
S #1005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
S #1005
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| __pycache__/ | ||
| env | ||
| .env | ||
| .venv | ||
| .git | ||
| *.pyc | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| FROM python:3.13-slim | ||
| LABEL authors="barsu" | ||
|
|
||
| ENV PYTHONUNBUFFERED=1 | ||
|
|
||
| WORKDIR /app | ||
| COPY requirements.txt requirements.txt | ||
|
|
||
| RUN apt-get update && apt-get install -y gcc \ | ||
| && pip install --no-cache-dir -r requirements.txt \ | ||
| && apt-get remove -y gcc && apt-get autoremove -y | ||
|
|
||
| COPY . . | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,7 +46,9 @@ class Meta: | |
|
|
||
| class MovieListSerializer(MovieSerializer): | ||
| genres = serializers.SlugRelatedField( | ||
| many=True, read_only=True, slug_field="name" | ||
| many=True, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The ActorSerializer declares "full_name" in Meta.fields but there is no corresponding serializer field defined. Since |
||
| read_only=True, | ||
| slug_field="name" | ||
| ) | ||
| actors = serializers.SlugRelatedField( | ||
| many=True, read_only=True, slug_field="full_name" | ||
|
|
@@ -90,7 +92,8 @@ class MovieSessionListSerializer(MovieSessionSerializer): | |
| movie_title = serializers.CharField(source="movie.title", read_only=True) | ||
| movie_image = serializers.ImageField(source="movie.image", read_only=True) | ||
| cinema_hall_name = serializers.CharField( | ||
| source="cinema_hall.name", read_only=True | ||
| source="cinema_hall.name", | ||
| read_only=True | ||
| ) | ||
| cinema_hall_capacity = serializers.IntegerField( | ||
| source="cinema_hall.capacity", read_only=True | ||
|
|
@@ -117,7 +120,7 @@ def validate(self, attrs): | |
| attrs["row"], | ||
| attrs["seat"], | ||
| attrs["movie_session"].cinema_hall, | ||
| ValidationError | ||
| ValidationError, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're passing |
||
| ) | ||
| return data | ||
|
|
||
|
|
@@ -139,9 +142,7 @@ class Meta: | |
| class MovieSessionDetailSerializer(MovieSessionSerializer): | ||
| movie = MovieListSerializer(many=False, read_only=True) | ||
| cinema_hall = CinemaHallSerializer(many=False, read_only=True) | ||
| taken_places = TicketSeatsSerializer( | ||
| source="tickets", many=True, read_only=True | ||
| ) | ||
| taken_places = TicketSeatsSerializer(source="tickets", many=True, read_only=True) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MovieListSerializer uses |
||
|
|
||
| class Meta: | ||
| model = MovieSession | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import time | ||
|
|
||
| from django.core.management.base import BaseCommand | ||
| from django.db import connection | ||
| from django.db.utils import OperationalError | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| def handle(self, *args, **options): | ||
| while True: | ||
| try: | ||
| self.stdout.write("Waiting for database...") | ||
| connection.ensure_connection() | ||
| self.stdout.write("Database available!") | ||
| break | ||
| except OperationalError: | ||
| time.sleep(3) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,23 +9,20 @@ | |
| For the full list of settings and their values, see | ||
| https://docs.djangoproject.com/en/4.0/ref/settings/ | ||
| """ | ||
|
Comment on lines
9
to
11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Dockerfile installs only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To make the image thinner, clean apt caches and use |
||
|
|
||
| import os | ||
| from datetime import timedelta | ||
| from pathlib import Path | ||
|
|
||
| # Build paths inside the project like this: BASE_DIR / 'subdir'. | ||
| BASE_DIR = Path(__file__).resolve().parent.parent | ||
|
|
||
|
|
||
| # Quick-start development settings - unsuitable for production | ||
| # See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/ | ||
|
|
||
| # SECURITY WARNING: keep the secret key used in production secret! | ||
| SECRET_KEY = ( | ||
| "django-insecure-6vubhk2$++agnctay_4pxy_8cq)mosmn(*-#2b^v4cgsh-^!i3" | ||
| ) | ||
| SECRET_KEY = os.environ.get("SECRET_KEY") | ||
|
|
||
| # SECURITY WARNING: don't run with debug turned on in production! | ||
| DEBUG = True | ||
| DEBUG = os.environ.get('DEBUG', 'False').lower() in ('true', '1') | ||
|
|
||
| ALLOWED_HOSTS = [] | ||
|
|
||
|
|
@@ -45,6 +42,7 @@ | |
| "rest_framework", | ||
| "drf_spectacular", | ||
| "debug_toolbar", | ||
| "cinema_service", | ||
| "cinema", | ||
| "user", | ||
| ] | ||
|
|
@@ -80,37 +78,37 @@ | |
|
|
||
| WSGI_APPLICATION = "cinema_service.wsgi.application" | ||
|
|
||
|
|
||
| # Database | ||
| # https://docs.djangoproject.com/en/4.0/ref/settings/#databases | ||
|
|
||
|
|
||
| DATABASES = { | ||
| "default": { | ||
| "ENGINE": "django.db.backends.sqlite3", | ||
| "NAME": BASE_DIR / "db.sqlite3", | ||
| "ENGINE": "django.db.backends.postgresql", | ||
| "NAME": os.environ.get("DB_NAME", "postgres"), | ||
| "USER": os.environ.get("DB_USER", "postgres"), | ||
| "PASSWORD": os.environ['DB_PASSWORD'], | ||
| "HOST": os.environ.get("DB_HOST", "db"), | ||
| "PORT": os.environ.get("DB_PORT", "5432"), | ||
|
Comment on lines
+87
to
+92
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Database settings correctly use environment variables and default HOST='db' (good for docker-compose). However DB_PASSWORD defaults to an empty string — ensure your |
||
| } | ||
| } | ||
|
|
||
|
|
||
| # Password validation | ||
| # https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators | ||
|
|
||
| AUTH_PASSWORD_VALIDATORS = [ | ||
| { | ||
| "NAME": "django.contrib.auth.password_validation." | ||
| "UserAttributeSimilarityValidator", | ||
| "UserAttributeSimilarityValidator", | ||
| }, | ||
| { | ||
| "NAME": "django.contrib.auth.password_validation." | ||
| "MinimumLengthValidator", | ||
| "NAME": "django.contrib.auth.password_validation." "MinimumLengthValidator", | ||
| }, | ||
| { | ||
| "NAME": "django.contrib.auth.password_validation." | ||
| "CommonPasswordValidator", | ||
| "NAME": "django.contrib.auth.password_validation." "CommonPasswordValidator", | ||
| }, | ||
| { | ||
| "NAME": "django.contrib.auth.password_validation." | ||
| "NumericPasswordValidator", | ||
| "NAME": "django.contrib.auth.password_validation." "NumericPasswordValidator", | ||
| }, | ||
| ] | ||
|
|
||
|
|
@@ -127,14 +125,15 @@ | |
|
|
||
| USE_TZ = False | ||
|
|
||
|
|
||
| # Static files (CSS, JavaScript, Images) | ||
| # https://docs.djangoproject.com/en/4.0/howto/static-files/ | ||
|
|
||
| STATIC_URL = "static/" | ||
| STATIC_URL = "/static/" | ||
|
|
||
| MEDIA_URL = "/media/" | ||
|
|
||
| MEDIA_ROOT = BASE_DIR / "media" | ||
| STATIC_ROOT = BASE_DIR / "static" | ||
|
Comment on lines
+134
to
+136
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MEDIA_ROOT and STATIC_ROOT are set which is good for mounting volumes. However |
||
|
|
||
| # Default primary key field type | ||
| # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| services: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recommendation: verify the chosen base image tag |
||
| app: | ||
| build: | ||
| context: . | ||
| ports: | ||
| - "8000:8000" | ||
| command: sh -c "python manage.py wait_for_db && python manage.py migrate && python manage.py runserver 0.0.0.0:8000" | ||
| env_file: | ||
| - .env | ||
|
Comment on lines
+7
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HIGH: your Dockerfile installs only |
||
| depends_on: | ||
| - db | ||
|
Comment on lines
+9
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Dockerfile installs only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You remove |
||
| volumes: | ||
| - ./media:/app/media | ||
| - ./static:/app/static | ||
| db: | ||
| image: postgres:14-alpine | ||
| env_file: | ||
| - .env | ||
| volumes: | ||
| - db_volume:/var/lib/postgresql/data | ||
|
|
||
| volumes: | ||
| db_volume: | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| #!/usr/bin/env python | ||
| """Django's command-line utility for administrative tasks.""" | ||
|
|
||
| import os | ||
| import sys | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,3 +8,4 @@ djangorestframework | |
| djangorestframework-simplejwt | ||
| drf-spectacular | ||
| Pillow | ||
| psycopg2-binary | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a very new base tag
python:3.13-slimcan cause missing binary wheels for some packages. Verify this tag exists and is compatible with your requirements; consider pinning to a stable minor version (for examplepython:3.11-slim) to avoid unexpected build failures.