-
Notifications
You must be signed in to change notification settings - Fork 930
Update deploy_django_app.sh #15
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 | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -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 | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
Comment on lines
18
to
21
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. Missing closing brace for The Apply this diff to add the missing closing brace: deploy() {
docker build -t notes-app .
dockercompose up
+}📝 Committable suggestion
Suggested change
🧰 Tools🪛 Shellcheck (0.11.0)[error] 18-18: Couldn't parse this brace group. Fix to allow more checks. (SC1073) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
| # Clone the code | ||||||||||||||||||||||||||||||||||
| if ! code_clone; then | ||||||||||||||||||||||||||||||||||
| if ! clone; then | ||||||||||||||||||||||||||||||||||
| cd django-notes-app || exit 1 | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+22
to
24
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. Fix inverted conditional logic for clone. The logic is backwards: 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 1Alternatively, 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # 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 | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
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.
Fix invalid Docker Compose command syntax.
Line 20 uses
dockercompose up, which is not a valid command. It should be eitherdocker-compose upordocker compose up(depending on your Docker installation).Apply this diff:
📝 Committable suggestion
🤖 Prompt for AI Agents