Skip to content
Open
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
66 changes: 15 additions & 51 deletions day03/deploy_django_app.sh
Original file line number Diff line number Diff line change
@@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Fix invalid Docker Compose command syntax.

Line 20 uses dockercompose up, which is not a valid command. It should be either docker-compose up or docker compose up (depending on your Docker installation).

Apply this diff:

-    dockercompose up 
+    docker-compose up
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
dockercompose up
docker-compose up
🤖 Prompt for AI Agents
In day03/deploy_django_app.sh around line 20, the script calls the invalid
command "dockercompose up"; replace it with a valid Docker Compose
invocation—either "docker-compose up" (hyphenated standalone CLI) or "docker
compose up" (Docker CLI plugin), matching the project's Docker setup; update the
script to use the correct command and ensure any flags (e.g., -d) or
environment/working-directory expectations remain as before.


Comment on lines 18 to 21
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Missing closing brace for deploy() function.

The deploy() function definition starts at line 18 but is never closed. This is confirmed by the shellcheck error "Couldn't parse this brace group" (SC1073).

Apply this diff to add the missing closing brace:

 deploy() {
     docker build -t notes-app . 
     dockercompose up 
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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
deploy() {
docker build -t notes-app .
dockercompose up
}
🧰 Tools
🪛 Shellcheck (0.11.0)

[error] 18-18: Couldn't parse this brace group. Fix to allow more checks.

(SC1073)

🤖 Prompt for AI Agents
In day03/deploy_django_app.sh around lines 18 to 21, the deploy() function is
missing its closing brace; add a single closing curly brace "}" after the docker
build/dockercompose lines to properly terminate the function (ensure it's on its
own line and the file ends with a newline).

# Clone the code
if ! code_clone; then
if ! clone; then
cd django-notes-app || exit 1
fi
Comment on lines +22 to 24
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Fix inverted conditional logic for clone.

The logic is backwards: if ! clone; means "if clone fails", but then the code attempts to cd django-notes-app, which would not exist if the clone failed. This will cause incorrect behavior.

Apply this diff to fix the logic:

-if ! clone; then
-    cd django-notes-app || exit 1
-fi
+clone || exit 1
+cd django-notes-app || exit 1

Alternatively, if you prefer the if-statement style for consistency with other checks:

-if ! clone; then
+if clone; then
     cd django-notes-app || exit 1
+else
+    exit 1
 fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if ! clone; then
cd django-notes-app || exit 1
fi
clone || exit 1
cd django-notes-app || exit 1
🤖 Prompt for AI Agents
In day03/deploy_django_app.sh around lines 22 to 24, the conditional is
inverted: it currently does "if ! clone; then cd django-notes-app || exit 1 fi"
which tries to cd when clone failed; change the logic so that on successful
clone you cd into the repo and on failure you exit. For example, call clone and
on success run "cd django-notes-app || exit 1"; on failure exit with non-zero;
or use the if-statement style "if clone; then cd django-notes-app || exit 1;
else exit 1; fi" so the script only attempts to cd when the clone succeeded.


# 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

Expand Down