mirror of
https://github.com/IS1DI/x0gp.git
synced 2026-07-16 20:47:55 +00:00
- Add Dockerfile.fast which packages a pre-built binary instead of compiling inside the container. - Add scripts/build-fast.ps1 (PowerShell) and scripts/build-fast.sh (Bash) to automate local cross-compilation (CGO_ENABLED=0 GOOS=linux) and Docker packaging. - Set executable bit for build-fast.sh.
50 lines
1.5 KiB
PowerShell
50 lines
1.5 KiB
PowerShell
# PowerShell script for fast Docker build using host compilation
|
|
param (
|
|
[string]$Arch = "arm64",
|
|
[string]$Tag = "x0gp-server:latest"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
# Navigate to the server root directory if not already there
|
|
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$ServerDir = Split-Path -Parent $ScriptDir
|
|
Push-Location $ServerDir
|
|
|
|
try {
|
|
Write-Host "Building Go binary for OS=linux, ARCH=$Arch..." -ForegroundColor Cyan
|
|
|
|
# Setup temporary binary path
|
|
$BinPath = "bin/poc-server-linux-$Arch"
|
|
if (!(Test-Path "bin")) {
|
|
New-Item -ItemType Directory -Path "bin" | Out-Null
|
|
}
|
|
|
|
# Configure cross-compilation environment variables
|
|
$env:CGO_ENABLED = "0"
|
|
$env:GOOS = "linux"
|
|
$env:GOARCH = $Arch
|
|
|
|
# Compile
|
|
go build -ldflags="-s -w" -o $BinPath ./cmd/poc-server
|
|
|
|
Write-Host "Go binary successfully compiled: $BinPath" -ForegroundColor Green
|
|
Write-Host "Building Docker image '$Tag'..." -ForegroundColor Cyan
|
|
|
|
# Run docker build
|
|
docker build --build-arg BINARY_PATH=$BinPath -t $Tag -f Dockerfile.fast .
|
|
|
|
Write-Host "`nDocker image '$Tag' built successfully!" -ForegroundColor Green
|
|
}
|
|
catch {
|
|
Write-Host "Error occurred: $_" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
finally {
|
|
# Restore environment variables
|
|
Remove-Item env:CGO_ENABLED -ErrorAction SilentlyContinue
|
|
Remove-Item env:GOOS -ErrorAction SilentlyContinue
|
|
Remove-Item env:GOARCH -ErrorAction SilentlyContinue
|
|
Pop-Location
|
|
}
|