-
Notifications
You must be signed in to change notification settings - Fork 945
solved task #1023
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?
solved task #1023
Changes from 1 commit
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,20 @@ | ||
| .idea/ | ||
| .vscode/ | ||
| *.iml | ||
| .DS_Store | ||
| .env | ||
| venv/ | ||
| .pytest_cache/ | ||
| **__pycache__/ | ||
| *.pyc | ||
| **db.sqlite3 | ||
| media/ | ||
| .venv/ | ||
| Dockerfile | ||
|
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. Static files directory is not created in Dockerfile. Add |
||
| .git | ||
| .gitignore | ||
| backups | ||
| *.log | ||
|
Comment on lines
+14
to
+17
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. Critical logic bug: The |
||
| tmp | ||
| docker-compose.yml | ||
| logs/ | ||
|
Comment on lines
+13
to
+20
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 .dockerignore file excludes Dockerfile and docker-compose.yml from the build context. However, docker-compose.yml is not needed inside the app container (it's only for docker-compose), so this exclusion is fine. But if the Dockerfile is in the build context, it will be included - which is actually correct behavior. The exclusion may be redundant. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,5 +6,10 @@ | |
| venv/ | ||
| .pytest_cache/ | ||
| **__pycache__/ | ||
| *.pyc | ||
| **db.sqlite3 | ||
| media | ||
| media/ | ||
| .venv/ | ||
| staticfiles/ | ||
| *.log | ||
| logs/ | ||
|
Comment on lines
+14
to
+15
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. This line will never execute because db_conn is assigned inside the try block before reaching this line. The while condition should probably be |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| FROM python:3.11.15-alpine3.22 | ||
|
|
||
| LABEL maintainer="yukhnenko.o@gmail.com" | ||
|
|
||
| ENV PYTHONUNBUFFERED=1 | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY requirements.txt requirements.txt | ||
| RUN pip install -r requirements.txt | ||
|
|
||
| COPY . . | ||
| RUN mkdir -p /files/media | ||
|
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. Incorrect Exclusions:
Comment on lines
+9
to
+13
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 startup command sequence is missing |
||
|
|
||
|
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. Critical Bug: The while loop |
||
| RUN adduser \ | ||
| --disabled-password \ | ||
| --no-create-home \ | ||
| my_user | ||
|
|
||
| RUN chown -R my_user /files/media | ||
| RUN chmod -R 755 /files/media | ||
|
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 |
||
|
|
||
| USER my_user | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| from django.core.management.base import BaseCommand | ||
| from django.db import connections | ||
|
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 |
||
| from django.db.utils import OperationalError | ||
| import time | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| """Django command to pause execution until database is available""" | ||
|
|
||
| def handle(self, *args, **options): | ||
| self.stdout.write("Waiting for database...", ending="") | ||
|
Comment on lines
+8
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 docker-compose command sequence is missing |
||
|
|
||
| db_conn = None | ||
|
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 |
||
|
|
||
|
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 |
||
| while not db_conn: | ||
| try: | ||
| db_conn = connections["default"] | ||
| self.stdout.write( | ||
| "Database unavailable, waiting for a 1 second", | ||
|
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 |
||
| ending="" | ||
| ) | ||
|
Comment on lines
+18
to
+26
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 |
||
| db_conn.cursor() | ||
| except OperationalError: | ||
| time.sleep(1) | ||
|
|
||
| self.stdout.write(self.style.SUCCESS("Database available!")) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,9 +9,13 @@ | |
| 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 command sequence is missing
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 startup command sequence is missing |
||
| import os | ||
| from dotenv import load_dotenv | ||
| from datetime import timedelta | ||
| from pathlib import Path | ||
|
|
||
| load_dotenv() | ||
|
|
||
| # Build paths inside the project like this: BASE_DIR / 'subdir'. | ||
| BASE_DIR = Path(__file__).resolve().parent.parent | ||
|
|
||
|
|
@@ -20,9 +24,7 @@ | |
| # 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.getenv("DJANGO_SECRET_KEY") | ||
|
Comment on lines
26
to
+27
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 volume mapping uses |
||
|
|
||
| # SECURITY WARNING: don't run with debug turned on in production! | ||
| DEBUG = True | ||
|
|
@@ -86,8 +88,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"], | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -132,9 +138,8 @@ | |
| # https://docs.djangoproject.com/en/4.0/howto/static-files/ | ||
|
|
||
| STATIC_URL = "static/" | ||
|
|
||
| MEDIA_URL = "/media/" | ||
| MEDIA_ROOT = BASE_DIR / "media" | ||
| MEDIA_ROOT = "/files/media" | ||
|
Comment on lines
141
to
+143
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. settings.py is missing STATIC_ROOT configuration. While Django will use BASE_DIR / "staticfiles" as default, explicitly setting STATIC_ROOT is a best practice for Docker deployments. Add: STATIC_ROOT = BASE_DIR / "staticfiles" near line 139. |
||
|
|
||
| # 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,31 @@ | ||
| services: | ||
| cinema: | ||
|
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 docker-compose service is named |
||
| build: | ||
| context: . | ||
| env_file: | ||
| - .env | ||
| ports: | ||
| - "8000:8000" | ||
| command: > | ||
| sh -c "python manage.py wait_for_db && | ||
| python manage.py migrate && | ||
|
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. Missing |
||
| python manage.py runserver 0.0.0.0:8000" | ||
| volumes: | ||
| - my_media:/files/media | ||
| depends_on: | ||
| - db | ||
|
|
||
|
|
||
| db: | ||
| image: postgres:16-alpine3.22 | ||
| restart: always | ||
| env_file: | ||
| - .env | ||
| ports: | ||
| - "5432:5432" | ||
| volumes: | ||
|
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 database volume mapping uses |
||
| - my_db:$PGDATA | ||
|
|
||
| volumes: | ||
| my_db: | ||
| my_media: | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,3 +8,7 @@ djangorestframework | |
| djangorestframework-simplejwt | ||
| drf-spectacular | ||
| Pillow | ||
| python-dotenv | ||
| psycopg | ||
| psycopg-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.
Missing
collectstatic --noinputcommand. According to CHECKLIST ITEM #10, the Dockerfile should includecollectstatic --noinputas part of the build process for proper static file handling with Docker. Add this before the USER directive:RUN python manage.py collectstatic --noinput