Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.git
.gitignore
.env
__pycache__
*.pyc
.venv
media/
static/
9 changes: 9 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
POSTGRES_USER=your_user
POSTGRES_PASSWORD=your_password
POSTGRES_DB=postgres_db
DB_HOST=db
DB_PORT=5432

SECRET_KEY=change_me
DEBUG=1
ALLOWED_HOSTS=127.0.0.1,localhost
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM python:3.13-slim

LABEL maintainer="Marek Drządzewski"

ENV PYTHONUNBUFFERED=1

WORKDIR /app

COPY requirements.txt .
RUN pip install --upgrade pip && pip install -r requirements.txt

COPY . .

RUN adduser \
--disabled-password \
--no-create-home \
django-user

RUN mkdir -p /vol/web \
&& chown -R django-user:django-user /vol \
&& chmod -R 755 /vol/web

USER django-user
12 changes: 9 additions & 3 deletions cinema_service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""
from datetime import timedelta
from pathlib import Path
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand Down Expand Up @@ -47,6 +48,7 @@
"debug_toolbar",
"cinema",
"user",
"starter",
]

MIDDLEWARE = [
Expand Down Expand Up @@ -86,8 +88,12 @@

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
"ENGINE": "django.db.backends.postgresql",
"NAME": os.environ.get("POSTGRES_DB"),
"USER": os.environ.get("POSTGRES_USER"),
"PASSWORD": os.environ.get("POSTGRES_PASSWORD"),
"HOST": os.environ.get("DB_HOST"),
"PORT": os.environ.get("DB_PORT"),
}
}

Expand Down Expand Up @@ -125,7 +131,7 @@

USE_I18N = True

USE_TZ = False
USE_TZ = True


# Static files (CSS, JavaScript, Images)
Expand Down
27 changes: 27 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
services:
web:
build: .
container_name: cinema_service
command: >
sh -c "python manage.py wait_for_db &&
python manage.py migrate &&
python manage.py runserver 0.0.0.0:8000"
ports:
- "8000:8000"
volumes:
- ./:/app
env_file:
- .env
db:
image: postgres:15-alpine
container_name: postgres_container
restart: always
env_file:
- .env
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data

volumes:
pgdata:
38 changes: 28 additions & 10 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
django
flake8
flake8-quotes
flake8-variables-names
pep8-naming
django-debug-toolbar
djangorestframework
djangorestframework-simplejwt
drf-spectacular
Pillow
asgiref==3.11.1
attrs==26.1.0
Django==5.2.13
django-debug-toolbar==6.3.0
djangorestframework==3.17.1
djangorestframework_simplejwt==5.5.1
drf-spectacular==0.29.0
flake8==7.3.0
flake8-quotes==3.4.0
flake8-variables-names==0.0.6
inflection==0.5.1
jsonschema==4.26.0
jsonschema-specifications==2025.9.1
mccabe==0.7.0
pep8-naming==0.15.1
pillow==12.2.0
psycopg2-binary==2.9.11
pycodestyle==2.14.0
pyflakes==3.4.0
PyJWT==2.12.1
PyYAML==6.0.3
referencing==0.37.0
rpds-py==0.30.0
setuptools==82.0.1
sqlparse==0.5.5
typing_extensions==4.15.0
tzdata==2026.1
uritemplate==4.2.0
Empty file added starter/__init__.py
Empty file.
Empty file added starter/management/__init__.py
Empty file.
Empty file.
35 changes: 35 additions & 0 deletions starter/management/commands/wait_for_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import time
from django.core.management.base import BaseCommand
from django.db import connections
from django.db.utils import OperationalError


class Command(BaseCommand):

def handle(self, *args, **kwargs):
self.stdout.write("Waiting for database...")
try_counter = 0
max_retries = 40

while True:
try:
db_conn = connections["default"]
db_conn.cursor()

self.stdout.write(self.style.SUCCESS("Database connected!"))
break

except OperationalError:
self.stdout.write(
"Database unavailable, waiting 2 seconds..."
)
time.sleep(2)
try_counter += 1

if try_counter >= max_retries:
self.stdout.write(
self.style.ERROR("Cannot connect to db!"
" Check your connection or"
" try again later.!")
)
raise Exception("Database not available")
Loading