From 105bfc0897510e4d1a36c24c27bf8f536fccfa6a Mon Sep 17 00:00:00 2001 From: On-cloud7 Date: Fri, 23 Jan 2026 22:00:45 +0530 Subject: [PATCH 01/11] dockerignore and Dockerfile is added --- backend/.dockerignore | 6 ++++++ backend/Dockerfile | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 backend/.dockerignore create mode 100644 backend/Dockerfile diff --git a/backend/.dockerignore b/backend/.dockerignore new file mode 100644 index 00000000..e09bc994 --- /dev/null +++ b/backend/.dockerignore @@ -0,0 +1,6 @@ +__pycache__/ +*.pyc +*.sqlite3 +venv/ +.env +.git diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 00000000..6ad78166 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,36 @@ +# -------- Builder stage -------- +FROM python:3.12-slim AS builder + +WORKDIR /app + +RUN apt-get update && apt-get install -y \ + build-essential gcc libpq-dev \ + && rm -rf /var/lib/apt/lists/* + +RUN python -m venv /opt/venv +ENV PATH="/opt/venv/bin:$PATH" + +RUN pip install --upgrade pip +RUN pip install django django-cors-headers psycopg2-binary + +COPY . . + +# -------- Runtime stage -------- +FROM python:3.12-slim + +WORKDIR /app + +RUN useradd -m appuser +USER appuser + +COPY --from=builder /opt/venv /opt/venv +COPY --from=builder /app /app + +ENV PATH="/opt/venv/bin:$PATH" +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONUNBUFFERED=1 +ENV DEBUG=0 + +EXPOSE 8000 + +CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"] From 42b977f1fb878c6accc91cd15771e4d3e2c53660 Mon Sep 17 00:00:00 2001 From: On-cloud7 Date: Fri, 23 Jan 2026 16:42:54 +0000 Subject: [PATCH 02/11] Implemented multi-stage Dockerfile with non-root user --- backend/.dockerignore | 12 +- backend/Dockerfile | 72 +++++------ backend/config/asgi.py | 32 ++--- backend/config/settings.py | 244 ++++++++++++++++++------------------- backend/config/urls.py | 46 +++---- backend/config/wsgi.py | 32 ++--- backend/core/admin.py | 6 +- backend/core/apps.py | 10 +- backend/core/models.py | 6 +- backend/core/tests.py | 6 +- backend/core/urls.py | 12 +- backend/core/views.py | 8 +- backend/manage.py | 44 +++---- 13 files changed, 265 insertions(+), 265 deletions(-) diff --git a/backend/.dockerignore b/backend/.dockerignore index e09bc994..6b390610 100644 --- a/backend/.dockerignore +++ b/backend/.dockerignore @@ -1,6 +1,6 @@ -__pycache__/ -*.pyc -*.sqlite3 -venv/ -.env -.git +__pycache__/ +*.pyc +*.sqlite3 +venv/ +.env +.git diff --git a/backend/Dockerfile b/backend/Dockerfile index 6ad78166..6492f6db 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,36 +1,36 @@ -# -------- Builder stage -------- -FROM python:3.12-slim AS builder - -WORKDIR /app - -RUN apt-get update && apt-get install -y \ - build-essential gcc libpq-dev \ - && rm -rf /var/lib/apt/lists/* - -RUN python -m venv /opt/venv -ENV PATH="/opt/venv/bin:$PATH" - -RUN pip install --upgrade pip -RUN pip install django django-cors-headers psycopg2-binary - -COPY . . - -# -------- Runtime stage -------- -FROM python:3.12-slim - -WORKDIR /app - -RUN useradd -m appuser -USER appuser - -COPY --from=builder /opt/venv /opt/venv -COPY --from=builder /app /app - -ENV PATH="/opt/venv/bin:$PATH" -ENV PYTHONDONTWRITEBYTECODE=1 -ENV PYTHONUNBUFFERED=1 -ENV DEBUG=0 - -EXPOSE 8000 - -CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"] +# -------- Builder stage -------- +FROM python:3.12-slim AS builder + +WORKDIR /app + +RUN apt-get update && apt-get install -y \ + build-essential gcc libpq-dev \ + && rm -rf /var/lib/apt/lists/* + +RUN python -m venv /opt/venv +ENV PATH="/opt/venv/bin:$PATH" + +RUN pip install --upgrade pip +RUN pip install django django-cors-headers psycopg2-binary + +COPY . . + +# -------- Runtime stage -------- +FROM python:3.12-slim + +WORKDIR /app + +RUN useradd -m appuser +USER appuser + +COPY --from=builder /opt/venv /opt/venv +COPY --from=builder /app /app + +ENV PATH="/opt/venv/bin:$PATH" +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONUNBUFFERED=1 +ENV DEBUG=0 + +EXPOSE 8000 + +CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"] diff --git a/backend/config/asgi.py b/backend/config/asgi.py index ffbb5f50..18377bb9 100644 --- a/backend/config/asgi.py +++ b/backend/config/asgi.py @@ -1,16 +1,16 @@ -""" -ASGI config for config project. - -It exposes the ASGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/6.0/howto/deployment/asgi/ -""" - -import os - -from django.core.asgi import get_asgi_application - -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') - -application = get_asgi_application() +""" +ASGI config for config project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/6.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') + +application = get_asgi_application() diff --git a/backend/config/settings.py b/backend/config/settings.py index b5764dac..6674ff19 100644 --- a/backend/config/settings.py +++ b/backend/config/settings.py @@ -1,122 +1,122 @@ -""" -Django settings for config project. - -Generated by 'django-admin startproject' using Django 6.0.1. - -For more information on this file, see -https://docs.djangoproject.com/en/6.0/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/6.0/ref/settings/ -""" - -from pathlib import Path - -# Build paths inside the project like this: BASE_DIR / 'subdir'. -BASE_DIR = Path(__file__).resolve().parent.parent - - -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'django-insecure-_9x%j_pvwb=^d^%whvti=0)yk_-t(i62i^xj!yruyg%xotvkv&' - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -ALLOWED_HOSTS = [] - - -# Application definition - -INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'corsheaders', - 'core', -] - -MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - 'corsheaders.middleware.CorsMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', -] - -ROOT_URLCONF = 'config.urls' - -TEMPLATES = [ - { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [ - 'django.template.context_processors.request', - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', - ], - }, - }, -] - -WSGI_APPLICATION = 'config.wsgi.application' - - -# Database -# https://docs.djangoproject.com/en/6.0/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', - } -} - - -# Password validation -# https://docs.djangoproject.com/en/6.0/ref/settings/#auth-password-validators - -AUTH_PASSWORD_VALIDATORS = [ - { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', - }, -] - - -# Internationalization -# https://docs.djangoproject.com/en/6.0/topics/i18n/ - -LANGUAGE_CODE = 'en-us' - -TIME_ZONE = 'UTC' - -USE_I18N = True - -USE_TZ = True - - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/6.0/howto/static-files/ - -STATIC_URL = 'static/' - -CORS_ALLOW_ALL_ORIGINS = True +""" +Django settings for config project. + +Generated by 'django-admin startproject' using Django 6.0.1. + +For more information on this file, see +https://docs.djangoproject.com/en/6.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/6.0/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-_9x%j_pvwb=^d^%whvti=0)yk_-t(i62i^xj!yruyg%xotvkv&' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'corsheaders', + 'core', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'corsheaders.middleware.CorsMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'config.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'config.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/6.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/6.0/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/6.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/6.0/howto/static-files/ + +STATIC_URL = 'static/' + +CORS_ALLOW_ALL_ORIGINS = True diff --git a/backend/config/urls.py b/backend/config/urls.py index 193911f5..befa9461 100644 --- a/backend/config/urls.py +++ b/backend/config/urls.py @@ -1,23 +1,23 @@ -""" -URL configuration for config project. - -The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/6.0/topics/http/urls/ -Examples: -Function views - 1. Add an import: from my_app import views - 2. Add a URL to urlpatterns: path('', views.home, name='home') -Class-based views - 1. Add an import: from other_app.views import Home - 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') -Including another URLconf - 1. Import the include() function: from django.urls import include, path - 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) -""" -from django.contrib import admin -from django.urls import path, include - -urlpatterns = [ - path('admin/', admin.site.urls), - path('api/', include('core.urls')), -] +""" +URL configuration for config project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/6.0/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path, include + +urlpatterns = [ + path('admin/', admin.site.urls), + path('api/', include('core.urls')), +] diff --git a/backend/config/wsgi.py b/backend/config/wsgi.py index 4ced5749..5165ee97 100644 --- a/backend/config/wsgi.py +++ b/backend/config/wsgi.py @@ -1,16 +1,16 @@ -""" -WSGI config for config project. - -It exposes the WSGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/6.0/howto/deployment/wsgi/ -""" - -import os - -from django.core.wsgi import get_wsgi_application - -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') - -application = get_wsgi_application() +""" +WSGI config for config project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/6.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') + +application = get_wsgi_application() diff --git a/backend/core/admin.py b/backend/core/admin.py index 8c38f3f3..ea5d68b7 100644 --- a/backend/core/admin.py +++ b/backend/core/admin.py @@ -1,3 +1,3 @@ -from django.contrib import admin - -# Register your models here. +from django.contrib import admin + +# Register your models here. diff --git a/backend/core/apps.py b/backend/core/apps.py index 26f78a8e..ae16c3e7 100644 --- a/backend/core/apps.py +++ b/backend/core/apps.py @@ -1,5 +1,5 @@ -from django.apps import AppConfig - - -class CoreConfig(AppConfig): - name = 'core' +from django.apps import AppConfig + + +class CoreConfig(AppConfig): + name = 'core' diff --git a/backend/core/models.py b/backend/core/models.py index 71a83623..fd18c6ea 100644 --- a/backend/core/models.py +++ b/backend/core/models.py @@ -1,3 +1,3 @@ -from django.db import models - -# Create your models here. +from django.db import models + +# Create your models here. diff --git a/backend/core/tests.py b/backend/core/tests.py index 7ce503c2..de8bdc00 100644 --- a/backend/core/tests.py +++ b/backend/core/tests.py @@ -1,3 +1,3 @@ -from django.test import TestCase - -# Create your tests here. +from django.test import TestCase + +# Create your tests here. diff --git a/backend/core/urls.py b/backend/core/urls.py index eb42a8dc..32413910 100644 --- a/backend/core/urls.py +++ b/backend/core/urls.py @@ -1,6 +1,6 @@ -from django.urls import path -from .views import hello_world - -urlpatterns = [ - path('hello/', hello_world, name='hello_world'), -] +from django.urls import path +from .views import hello_world + +urlpatterns = [ + path('hello/', hello_world, name='hello_world'), +] diff --git a/backend/core/views.py b/backend/core/views.py index 14810e48..0892cba2 100644 --- a/backend/core/views.py +++ b/backend/core/views.py @@ -1,4 +1,4 @@ -from django.http import JsonResponse - -def hello_world(request): - return JsonResponse({"message": "Hello World from Django Backend!"}) +from django.http import JsonResponse + +def hello_world(request): + return JsonResponse({"message": "Hello World from Django Backend!"}) diff --git a/backend/manage.py b/backend/manage.py index 8e7ac79b..192aaab6 100755 --- a/backend/manage.py +++ b/backend/manage.py @@ -1,22 +1,22 @@ -#!/usr/bin/env python -"""Django's command-line utility for administrative tasks.""" -import os -import sys - - -def main(): - """Run administrative tasks.""" - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') - try: - from django.core.management import execute_from_command_line - except ImportError as exc: - raise ImportError( - "Couldn't import Django. Are you sure it's installed and " - "available on your PYTHONPATH environment variable? Did you " - "forget to activate a virtual environment?" - ) from exc - execute_from_command_line(sys.argv) - - -if __name__ == '__main__': - main() +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() From 924bd5bc2d0d93131c438b909be04e6b963f9eee Mon Sep 17 00:00:00 2001 From: On-cloud7 Date: Fri, 23 Jan 2026 22:14:39 +0530 Subject: [PATCH 03/11] files deleted --- backend/.dockerignore | 6 ------ backend/Dockerfile | 36 ------------------------------------ 2 files changed, 42 deletions(-) delete mode 100644 backend/.dockerignore delete mode 100644 backend/Dockerfile diff --git a/backend/.dockerignore b/backend/.dockerignore deleted file mode 100644 index 6b390610..00000000 --- a/backend/.dockerignore +++ /dev/null @@ -1,6 +0,0 @@ -__pycache__/ -*.pyc -*.sqlite3 -venv/ -.env -.git diff --git a/backend/Dockerfile b/backend/Dockerfile deleted file mode 100644 index 6492f6db..00000000 --- a/backend/Dockerfile +++ /dev/null @@ -1,36 +0,0 @@ -# -------- Builder stage -------- -FROM python:3.12-slim AS builder - -WORKDIR /app - -RUN apt-get update && apt-get install -y \ - build-essential gcc libpq-dev \ - && rm -rf /var/lib/apt/lists/* - -RUN python -m venv /opt/venv -ENV PATH="/opt/venv/bin:$PATH" - -RUN pip install --upgrade pip -RUN pip install django django-cors-headers psycopg2-binary - -COPY . . - -# -------- Runtime stage -------- -FROM python:3.12-slim - -WORKDIR /app - -RUN useradd -m appuser -USER appuser - -COPY --from=builder /opt/venv /opt/venv -COPY --from=builder /app /app - -ENV PATH="/opt/venv/bin:$PATH" -ENV PYTHONDONTWRITEBYTECODE=1 -ENV PYTHONUNBUFFERED=1 -ENV DEBUG=0 - -EXPOSE 8000 - -CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"] From 5e1cc357568078ea5cfe38e5fc51ff82b50e35ba Mon Sep 17 00:00:00 2001 From: On-cloud7 Date: Sun, 25 Jan 2026 20:24:31 +0530 Subject: [PATCH 04/11] Dockerfile of frontend & backend is added --- backend/.dockerignore | 22 ++++++++++++++++++++ backend/Dockerfile | 47 ++++++++++++++++++++++++++++++++++++++++++ frontend/.dockerignore | 4 ++++ frontend/Dockerfile | 37 +++++++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+) create mode 100644 backend/.dockerignore create mode 100644 backend/Dockerfile create mode 100644 frontend/.dockerignore create mode 100644 frontend/Dockerfile diff --git a/backend/.dockerignore b/backend/.dockerignore new file mode 100644 index 00000000..437f8aaf --- /dev/null +++ b/backend/.dockerignore @@ -0,0 +1,22 @@ +# Python cache +__pycache__/ +*.pyc +*.pyo +*.pyd + +# Virtual environments (VERY IMPORTANT) +venv/ +.venv/ +env/ + +# Git +.git/ +.gitignore + +# Frontend / build junk (safe even if not present) +node_modules/ +dist/ +build/ + +# Local DB +*.sqlite3 diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 00000000..6391e8b5 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,47 @@ +# -------- Builder stage -------- +FROM python:3.12-slim AS builder + +WORKDIR /app + +# System dependencies +RUN apt-get update && apt-get install -y \ + build-essential gcc libpq-dev \ + && rm -rf /var/lib/apt/lists/* + +# Create virtual environment +RUN python -m venv /opt/venv +ENV PATH="/opt/venv/bin:$PATH" + +# Install Python dependencies +RUN pip install --upgrade pip +RUN pip install django django-cors-headers psycopg2-binary + +# Copy project source (venv is ignored via .dockerignore) +COPY . . + +# -------- Runtime stage -------- +FROM python:3.12-slim + +WORKDIR /app + +# Create non-root user +RUN useradd -m appuser + +# Copy venv and app from builder +COPY --from=builder /opt/venv /opt/venv +COPY --from=builder /app /app + +# Permissions +RUN chown -R appuser:appuser /app /opt/venv + +USER appuser + +# Environment variables +ENV PATH="/opt/venv/bin:$PATH" +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONUNBUFFERED=1 +ENV DJANGO_SETTINGS_MODULE=config.settings + +EXPOSE 8000 + +CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"] diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 00000000..375e27eb --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1,4 @@ +node_modules +dist +.git + diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 00000000..dff32d5d --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,37 @@ +# -------- Build stage -------- +FROM node:20-alpine AS builder +WORKDIR /app + +ARG VITE_API_URL +ENV VITE_API_URL=$VITE_API_URL + +COPY package*.json ./ +RUN npm install +COPY . . +RUN npm run build + +# -------- Runtime stage -------- +FROM nginx:alpine + +# Create non-root user +RUN adduser -D appuser + +# Create and fix permissions for nginx directories +RUN mkdir -p \ + /var/cache/nginx/client_temp \ + /var/cache/nginx/proxy_temp \ + /var/cache/nginx/fastcgi_temp \ + /var/cache/nginx/uwsgi_temp \ + /var/cache/nginx/scgi_temp \ + /var/run \ + /run \ + /usr/share/nginx/html \ + && chown -R appuser:appuser /var/cache/nginx /var/run /run /usr/share/nginx/html + +# Copy built frontend +COPY --from=builder /app/dist /usr/share/nginx/html + +USER appuser + +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] From c11ea6824f425bc5f9057212751baa432baf3f88 Mon Sep 17 00:00:00 2001 From: On-cloud7 Date: Sun, 25 Jan 2026 20:27:40 +0530 Subject: [PATCH 05/11] docker-compose.yml added --- docker-compose.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..add8f7f7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,23 @@ +version: "3.9" + +services: + backend: + build: + context: ./backend + ports: + - "8000:8000" + environment: + - DJANGO_SETTINGS_MODULE=config.settings + - DEBUG=0 + command: python manage.py runserver 0.0.0.0:8000 + + frontend: + build: + context: ./frontend + args: + VITE_API_URL: http://backend:8000 + ports: + - "3000:80" + depends_on: + - backend + From c06d35cae463a3eb59d774a379a26b73f66a27b4 Mon Sep 17 00:00:00 2001 From: On-cloud7 Date: Sun, 25 Jan 2026 21:13:22 +0530 Subject: [PATCH 06/11] terraform file is created --- infra-terraform/terraform.tf | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 infra-terraform/terraform.tf diff --git a/infra-terraform/terraform.tf b/infra-terraform/terraform.tf new file mode 100644 index 00000000..e69de29b From d763ae8a5bbaccc1313ab04c0a2b5c74a392b6c0 Mon Sep 17 00:00:00 2001 From: On-cloud7 Date: Sun, 25 Jan 2026 21:16:23 +0530 Subject: [PATCH 07/11] terraform files are added --- infra-terraform/EC2.tf | 67 ++++++++++++++++++++++++++++++++++++ infra-terraform/terraform.tf | 12 +++++++ infra-terraform/variable.tf | 33 ++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 infra-terraform/EC2.tf create mode 100644 infra-terraform/variable.tf diff --git a/infra-terraform/EC2.tf b/infra-terraform/EC2.tf new file mode 100644 index 00000000..3296e2a2 --- /dev/null +++ b/infra-terraform/EC2.tf @@ -0,0 +1,67 @@ +resource "aws_key_pair" "my-key" { + key_name = "priya-key" + public_key = file("priya-key.pub") + + +} +resource "aws_default_vpc" "default" {//aws ka vpc configurable nhi hota to by default he rakte hai + +} + +resource "aws_security_group" "my_sg" { + name = "my security group" + description = "this is a security group don by terraform" + vpc_id = aws_default_vpc.default.id//interpolation : wo . jo hai usko interpolation bolte hai kisi bhi resource ke andar jo value hai wo aap utha sakte ho attributes ki values bhi utha sakte hai + + ingress { //inbound rules + description = "allow access to ssh port 22" + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] // avaible to everyone + } + ingress { + description = "allow access to http port 80" + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + ingress{ + + description = "this is allow accces to https port 443" + from_port = 443 + to_port = 443 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + egress { //outbound rules + description= "allow all out going traffic" + to_port = 0 // to_port& from_port is always zero + from_port = 0 + protocol = "-1"//outgoing traffic for every type + cidr_blocks = ["0.0.0.0/0"] + + } + tags={ + name = "my security group" + } +} +resource "aws_instance" "my_instance" { + + ami= "ami-087a0156cb826e921" + instance_type = "t2.micro" + security_groups = [aws_security_group.my_sg.name] //interpolation + key_name = aws_key_pair.my-key.key_name // interpolation + + root_block_device { //ebs or volume + volume_size = "10" + volume_type = "gp3" + + + } + tags = { + Name = "devops-instance" // ec2 name + } +} \ No newline at end of file diff --git a/infra-terraform/terraform.tf b/infra-terraform/terraform.tf index e69de29b..bbb27133 100644 --- a/infra-terraform/terraform.tf +++ b/infra-terraform/terraform.tf @@ -0,0 +1,12 @@ +terraform{ + required_providers { + aws = { + source = "hashicorp/aws" + version = "5.78.0" + } + } +} +provider "aws" { + region = "eu-west-1" + +} \ No newline at end of file diff --git a/infra-terraform/variable.tf b/infra-terraform/variable.tf new file mode 100644 index 00000000..2c86a465 --- /dev/null +++ b/infra-terraform/variable.tf @@ -0,0 +1,33 @@ +variable "aws_region"{ + description = "this is the region for aws region" + default = "eu-west-1" +} + +# variable "aws_ec2_ami_id"{ +# description ="this is ami_id for ubuntu instance" +# default = "ami-087a0156cb826e921" + +# } + +variable "aws_instance_type" { + description ="this is a instance type for ec2 instance" + default = "t2.micro" + +} + +variable "aws_ec2_instance_name" { + description = "this is the name given to the ec2 instance" + default = "priya_instance" + +} + +variable "aws_root_volume_size" { + description ="this is root volume size for the aws " + default = "10" + +} + +variable "aws_instance_count"{ + description = "The count if Ec2 instance needed" + default = 1 +} \ No newline at end of file From 6c166b1a51f5cc356e324bde421c63415bb877cd Mon Sep 17 00:00:00 2001 From: On-cloud7 Date: Sun, 25 Jan 2026 21:21:37 +0530 Subject: [PATCH 08/11] cicd added --- .github/workflows/cicd.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/cicd.yml diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml new file mode 100644 index 00000000..c8ee7c07 --- /dev/null +++ b/.github/workflows/cicd.yml @@ -0,0 +1,32 @@ +name: CI-CD Pipeline + +on: + push: + branches: + - main + +jobs: + docker-build-push: + runs-on: ubuntu-latest + + steps: + # Step 1: Checkout code + - name: Checkout repository + uses: actions/checkout@v4 + + # Step 2: Login to Docker Hub + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + # Step 3: Build Docker image + - name: Build Docker image + run: | + docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/devops-assessment:latest . + + # Step 4: Push Docker image + - name: Push Docker image + run: | + docker push ${{ secrets.DOCKERHUB_USERNAME }}/devops-assessment:latest From 9b686a4993e894913a61d5e940c8b1493b94d51d Mon Sep 17 00:00:00 2001 From: priyanka pardeshi <140867398+On-cloud7@users.noreply.github.com> Date: Sun, 25 Jan 2026 21:30:28 +0530 Subject: [PATCH 09/11] Create Devops.md --- Devops.md | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 Devops.md diff --git a/Devops.md b/Devops.md new file mode 100644 index 00000000..14392f87 --- /dev/null +++ b/Devops.md @@ -0,0 +1,84 @@ +# 🐳 Docker-Based DevOps Deployment (with Terraform & CI/CD) + +## 📌 Overview +This document describes the **Docker-based deployment strategy** for a full-stack application, enhanced with **CI/CD automation using GitHub Actions** and **Infrastructure as Code (IaC) using Terraform**. + +The focus of this setup includes: +- Containerization using Docker +- Service orchestration using Docker Compose +- Automated image build and push using GitHub Actions +- Cloud infrastructure provisioning using Terraform + +--- + +## 🧩 Application Stack + +- **Backend:** Django (REST API) +- **Frontend:** React (Vite + TypeScript) +- **Containerization:** Docker +- **Orchestration:** Docker Compose +- **CI/CD:** GitHub Actions +- **Infrastructure as Code:** Terraform +- **Cloud Platform:** AWS + +--- + +## 🛠 Docker Containerization + +### Backend (Django) +- Dockerized using a **Python slim base image** +- Dependencies installed using `requirements.txt` +- REST API exposed on **port 8000** +- Runs as a standalone Docker container + +### Frontend (React – Vite + TypeScript) +- Dockerized using a **Node Alpine base image** +- Application built using **npm** +- Frontend exposed on **port 3000** +- Served through a Docker container + +--- + +## 🔗 Docker Compose Orchestration + +- `docker-compose.yml` is used to manage multi-container deployment +- Backend and frontend run as **separate services** +- Services communicate via an **internal Docker network** +- Ports are mapped to the host system for browser access + +### Port Mapping + +| Service | Container Port | Host Port | +|--------|----------------|-----------| +| Backend | 8000 | 8000 | +| Frontend | 3000 | 3000 | + +--- + +## ▶️ Run Application Using Docker + +### Prerequisites +- Docker +- Docker Compose + +### Command +```bash +docker compose up --build +``` +## ☁️ Terraform (Infrastructure as Code) + +Terraform is used alongside Docker to provision and manage cloud infrastructure required for deployment. + +### Terraform Integration with Docker Workflow +- Terraform code is stored in `infra-terraform/` +- Infrastructure is defined using `.tf` files +- Enables automated provisioning of cloud resources (e.g., EC2, networking) +- Ensures Docker containers run on consistent and reproducible infrastructure + +### Terraform Commands +```bash +terraform init +terraform validate +terraform plan +terraform apply +``` From 9269b03b14782824919630d493f8e51f148b672d Mon Sep 17 00:00:00 2001 From: priyanka pardeshi <140867398+On-cloud7@users.noreply.github.com> Date: Sun, 25 Jan 2026 21:32:59 +0530 Subject: [PATCH 10/11] Update Devops.md --- Devops.md | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Devops.md b/Devops.md index 14392f87..3cfd873d 100644 --- a/Devops.md +++ b/Devops.md @@ -1,6 +1,6 @@ -# 🐳 Docker-Based DevOps Deployment (with Terraform & CI/CD) +# Docker-Based DevOps Deployment (with Terraform & CI/CD) -## 📌 Overview +## Overview This document describes the **Docker-based deployment strategy** for a full-stack application, enhanced with **CI/CD automation using GitHub Actions** and **Infrastructure as Code (IaC) using Terraform**. The focus of this setup includes: @@ -11,7 +11,7 @@ The focus of this setup includes: --- -## 🧩 Application Stack +## Application Stack - **Backend:** Django (REST API) - **Frontend:** React (Vite + TypeScript) @@ -23,7 +23,7 @@ The focus of this setup includes: --- -## 🛠 Docker Containerization +## Docker Containerization ### Backend (Django) - Dockerized using a **Python slim base image** @@ -39,7 +39,7 @@ The focus of this setup includes: --- -## 🔗 Docker Compose Orchestration +## Docker Compose Orchestration - `docker-compose.yml` is used to manage multi-container deployment - Backend and frontend run as **separate services** @@ -55,7 +55,7 @@ The focus of this setup includes: --- -## ▶️ Run Application Using Docker +## Run Application Using Docker ### Prerequisites - Docker @@ -65,7 +65,7 @@ The focus of this setup includes: ```bash docker compose up --build ``` -## ☁️ Terraform (Infrastructure as Code) +## Terraform (Infrastructure as Code) Terraform is used alongside Docker to provision and manage cloud infrastructure required for deployment. @@ -82,3 +82,8 @@ terraform validate terraform plan terraform apply ``` + +## ⚙️ GitHub Actions CI/CD + +GitHub Actions automates Docker image build, push, and Terraform validation on every push to the `main` branch, ensuring consistent deployments and early infrastructure validation. + From 1f42d765ef7f21bdf97983ceb91c7244a887d7d7 Mon Sep 17 00:00:00 2001 From: priyanka pardeshi <140867398+On-cloud7@users.noreply.github.com> Date: Sun, 25 Jan 2026 21:33:15 +0530 Subject: [PATCH 11/11] Revise GitHub Actions CI/CD section in Devops.md Updated section header and clarified GitHub Actions CI/CD description. --- Devops.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Devops.md b/Devops.md index 3cfd873d..09e7676f 100644 --- a/Devops.md +++ b/Devops.md @@ -83,7 +83,7 @@ terraform plan terraform apply ``` -## ⚙️ GitHub Actions CI/CD +## GitHub Actions CI/CD GitHub Actions automates Docker image build, push, and Terraform validation on every push to the `main` branch, ensuring consistent deployments and early infrastructure validation.