-
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
Open
3883IZ
wants to merge
5
commits into
mate-academy:master
Choose a base branch
from
3883IZ:develop
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
eaee942
Setup Docker deployment, env files, fixtures, and admin access
boxletter2011-lgtm 7507226
Fix flake8 E501 issues in settings.py
boxletter2011-lgtm 0c0da8c
Remove bind mount from docker-compose to ensure independent container
boxletter2011-lgtm e8505c6
Update .dockerignore to exclude env files and media directory
boxletter2011-lgtm 801f54e
Fix Dockerfile CMD to use cinema_service.wsgi:application
boxletter2011-lgtm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| .venv | ||
| __pycache__/ | ||
| *.pyc | ||
| *.pyo | ||
| *.pyd | ||
| *.sqlite3 | ||
| .git | ||
| .github | ||
| .env* | ||
| media/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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_service.wsgi:application", "--bind", "0.0.0.0:8000"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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!")) |
41 changes: 41 additions & 0 deletions
41
cinema/migrations/0002_alter_movie_actors_alter_movie_genres_and_more.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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), | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| 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: | ||
| - static_volume:/app/static | ||
| - media_volume:/app/media | ||
| ports: | ||
| - "8000:8000" | ||
| depends_on: | ||
| - db | ||
|
|
||
| volumes: | ||
| postgres_data: | ||
| static_volume: | ||
| media_volume: |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.