-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-build.ps1
142 lines (118 loc) · 4.01 KB
/
docker-build.ps1
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
function Check-DockerInstallation {
if (-not (Get-Command "docker" -ErrorAction SilentlyContinue)) {
Write-Host "❌ Docker is not installed!" -ForegroundColor Red
Write-Host "Please install Docker Desktop from: https://www.docker.com/products/docker-desktop" -ForegroundColor Yellow
return $false
}
try {
docker info | Out-Null
} catch {
Write-Host "❌ Docker is not running!" -ForegroundColor Red
Write-Host "Please start Docker Desktop" -ForegroundColor Yellow
return $false
}
return $true
}
function Build-DockerImage {
param (
[string]$platform
)
$dockerfile = @"
FROM rust:latest
RUN rustup target add x86_64-unknown-linux-musl
RUN rustup target add x86_64-apple-darwin
RUN rustup target add aarch64-apple-darwin
RUN cargo install cross
WORKDIR /app
"@
Write-Host "🐳 Building Docker image for $platform..." -ForegroundColor Cyan
$dockerfile | Out-File -FilePath "Dockerfile" -Encoding utf8
docker build -t hot-reload-builder .
Remove-Item "Dockerfile"
}
function Show-BuildMenu {
Write-Host "`n🚀 Docker Build Menu" -ForegroundColor Cyan
Write-Host "------------------------"
Write-Host "1. Build UI (All platforms)"
Write-Host "2. Build Watcher (All platforms)"
Write-Host "3. Build Everything"
Write-Host "4. Exit"
Write-Host "------------------------"
$choice = Read-Host "Choose an option"
return $choice
}
function Build-Project {
param (
[string]$project,
[string]$target
)
Write-Host "`n🔨 Building $project for $target..." -ForegroundColor Yellow
$volumePath = (Get-Location).Path
$dockerCmd = "docker run --rm -v `"${volumePath}:/app`" hot-reload-builder"
$buildCmd = "cross build --release --target $target -p $project"
Invoke-Expression "$dockerCmd $buildCmd"
if ($LASTEXITCODE -eq 0) {
$binName = if ($target -like "*windows*") { "$project.exe" } else { $project }
$sourcePath = "target/$target/release/$binName"
if (Test-Path $sourcePath) {
$tempDir = "temp_build"
New-Item -Path $tempDir -ItemType Directory -Force | Out-Null
Copy-Item $sourcePath -Destination $tempDir
Copy-Item "config.json" -Destination $tempDir -ErrorAction SilentlyContinue
$zipName = "release/${project}_${target}.zip"
Compress-Archive -Path "$tempDir/*" -DestinationPath $zipName -Force
Remove-Item -Path $tempDir -Recurse -Force
Write-Host " ✅ Created $zipName" -ForegroundColor Green
}
} else {
Write-Host " ❌ Build failed for $target" -ForegroundColor Red
}
}
function Build-AllPlatforms {
param (
[string]$project
)
$targets = @(
"x86_64-pc-windows-msvc",
"x86_64-unknown-linux-musl",
"x86_64-apple-darwin",
"aarch64-apple-darwin"
)
foreach ($target in $targets) {
Build-Project -project $project -target $target
}
}
# Main
Clear-Host
Write-Host "🐳 Docker Build System" -ForegroundColor Magenta
Write-Host "------------------------"
if (-not (Check-DockerInstallation)) {
exit 1
}
New-Item -Path "release" -ItemType Directory -Force | Out-Null
Build-DockerImage
do {
$choice = Show-BuildMenu
switch ($choice) {
"1" {
Build-AllPlatforms -project "hot-reload-ui"
}
"2" {
Build-AllPlatforms -project "hot-reload-watcher"
}
"3" {
Build-AllPlatforms -project "hot-reload-ui"
Build-AllPlatforms -project "hot-reload-watcher"
}
"4" {
Write-Host "`n👋 Goodbye!" -ForegroundColor Cyan
exit 0
}
default {
Write-Host "❌ Invalid option" -ForegroundColor Red
}
}
Write-Host "`nPress any key to continue..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Clear-Host
} while ($true)