-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-deploy.ps1
More file actions
219 lines (191 loc) · 6.31 KB
/
docker-deploy.ps1
File metadata and controls
219 lines (191 loc) · 6.31 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
212
213
214
215
216
217
218
219
# ============================================
# Chronos Docker Deployment Script (PowerShell)
# ============================================
# Quick deployment script for Chronos
# Usage: .\docker-deploy.ps1 [start|stop|restart|logs|status]
# ============================================
# Colors
function Write-Info { Write-Host "[INFO] $args" -ForegroundColor Cyan }
function Write-Success { Write-Host "[SUCCESS] $args" -ForegroundColor Green }
function Write-Warning { Write-Host "[WARNING] $args" -ForegroundColor Yellow }
function Write-Error-Custom { Write-Host "[ERROR] $args" -ForegroundColor Red }
# Check prerequisites
function Check-Prerequisites {
Write-Info "Checking prerequisites..."
if (-not (Get-Command docker -ErrorAction SilentlyContinue)) {
Write-Error-Custom "Docker is not installed. Please install Docker Desktop first."
exit 1
}
if (-not (Get-Command docker-compose -ErrorAction SilentlyContinue)) {
Write-Error-Custom "Docker Compose is not installed. Please install Docker Desktop first."
exit 1
}
Write-Success "Prerequisites check passed"
}
# Setup environment
function Setup-Environment {
if (-not (Test-Path .env)) {
Write-Info "Setting up environment file..."
Copy-Item .env.example .env
Write-Warning "Please edit .env file with your configuration before starting"
Write-Info "Default environment file created from .env.example"
} else {
Write-Success "Environment file already exists"
}
}
# Start services
function Start-Services {
Write-Info "Starting Chronos services..."
docker-compose up -d --build
Write-Info "Waiting for services to be ready..."
Start-Sleep -Seconds 10
Write-Success "Chronos is now running!"
Write-Host ""
Write-Host "=====================================" -ForegroundColor Green
Write-Host "Access the application:" -ForegroundColor Green
Write-Host " Frontend: http://localhost" -ForegroundColor Green
Write-Host " Backend: http://localhost:8000" -ForegroundColor Green
Write-Host " API Docs: http://localhost:8000/docs" -ForegroundColor Green
Write-Host "=====================================" -ForegroundColor Green
}
# Stop services
function Stop-Services {
Write-Info "Stopping Chronos services..."
docker-compose down
Write-Success "Chronos services stopped"
}
# Restart services
function Restart-Services {
Write-Info "Restarting Chronos services..."
docker-compose restart
Write-Success "Chronos services restarted"
}
# Show logs
function Show-Logs {
docker-compose logs -f
}
# Show status
function Show-Status {
Write-Info "Chronos Services Status:"
Write-Host ""
docker-compose ps
Write-Host ""
Write-Info "Service Health:"
Write-Host ""
# Check frontend
try {
$response = Invoke-WebRequest -Uri "http://localhost/health" -TimeoutSec 5 -ErrorAction Stop
if ($response.StatusCode -eq 200) {
Write-Success "Frontend: Healthy"
}
} catch {
Write-Error-Custom "Frontend: Not responding"
}
# Check backend
try {
$response = Invoke-WebRequest -Uri "http://localhost:8000/health" -TimeoutSec 5 -ErrorAction Stop
if ($response.StatusCode -eq 200) {
Write-Success "Backend: Healthy"
}
} catch {
Write-Error-Custom "Backend: Not responding"
}
# Check database
$dbStatus = docker-compose ps database
if ($dbStatus -match "healthy") {
Write-Success "Database: Healthy"
} else {
Write-Warning "Database: Status unknown"
}
}
# Backup database
function Backup-Database {
Write-Info "Backing up database..."
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
$backupFile = "backup_${timestamp}.sql"
docker exec chronos-database mysqldump -u chronos -pchronos_password chronos > $backupFile
Write-Success "Database backup created: $backupFile"
}
# Restore database
function Restore-Database {
param(
[Parameter(Mandatory=$true)]
[string]$BackupFile
)
if (-not (Test-Path $BackupFile)) {
Write-Error-Custom "Backup file not found: $BackupFile"
exit 1
}
Write-Warning "Restoring database from $BackupFile..."
Write-Warning "This will overwrite the current database!"
$confirm = Read-Host "Are you sure? (yes/no)"
if ($confirm -eq "yes") {
Get-Content $BackupFile | docker exec -i chronos-database mysql -u chronos -pchronos_password chronos
Write-Success "Database restored from $BackupFile"
} else {
Write-Info "Database restore cancelled"
}
}
# Show help
function Show-Help {
Write-Host "Chronos Docker Deployment Script"
Write-Host ""
Write-Host "Usage: .\docker-deploy.ps1 [command]"
Write-Host ""
Write-Host "Commands:" -ForegroundColor Cyan
Write-Host " start - Start all services"
Write-Host " stop - Stop all services"
Write-Host " restart - Restart all services"
Write-Host " logs - View service logs"
Write-Host " status - Show service status"
Write-Host " backup - Backup database"
Write-Host " restore - Restore database from backup"
Write-Host " help - Show this help message"
Write-Host ""
Write-Host "Examples:" -ForegroundColor Cyan
Write-Host " .\docker-deploy.ps1 start"
Write-Host " .\docker-deploy.ps1 logs"
Write-Host " .\docker-deploy.ps1 backup"
Write-Host " .\docker-deploy.ps1 restore backup_20240101_120000.sql"
}
# Main script
Check-Prerequisites
$command = $args[0]
switch ($command) {
"start" {
Setup-Environment
Start-Services
}
"stop" {
Stop-Services
}
"restart" {
Restart-Services
}
"logs" {
Show-Logs
}
"status" {
Show-Status
}
"backup" {
Backup-Database
}
"restore" {
if ($args[1]) {
Restore-Database -BackupFile $args[1]
} else {
Write-Error-Custom "Please specify backup file: .\docker-deploy.ps1 restore <backup.sql>"
exit 1
}
}
"help" {
Show-Help
}
default {
if ($command) {
Write-Error-Custom "Unknown command: $command"
}
Show-Help
}
}