-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-build.ps1
More file actions
112 lines (92 loc) · 4.74 KB
/
docker-build.ps1
File metadata and controls
112 lines (92 loc) · 4.74 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
# PowerShell script for building and running Flask Chat Server Docker containers
# docker-build.ps1
param(
[Parameter(Mandatory=$false)]
[ValidateSet("development", "production")]
[string]$Environment = "development",
[Parameter(Mandatory=$false)]
[switch]$BuildOnly,
[Parameter(Mandatory=$false)]
[switch]$NoCache,
[Parameter(Mandatory=$false)]
[switch]$Help
)
# Function to display usage
function Show-Usage {
Write-Host "Usage: .\docker-build.ps1 [OPTIONS]" -ForegroundColor Blue
Write-Host "Options:" -ForegroundColor Blue
Write-Host " -Environment ENVIRONMENT Set environment (development|production) [default: development]" -ForegroundColor White
Write-Host " -BuildOnly Build only, don't run containers" -ForegroundColor White
Write-Host " -NoCache Build without using cache" -ForegroundColor White
Write-Host " -Help Show this help message" -ForegroundColor White
Write-Host ""
Write-Host "Examples:" -ForegroundColor Yellow
Write-Host " .\docker-build.ps1 # Build and run development environment" -ForegroundColor Gray
Write-Host " .\docker-build.ps1 -Environment production # Build and run production environment" -ForegroundColor Gray
Write-Host " .\docker-build.ps1 -BuildOnly -NoCache # Build only with no cache" -ForegroundColor Gray
}
# Show help if requested
if ($Help) {
Show-Usage
exit 0
}
Write-Host "🐳 Flask Chat Server Docker Build Script" -ForegroundColor Blue
Write-Host "=========================================" -ForegroundColor Blue
Write-Host "Environment: $Environment" -ForegroundColor Yellow
Write-Host "Build only: $BuildOnly" -ForegroundColor Yellow
Write-Host "No cache: $NoCache" -ForegroundColor Yellow
Write-Host ""
# Check if .env file exists
if (-not (Test-Path ".env")) {
Write-Host "⚠️ Warning: .env file not found. Make sure to create one with your configuration." -ForegroundColor Yellow
Write-Host ""
}
# Set Docker build args
$BuildArgs = @()
if ($NoCache) {
$BuildArgs += "--no-cache"
}
try {
# Build based on environment
if ($Environment -eq "development") {
Write-Host "🔧 Building development environment..." -ForegroundColor Green
# Build development image
Write-Host "Building development image..." -ForegroundColor Blue
$dockerCmd = "docker build " + ($BuildArgs -join " ") + " -f Dockerfile.dev -t transcribe-chat:dev ."
Invoke-Expression $dockerCmd
if (-not $BuildOnly) {
Write-Host "Starting development environment..." -ForegroundColor Blue
docker-compose -f docker-compose.chat.yml up -d chat-server
Write-Host "✅ Development environment started!" -ForegroundColor Green
Write-Host "📊 Chat Server: http://localhost:5000" -ForegroundColor Yellow
Write-Host "🏥 Health Check: http://localhost:5000/health" -ForegroundColor Yellow
Write-Host ""
Write-Host "To view logs: docker-compose -f docker-compose.chat.yml logs -f chat-server" -ForegroundColor Blue
Write-Host "To stop: docker-compose -f docker-compose.chat.yml down" -ForegroundColor Blue
}
} elseif ($Environment -eq "production") {
Write-Host "🚀 Building production environment..." -ForegroundColor Green
# Build production image
Write-Host "Building production image..." -ForegroundColor Blue
$dockerCmd = "docker build " + ($BuildArgs -join " ") + " -f Dockerfile.production -t transcribe-chat:prod ."
Invoke-Expression $dockerCmd
if (-not $BuildOnly) {
Write-Host "Starting production environment..." -ForegroundColor Blue
docker-compose -f docker-compose.chat.yml --profile production up -d chat-server-prod
Write-Host "✅ Production environment started!" -ForegroundColor Green
Write-Host "📊 Chat Server: http://localhost:5001" -ForegroundColor Yellow
Write-Host "🏥 Health Check: http://localhost:5001/health" -ForegroundColor Yellow
Write-Host ""
Write-Host "To view logs: docker-compose -f docker-compose.chat.yml logs -f chat-server-prod" -ForegroundColor Blue
Write-Host "To stop: docker-compose -f docker-compose.chat.yml --profile production down" -ForegroundColor Blue
}
}
if ($BuildOnly) {
Write-Host "✅ Build completed successfully!" -ForegroundColor Green
}
Write-Host ""
Write-Host "🎉 Done!" -ForegroundColor Green
} catch {
Write-Host "❌ Error occurred: $($_.Exception.Message)" -ForegroundColor Red
exit 1
}