forked from LondheShubham153/Shell-Scripting-For-DevOps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy_django_app.sh
More file actions
executable file
·75 lines (63 loc) · 1.77 KB
/
deploy_django_app.sh
File metadata and controls
executable file
·75 lines (63 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/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
}
# 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
}
}
# 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
}
# 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 *********"
# Clone the code
if ! code_clone; then
cd django-notes-app || exit 1
fi
# Install dependencies
if ! install_requirements; then
exit 1
fi
# Perform required restarts
if ! required_restarts; then
exit 1
fi
# Deploy the app
if ! deploy; then
echo "Deployment failed. Mailing the admin..."
# Add your sendmail or notification logic here
exit 1
fi
echo "********** DEPLOYMENT DONE *********"