From 46240a6c381c584b3365ff7ea1af38cf179511bc Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 30 Dec 2025 23:05:57 +0330 Subject: [PATCH] dockerizing the project --- compose.yml | 36 ++++++++++++++++++++++++++++++++++++ dockerfile | 33 +++++++++++++++++++++++++++++++++ settings/settings.py | 16 ++++++++-------- 3 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 compose.yml create mode 100644 dockerfile diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..5ef475e --- /dev/null +++ b/compose.yml @@ -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: diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..091af94 --- /dev/null +++ b/dockerfile @@ -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 Django’s development server +CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"] \ No newline at end of file diff --git a/settings/settings.py b/settings/settings.py index 93f2fc2..1c176a1 100644 --- a/settings/settings.py +++ b/settings/settings.py @@ -26,12 +26,12 @@ BASE_DIR = Path(__file__).resolve().parent.parent # See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/ # 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! -DEBUG = True +DEBUG = os.getenv("DEBUG") -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ["*"] # Application definition @@ -93,11 +93,11 @@ WSGI_APPLICATION = "settings.wsgi.application" DATABASES = { "default": { "ENGINE": "django.db.backends.postgresql", - "NAME": "finka", - "USER": "finkaadmin", - "PASSWORD": os.getenv("DATABASEPASSWORD"), - "HOST": "localhost", # Or your PostgreSQL server's IP/hostname - "PORT": "5432", + "NAME": os.getenv("DATABASE_NAME"), + "USER": os.getenv("DATABASE_USERNAME"), + "PASSWORD": os.getenv("DATABASE_PASSWORD"), + "HOST": os.getenv("DATABASE_HOST"), # Or your PostgreSQL server's IP/hostname + "PORT": os.getenv("DATABASE_PORT"), } }