-
Notifications
You must be signed in to change notification settings - Fork 945
Solution #1016
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?
Solution #1016
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,4 @@ | ||
| .venv | ||
| Dockerfile | ||
| .idea | ||
| docker-compose.yaml | ||
|
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 typo: 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 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| FROM python:3.11.6-alpine3.18 | ||
| LABEL maintainer="tanakutova74@gmail.com" | ||
|
Comment on lines
+1
to
+2
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 being in .dockerignore will cause Docker build to fail. Docker needs the Dockerfile in the build context to execute. Remove 'Dockerfile' from .dockerignore. |
||
|
|
||
| ENV PYTHOUNNBUFFERED 1 | ||
|
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. Typo: 'PYTHOUNNBUFFERED' should be 'PYTHONUNBUFFERED'. This environment variable is currently being ignored. |
||
|
|
||
| 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. The |
||
| RUN adduser \ | ||
| --disabled-password \ | ||
| --no-create-home \ | ||
| my_user | ||
|
|
||
|
Comment on lines
+10
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. The wait logic needs to be restructured: call |
||
| RUN chown -R my_user /files/media | ||
| RUN chmod -R 755 /files/media | ||
|
|
||
| USER my_user | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import time | ||
|
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. Service is named 'cinema' but requirements specify 'app' service (used in verification commands like docker ps) |
||
|
|
||
| from django.core.management import BaseCommand | ||
| from django.db import connections, OperationalError | ||
|
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. Typo: should be 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 |
||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| def handle(self, *args, **options): | ||
| self.stdout.write("waiting for db...") | ||
| db_conn = None | ||
| while not db_conn: | ||
| try: | ||
| db_conn = connections["default"] | ||
| db_conn.cursor() | ||
| except OperationalError: | ||
| self.stdout.write( | ||
| "Database unavailable, waiting for 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. Missing |
||
| time.sleep(1) | ||
| self.stdout.write(self.style.SUCCESS("Database available!")) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Comment on lines
10
to
+12
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 datetime import timedelta | ||
| from pathlib import Path | ||
|
|
||
|
|
@@ -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"], | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -134,7 +139,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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| 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. Service is named |
||
| build: | ||
| context: . | ||
| env_file: | ||
| - .env | ||
| ports: | ||
| - "8001:8000" | ||
| volumes: | ||
| - ./:/app | ||
| - my_media:/files/media | ||
| command: > | ||
| sh -c " python manage.py wait_for_db && | ||
|
Comment on lines
+12
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 |
||
| python manage.py migrate && | ||
| python manage.py runserver 0.0.0.0:8000" | ||
| depends_on: | ||
| - db | ||
|
Comment on lines
+15
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. 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 |
||
|
|
||
| db: | ||
| image: postgres:16.0-alpine3.17 | ||
| restart: always | ||
| env_file: | ||
| - .env | ||
| ports: | ||
| - "5433:5432" | ||
| volumes: | ||
| - my_db:$PGDATA | ||
|
|
||
| volumes: | ||
| my_db: | ||
| my_media: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,3 +8,4 @@ djangorestframework | |
| djangorestframework-simplejwt | ||
| drf-spectacular | ||
| Pillow | ||
| psycopg2-binary>=2.9.5 | ||
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.
Critical:
Dockerfileshould NOT be in.dockerignore. The Dockerfile is needed inside the Docker build context to construct the image. Remove this line.