-
Notifications
You must be signed in to change notification settings - Fork 928
Update deploy_django_app.sh #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,33 +3,22 @@ | |||||||||||||||||
| # Deploy a Django app and handle errors | ||||||||||||||||||
|
|
||||||||||||||||||
| # Function to clone the Django app code | ||||||||||||||||||
| code_clone() { | ||||||||||||||||||
| 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 | ||||||||||||||||||
| git clone https://github.com/LondheShubham153/django-notes-app.git | ||||||||||||||||||
|
|
||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| # Function to install required dependencies | ||||||||||||||||||
| install_requirements() { | ||||||||||||||||||
| install() { | ||||||||||||||||||
| echo "Installing dependencies..." | ||||||||||||||||||
| sudo apt-get update && sudo apt-get install -y docker.io nginx docker-compose || { | ||||||||||||||||||
| echo "Failed to install dependencies." | ||||||||||||||||||
| return 1 | ||||||||||||||||||
| } | ||||||||||||||||||
| sudo apt-get update && sudo apt-get install -y docker.io nginx docker-compose-v2 | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| # Function to perform required restarts | ||||||||||||||||||
| required_restarts() { | ||||||||||||||||||
| restart() { | ||||||||||||||||||
| echo "Performing required restarts..." | ||||||||||||||||||
| sudo chown "$USER" /var/run/docker.sock || { | ||||||||||||||||||
| echo "Failed to change ownership of docker.sock." | ||||||||||||||||||
| return 1 | ||||||||||||||||||
| #sudo chown "$USER" /var/run/docker.sock | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| # Uncomment the following lines if needed: | ||||||||||||||||||
|
|
@@ -41,27 +30,30 @@ required_restarts() { | |||||||||||||||||
| # 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 | ||||||||||||||||||
| } | ||||||||||||||||||
| docker build -t notes-app . | ||||||||||||||||||
| docker run notes-app | ||||||||||||||||||
| #docker compose up | ||||||||||||||||||
|
|
||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| # Main deployment script | ||||||||||||||||||
| echo "********** DEPLOYMENT STARTED *********" | ||||||||||||||||||
|
|
||||||||||||||||||
| # Clone the code | ||||||||||||||||||
| if ! code_clone; then | ||||||||||||||||||
| if ! clone; then | ||||||||||||||||||
| echo "cloning failed" | ||||||||||||||||||
| cd django-notes-app || exit 1 | ||||||||||||||||||
| fi | ||||||||||||||||||
|
|
||||||||||||||||||
| # Install dependencies | ||||||||||||||||||
| if ! install_requirements; then | ||||||||||||||||||
| if ! install; then | ||||||||||||||||||
| echo "install failed" | ||||||||||||||||||
| exit 1 | ||||||||||||||||||
| fi | ||||||||||||||||||
|
|
||||||||||||||||||
| # Perform required restarts | ||||||||||||||||||
| if ! required_restarts; then | ||||||||||||||||||
| if ! restarts; then | ||||||||||||||||||
| echo"restart failed" | ||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Syntax error: missing space between
Apply this diff to fix the syntax: -echo"restart failed"
+echo "restart failed"📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| exit 1 | ||||||||||||||||||
| fi | ||||||||||||||||||
|
Comment on lines
+55
to
58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function name mismatch: call to Line 55 calls Apply this diff to fix the function name: -if ! restarts; then
+if ! restart; then📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic error: error handling after clone is contradictory.
The script checks if
clonefails (line 43), then prints "cloning failed" (line 44), but immediately attempts to cd into the cloned directory (line 45) regardless. This logic is backwards—if cloning failed, the directory won't exist andcdwill fail. Either thecdshould be outside theifblock or the error handling should actuallyexitafter the failure message.Apply this diff to fix the logic:
🤖 Prompt for AI Agents