-
Notifications
You must be signed in to change notification settings - Fork 945
feat: Add Docker configuration and wait_for_db management command #1022
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
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,3 @@ | ||
| .venv | ||
| docker-compose.yml | ||
| .idea | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| FROM python:3.11.6-alpine3.18 | ||
| LABEL maineiner="yakovenkoanton2007@gmail.com" | ||
|
|
||
|
Comment on lines
+1
to
+3
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 |
||
| ENV PYTHOUNBUFFERED=1 | ||
|
|
||
| WORKDIR app/ | ||
|
|
||
| COPY requirements.txt requirements.txt | ||
|
|
||
| RUN pip install -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 755 /files/media | ||
|
|
||
| USER my_user | ||
|
Comment on lines
+1
to
+23
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 Issue: The |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import time | ||
|
|
||
| from django.core.management.base import BaseCommand | ||
|
Comment on lines
+1
to
+3
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 import connection, 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 in environment variable: |
||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| def handle(self, *args, **options): | ||
| self.stdout.write("Waiting for database...") | ||
| while True: | ||
| try: | ||
| with connection.cursor() as cursor: | ||
| cursor.execute("SELECT 1") | ||
| self.stdout.write(self.style.SUCCESS("Database available!")) | ||
| break | ||
| except OperationalError: | ||
| self.stdout.write("Database unavailable, waiting 2 seconds...") | ||
| time.sleep(2) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # Generated by Django 5.2.14 on 2026-05-20 12:02 | ||
|
|
||
|
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 in LABEL - 'maineiner' should be 'maintainer'. While this doesn't affect functionality, it's a minor correction. |
||
| import django.db.models.deletion | ||
| from django.conf import settings | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
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 |
||
|
|
||
| dependencies = [ | ||
| ('cinema', '0001_initial'), | ||
| migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
| ] | ||
|
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 |
||
|
|
||
| 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,30 @@ | ||
| services: | ||
| cinema_service: | ||
| build: | ||
| context: . | ||
| image: yakovenkoanton/cinema_service | ||
| env_file: | ||
| - .env | ||
|
Comment on lines
+6
to
+7
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 |
||
| 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" | ||
| depends_on: | ||
|
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. The |
||
| - db | ||
|
|
||
| db: | ||
| image: postgres:16.0-alpine3.17 | ||
| restart: always | ||
| env_file: | ||
| - .env | ||
| ports: | ||
| - "5433:5432" | ||
| volumes: | ||
| - my_db:$PGDATA | ||
|
Comment on lines
+18
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 healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5 |
||
|
|
||
| volumes: | ||
| my_db: | ||
| my_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. Critical Issue: |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,3 +8,4 @@ djangorestframework | |
| djangorestframework-simplejwt | ||
| drf-spectacular | ||
| Pillow | ||
| psycopg2-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.
.dockerignoreis missing common entries that should be excluded:.git,*.pyc,__pycache__,*.md,tests/,.github/, and the db volume namemy_dbshouldn't be there (volumes are not copied).