-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-deploy.sh
More file actions
211 lines (179 loc) · 5.18 KB
/
docker-deploy.sh
File metadata and controls
211 lines (179 loc) · 5.18 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/bin/bash
# ============================================
# Chronos Docker Deployment Script
# ============================================
# Quick deployment script for Chronos
# Usage: ./docker-deploy.sh [start|stop|restart|logs|status]
# ============================================
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Functions
print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
check_prerequisites() {
print_info "Checking prerequisites..."
if ! command -v docker &> /dev/null; then
print_error "Docker is not installed. Please install Docker first."
exit 1
fi
if ! command -v docker-compose &> /dev/null; then
print_error "Docker Compose is not installed. Please install Docker Compose first."
exit 1
fi
print_success "Prerequisites check passed"
}
setup_environment() {
if [ ! -f .env ]; then
print_info "Setting up environment file..."
cp .env.example .env
print_warning "Please edit .env file with your configuration before starting"
print_info "Default environment file created from .env.example"
else
print_success "Environment file already exists"
fi
}
start_services() {
print_info "Starting Chronos services..."
docker-compose up -d --build
print_info "Waiting for services to be ready..."
sleep 10
print_success "Chronos is now running!"
echo ""
echo -e "${GREEN}=====================================${NC}"
echo -e "${GREEN}Access the application:${NC}"
echo -e "${GREEN} Frontend: http://localhost${NC}"
echo -e "${GREEN} Backend: http://localhost:8000${NC}"
echo -e "${GREEN} API Docs: http://localhost:8000/docs${NC}"
echo -e "${GREEN}=====================================${NC}"
}
stop_services() {
print_info "Stopping Chronos services..."
docker-compose down
print_success "Chronos services stopped"
}
restart_services() {
print_info "Restarting Chronos services..."
docker-compose restart
print_success "Chronos services restarted"
}
show_logs() {
docker-compose logs -f
}
show_status() {
print_info "Chronos Services Status:"
echo ""
docker-compose ps
echo ""
print_info "Service Health:"
echo ""
# Check frontend
if curl -s http://localhost/health > /dev/null 2>&1; then
print_success "Frontend: Healthy"
else
print_error "Frontend: Not responding"
fi
# Check backend
if curl -s http://localhost:8000/health > /dev/null 2>&1; then
print_success "Backend: Healthy"
else
print_error "Backend: Not responding"
fi
# Check database
if docker-compose ps database | grep -q "healthy"; then
print_success "Database: Healthy"
else
print_warning "Database: Status unknown"
fi
}
backup_database() {
print_info "Backing up database..."
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
BACKUP_FILE="backup_${TIMESTAMP}.sql"
docker exec chronos-database mysqldump -u chronos -pchronos_password chronos > "$BACKUP_FILE"
print_success "Database backup created: $BACKUP_FILE"
}
restore_database() {
if [ -z "$1" ]; then
print_error "Please specify backup file: ./docker-deploy.sh restore <backup.sql>"
exit 1
fi
print_warning "Restoring database from $1..."
print_warning "This will overwrite the current database!"
read -p "Are you sure? (yes/no): " confirm
if [ "$confirm" = "yes" ]; then
docker exec -i chronos-database mysql -u chronos -pchronos_password chronos < "$1"
print_success "Database restored from $1"
else
print_info "Database restore cancelled"
fi
}
show_help() {
echo "Chronos Docker Deployment Script"
echo ""
echo "Usage: ./docker-deploy.sh [command]"
echo ""
echo "Commands:"
echo " start - Start all services"
echo " stop - Stop all services"
echo " restart - Restart all services"
echo " logs - View service logs"
echo " status - Show service status"
echo " backup - Backup database"
echo " restore - Restore database from backup"
echo " help - Show this help message"
echo ""
echo "Examples:"
echo " ./docker-deploy.sh start"
echo " ./docker-deploy.sh logs"
echo " ./docker-deploy.sh backup"
echo " ./docker-deploy.sh restore backup_20240101_120000.sql"
}
# Main script
check_prerequisites
case "${1:-start}" in
start)
setup_environment
start_services
;;
stop)
stop_services
;;
restart)
restart_services
;;
logs)
show_logs
;;
status)
show_status
;;
backup)
backup_database
;;
restore)
restore_database "$2"
;;
help|--help|-h)
show_help
;;
*)
print_error "Unknown command: $1"
show_help
exit 1
;;
esac