dockerizing the project

This commit is contained in:
=
2025-12-30 23:05:57 +03:30
parent 17522d57cd
commit 46240a6c38
3 changed files with 77 additions and 8 deletions

36
compose.yml Normal file
View File

@@ -0,0 +1,36 @@
services:
db:
image: postgres:17
environment:
POSTGRES_DB: ${DATABASE_NAME}
POSTGRES_USER: ${DATABASE_USERNAME}
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
env_file:
- .env
django-web:
build: .
container_name: django-docker
ports:
- "8000:8000"
depends_on:
- db
environment:
DJANGO_SECRET_KEY: ${DJANGO_SECRET_KEY}
DEBUG: ${DEBUG}
DJANGO_LOGLEVEL: ${DJANGO_LOGLEVEL}
DJANGO_ALLOWED_HOSTS: ${DJANGO_ALLOWED_HOSTS}
DATABASE_ENGINE: ${DATABASE_ENGINE}
DATABASE_NAME: ${DATABASE_NAME}
DATABASE_USERNAME: ${DATABASE_USERNAME}
DATABASE_PASSWORD: ${DATABASE_PASSWORD}
DATABASE_HOST: ${DATABASE_HOST}
DATABASE_PORT: ${DATABASE_PORT}
env_file:
- .env
volumes:
postgres_data:

33
dockerfile Normal file
View File

@@ -0,0 +1,33 @@
# Use the official Python runtime image
FROM python:3.13-slim
# Create the app directory
RUN mkdir /app
# Set the working directory inside the container
WORKDIR /app
# Set environment variables
# Prevents Python from writing pyc files to disk
ENV PYTHONDONTWRITEBYTECODE=1
#Prevents Python from buffering stdout and stderr
ENV PYTHONUNBUFFERED=1
# Upgrade pip
RUN pip install --upgrade pip
# Copy the Django project and install dependencies
COPY requirements.txt /app/
# run this command to install all dependencies
RUN pip install -r requirements.txt
# Copy the Django project to the container
COPY . /app/
# Expose the Django port
EXPOSE 8000
ENTRYPOINT [ "/Entrypoint.sh" ]
# Run Djangos development server
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

View File

@@ -26,12 +26,12 @@ BASE_DIR = Path(__file__).resolve().parent.parent
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/ # See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret! # SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-so1ts^_(*t1rlr172801d%6o66$!#)^vc^9_)1n1wh*a5j9w#7" SECRET_KEY = os.getenv("DJANGO_SECRET_KEY")
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True DEBUG = os.getenv("DEBUG")
ALLOWED_HOSTS = [] ALLOWED_HOSTS = ["*"]
# Application definition # Application definition
@@ -93,11 +93,11 @@ WSGI_APPLICATION = "settings.wsgi.application"
DATABASES = { DATABASES = {
"default": { "default": {
"ENGINE": "django.db.backends.postgresql", "ENGINE": "django.db.backends.postgresql",
"NAME": "finka", "NAME": os.getenv("DATABASE_NAME"),
"USER": "finkaadmin", "USER": os.getenv("DATABASE_USERNAME"),
"PASSWORD": os.getenv("DATABASEPASSWORD"), "PASSWORD": os.getenv("DATABASE_PASSWORD"),
"HOST": "localhost", # Or your PostgreSQL server's IP/hostname "HOST": os.getenv("DATABASE_HOST"), # Or your PostgreSQL server's IP/hostname
"PORT": "5432", "PORT": os.getenv("DATABASE_PORT"),
} }
} }