From 4b280430d32084f4b0b8826a23f443dcbd7c0779 Mon Sep 17 00:00:00 2001 From: sanchu92 Date: Sat, 8 Nov 2025 14:03:56 +0530 Subject: [PATCH] Update deploy_django_app.sh --- day03/deploy_django_app.sh | 66 +++++++++----------------------------- 1 file changed, 15 insertions(+), 51 deletions(-) diff --git a/day03/deploy_django_app.sh b/day03/deploy_django_app.sh index 4aad1f2..edc1f3f 100755 --- a/day03/deploy_django_app.sh +++ b/day03/deploy_django_app.sh @@ -1,74 +1,38 @@ #!/bin/bash -# Deploy a Django app and handle errors - -# Function to clone the Django app code -code_clone() { - echo "Cloning the Django app..." - if [ -d "django-notes-app" ]; then - echo "The code directory already exists. Skipping clone." - else - git clone https://github.com/LondheShubham153/django-notes-app.git || { - echo "Failed to clone the code." - return 1 - } - fi +clone() { + git clone https://github.com/LondheShubham153/django-notes-app.git } -# Function to install required dependencies -install_requirements() { - echo "Installing dependencies..." - sudo apt-get update && sudo apt-get install -y docker.io nginx docker-compose || { - echo "Failed to install dependencies." - return 1 - } +install() { + sudo apt-get update && sudo apt-get install -y docker.io nginx docker-compose-v2 } -# Function to perform required restarts -required_restarts() { - echo "Performing required restarts..." - sudo chown "$USER" /var/run/docker.sock || { - echo "Failed to change ownership of docker.sock." - return 1 - } - - # Uncomment the following lines if needed: - # sudo systemctl enable docker - # sudo systemctl enable nginx - # sudo systemctl restart docker +restarts() { + sudo chown "$USER" /var/run/docker.sock + sudo systemctl enable docker + sudo systemctl enable nginx + sudo systemctl restart docker } -# Function to deploy the Django app deploy() { - echo "Building and deploying the Django app..." - docker build -t notes-app . && docker-compose up -d || { - echo "Failed to build and deploy the app." - return 1 - } -} - -# Main deployment script -echo "********** DEPLOYMENT STARTED *********" + docker build -t notes-app . + dockercompose up -# Clone the code -if ! code_clone; then +if ! clone; then cd django-notes-app || exit 1 fi -# Install dependencies -if ! install_requirements; then +if ! install; then exit 1 fi -# Perform required restarts -if ! required_restarts; then +if ! restarts; then exit 1 fi -# Deploy the app if ! deploy; then - echo "Deployment failed. Mailing the admin..." - # Add your sendmail or notification logic here + # Add your sendmail or notification logic here exit 1 fi