forked from dplusplus1024/lightning-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·148 lines (122 loc) · 3.91 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·148 lines (122 loc) · 3.91 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
# Enhanced deployment script with better error handling and output
# Load environment variables
if [[ ! -f .env ]]; then
echo "Error: .env file not found!"
exit 1
fi
source .env
# Check for required environment variables
if [[ -z "$DOMAIN" || -z "$DIGITAL_OCEAN_APP_ID" || -z "$DIGITAL_OCEAN_API" ]]; then
echo "Error: Required environment variables missing in .env file"
echo "Please ensure DOMAIN, DIGITAL_OCEAN_APP_ID, and DIGITAL_OCEAN_API are set"
exit 1
fi
# Terminal colors for better output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to display step information
function step() {
echo -e "${BLUE}[$(date +%H:%M:%S)]${NC} $1"
}
# Function to display success messages
function success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
# Function to display warning messages
function warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
# Function to display error messages
function error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if there are changes to commit
step "Checking for changes..."
git diff --quiet && git diff --staged --quiet
if [[ $? -eq 0 ]]; then
warning "Nothing to commit, working tree clean!"
exit 0
fi
# Add and commit changes
step "Adding changes to git..."
git add .
step "Committing changes..."
git commit -m "updated"
# Push changes
step "Pushing to remote repository..."
output=$(git push origin island-bitcoin 2>&1)
echo "$output"
# Check if there was nothing to commit
if [[ "$output" == *"nothing to commit, working tree clean"* ]]; then
warning "Nothing was changed! No need to run https://$DOMAIN/api/notifier/run"
exit 0
fi
# Wait for deployment to start
echo ""
step "Waiting to run https://$DOMAIN/api/notifier/run..."
echo -e "${BLUE}-------------------------------------------------------------${NC}"
# Wait a bit for the deployment to register in DigitalOcean
sleep 5
# Get the most recent deployment ID
step "Fetching recent deployment ID..."
recent_deployment_id=$(curl -s -X GET "https://api.digitalocean.com/v2/apps/$DIGITAL_OCEAN_APP_ID/deployments" \
-H "Authorization: Bearer $DIGITAL_OCEAN_API" \
-H "Content-Type: application/json" | \
jq -r '.deployments[0].id')
if [[ -z "$recent_deployment_id" || "$recent_deployment_id" == "null" ]]; then
error "Failed to get deployment ID. Check your credentials and app ID."
exit 1
fi
success "Found deployment ID: $recent_deployment_id"
# Track the deployment status
prev_status=""
dots=""
step "Monitoring deployment status..."
while true; do
# Get the current deployment status
deployment_status=$(curl -s -X GET "https://api.digitalocean.com/v2/apps/$DIGITAL_OCEAN_APP_ID/deployments/$recent_deployment_id" \
-H "Authorization: Bearer $DIGITAL_OCEAN_API" \
-H "Content-Type: application/json" | \
jq -r '.deployment.phase')
# Handle null status
if [[ -z "$deployment_status" || "$deployment_status" == "null" ]]; then
deployment_status="PENDING"
fi
# Show status change
if [[ "$deployment_status" != "$prev_status" ]]; then
echo -e "\n${YELLOW}Deployment status:${NC} $deployment_status"
prev_status=$deployment_status
dots=""
else
# Show progress with rotating spinner
spinner=("-" "\\" "|" "/")
printf "\r${BLUE}[${spinner[$(($(date +%s) % 4))}]${NC} Waiting... %s" "$dots"
dots="$dots."
if [[ ${#dots} -gt 50 ]]; then
dots="."
fi
fi
# Check for completion
if [[ "$deployment_status" == "ACTIVE" ]]; then
echo ""
success "Deployment completed successfully!"
step "Running notifier..."
# Call the notifier endpoint
notifier_result=$(curl -s "https://$DOMAIN/api/notifier/run")
success "Notifier executed: $notifier_result"
break
fi
# Check for error
if [[ "$deployment_status" == "ERROR" ]]; then
echo ""
error "Deployment failed with status: ERROR"
exit 1
fi
# Wait before checking again
sleep 2
done
success "Deployment process completed!"