-
Notifications
You must be signed in to change notification settings - Fork 946
Solution #1003
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 #1003
Changes from 2 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,4 @@ | ||
| .venv | ||
| Dockerfile | ||
| .idea | ||
| docker-compose.yml | ||
|
Comment on lines
+1
to
+4
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 file is missing some important entries. To avoid including secrets and unnecessary files in your Docker image, it's a good practice to also ignore files like |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| *.iml | ||
| .env | ||
| .DS_Store | ||
| venv/ | ||
| .venv/ | ||
| .pytest_cache/ | ||
| **__pycache__/ | ||
| **db.sqlite3 | ||
|
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 pattern is not correct for ignoring the |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| FROM python:3.12-alpine | ||
| LABEL maintainer="dmitriykuzmin@ymail.com" | ||
|
|
||
| ENV PYTHONUNBUFFERED=1 | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY requirements.txt requirements.txt | ||
| RUN pip install --no-cache-dir -r requirements.txt | ||
|
|
||
| COPY . . | ||
| RUN mkdir -p /files/media | ||
|
|
||
| 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. While you've correctly set ownership for the media directory, the application code directory ( It's a good practice to also change the ownership of the app directory. Consider adding |
||
|
|
||
| USER my_user | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # Generated by Django 5.2.12 on 2026-03-31 10:55 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.conf import settings | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('cinema', '0001_initial'), | ||
| migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AlterField( | ||
| model_name='movie', | ||
| name='actors', | ||
| field=models.ManyToManyField(blank=True, related_name='movies', to='cinema.actor'), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='movie', | ||
| name='genres', | ||
| field=models.ManyToManyField(blank=True, related_name='movies', to='cinema.genre'), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='moviesession', | ||
| name='cinema_hall', | ||
| field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='movie_sessions', to='cinema.cinemahall'), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='moviesession', | ||
| name='movie', | ||
| field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='movie_sessions', to='cinema.movie'), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='order', | ||
| name='user', | ||
| field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='orders', to=settings.AUTH_USER_MODEL), | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from django.contrib import admin | ||
|
|
||
| # Register your models here. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| from django.apps import AppConfig | ||
|
|
||
|
|
||
| class CoreConfig(AppConfig): | ||
| default_auto_field = "django.db.models.BigAutoField" | ||
| name = "core" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import time | ||
|
|
||
| from django.db import connections | ||
| from django.db.utils import OperationalError | ||
| from django.core.management.base import BaseCommand | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| """Django command to pause execution until database is available""" | ||
|
|
||
| def handle(self, *args, **kwargs): | ||
| self.stdout.write("Waiting for database...") | ||
| while True: | ||
| try: | ||
| db = connections["default"] | ||
| db.ensure_connection() | ||
| break | ||
| except OperationalError: | ||
| self.stdout.write("Database unavailable, waiting 1 second...") | ||
| time.sleep(1) | ||
| self.stdout.write(self.style.SUCCESS("Database available")) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from django.db import models | ||
|
|
||
| # Create your models here. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from django.test import TestCase | ||
|
|
||
| # Create your tests here. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from django.shortcuts import render | ||
|
|
||
| # Create your views here. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| services: | ||
| app: | ||
| build: | ||
| context: . | ||
| ports: | ||
| - "8000:8000" | ||
| volumes: | ||
| - ./:/app/ | ||
| - my_media:/files/media | ||
| 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 | ||
| depends_on: | ||
| - db | ||
|
|
||
| db: | ||
| image: postgres:14-alpine | ||
| ports: | ||
| - "5432:5432" | ||
| env_file: | ||
| - .env | ||
| restart: always | ||
| volumes: | ||
| - my_db:$PGDATA | ||
|
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 use of |
||
|
|
||
| volumes: | ||
| my_db: | ||
| my_media: | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,3 +8,5 @@ djangorestframework | |
| djangorestframework-simplejwt | ||
| drf-spectacular | ||
| Pillow | ||
| psycopg==3.1.12 | ||
| psycopg-binary==3.1.12 | ||
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.
This is a good start for the
.dockerignorefile. To better align with the requirement to keep the image as thin as possible, consider adding other common patterns to this list. For example, you should ignore Python's cache directory (__pycache__/) and often the.gitignorefile itself.