-
Notifications
You must be signed in to change notification settings - Fork 946
Setup Dockerized Django Cinema Project with Env and Fixtures #1001
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?
Changes from 1 commit
eaee942
7507226
0c0da8c
e8505c6
801f54e
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,8 @@ | ||
| .venv | ||
| __pycache__/ | ||
| *.pyc | ||
| *.pyo | ||
| *.pyd | ||
| *.sqlite3 | ||
| .git | ||
| .github | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| DJANGO_SECRET_KEY=unsafe-secret-key | ||
| DJANGO_DEBUG=False | ||
|
|
||
| POSTGRES_DB=cinema | ||
| POSTGRES_USER=cinema_user | ||
| POSTGRES_PASSWORD=cinema_pass | ||
| POSTGRES_HOST=db | ||
| POSTGRES_PORT=5432 | ||
|
|
||
| DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1 | ||
|
|
||
| # Автоматичний суперкористувач | ||
| DJANGO_SUPERUSER_USERNAME=admin2 | ||
| DJANGO_SUPERUSER_EMAIL=admin2@test.com | ||
| DJANGO_SUPERUSER_PASSWORD=Admin123! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # Django settings | ||
| DJANGO_SECRET_KEY=unsafe-secret-key | ||
| DJANGO_DEBUG=True | ||
|
|
||
| # PostgreSQL settings | ||
| POSTGRES_DB=cinema | ||
| POSTGRES_USER=cinema_user | ||
| POSTGRES_PASSWORD=cinema_pass | ||
| POSTGRES_HOST=db | ||
| POSTGRES_PORT=5432 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| DJANGO_SECRET_KEY=unsafe-secret-key | ||
| DJANGO_DEBUG=True | ||
|
|
||
| POSTGRES_DB=cinema | ||
| POSTGRES_USER=cinema_user | ||
| POSTGRES_PASSWORD=cinema_pass | ||
| POSTGRES_HOST=localhost | ||
| POSTGRES_PORT=5432 | ||
|
|
||
| DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,26 @@ | ||
| # IDE / Editor configs | ||
| .idea/ | ||
| .vscode/ | ||
| *.iml | ||
|
|
||
| # Environment files | ||
| .env | ||
| .env.local | ||
| .env.docker | ||
|
|
||
| # OS files | ||
| .DS_Store | ||
|
|
||
| # Virtual environments | ||
| venv/ | ||
| .venv/ | ||
|
|
||
| # Python cache | ||
| .pytest_cache/ | ||
| **__pycache__/ | ||
|
|
||
| # SQLite DB (якщо використовується для тестів) | ||
| **db.sqlite3 | ||
| media | ||
|
|
||
| # Media files (зберігаються у volume) | ||
| media/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| FROM python:3.10-slim | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY requirements.txt . | ||
| RUN pip install --no-cache-dir -r requirements.txt | ||
|
|
||
| COPY . . | ||
|
|
||
| CMD ["gunicorn", "cinema.wsgi:application", "--bind", "0.0.0.0:8000"] | ||
|
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 path to the WSGI application appears to be incorrect. Based on the project structure shown in |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import time | ||
| from django.db import connections | ||
| from django.db.utils import OperationalError | ||
| from django.core.management.base import BaseCommand | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| def handle(self, *args, **options): | ||
| self.stdout.write("Waiting for database...") | ||
| db_conn = None | ||
| while not db_conn: | ||
| try: | ||
| db_conn = connections["default"] | ||
| 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,41 @@ | ||
| # Generated by Django 5.0.3 on 2026-03-18 16:25 | ||
|
|
||
| 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,32 @@ | ||
| services: | ||
| db: | ||
| image: postgres:15 | ||
| env_file: | ||
| - .env.docker | ||
| volumes: | ||
| - postgres_data:/var/lib/postgresql/data | ||
| ports: | ||
| - "5432:5432" | ||
|
|
||
| app: | ||
| build: . | ||
| env_file: | ||
| - .env.docker | ||
| command: > | ||
| sh -c "python manage.py wait_for_db && | ||
| python manage.py migrate && | ||
| python manage.py collectstatic --noinput && | ||
| gunicorn cinema_service.wsgi:application --bind 0.0.0.0:8000" | ||
| volumes: | ||
| - .:/app | ||
|
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. Using a bind mount |
||
| - static_volume:/app/static | ||
| - media_volume:/app/media | ||
| ports: | ||
| - "8000:8000" | ||
| depends_on: | ||
| - db | ||
|
|
||
| volumes: | ||
| postgres_data: | ||
| static_volume: | ||
| media_volume: | ||
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 file is missing some important entries. To keep the image secure and lightweight, you should also ignore:
.env*): These may contain secrets and shouldn't be copied into the image..idea/,.vscode/): These are not needed for the application to run.media/directory: Since this is handled by a volume, it shouldn't be part of the initial image build.