-
Notifications
You must be signed in to change notification settings - Fork 828
Expand file tree
/
Copy pathbuild.ps1
More file actions
171 lines (141 loc) · 5.13 KB
/
Copy pathbuild.ps1
File metadata and controls
171 lines (141 loc) · 5.13 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
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Build and manage camofox-browser on Windows (PowerShell alternative to Makefile).
.DESCRIPTION
Provides the same targets as the Makefile for Windows users without make:
build - Download Camoufox + yt-dlp, then build the Docker image.
up - Build (if needed) and run the container.
down - Stop and remove the container.
reset - Full rebuild from scratch.
clean - Remove downloaded binaries.
fetch - Download Camoufox + yt-dlp binaries only.
.PARAMETER Target
The action to perform: build, up, down, reset, clean, fetch (default: build).
.PARAMETER Arch
Target architecture: x86_64 or aarch64 (default: x86_64).
.PARAMETER CamoufoxVersion
Camoufox version (default: 135.0.1).
.PARAMETER CamoufoxRelease
Camoufox release channel (default: beta.24).
.PARAMETER ContainerName
Docker container name (default: camofox-browser).
.PARAMETER HostPort
Host port to map (default: 9377).
.EXAMPLE
.\build.ps1 up # Build + run
.\build.ps1 down # Stop container
.\build.ps1 fetch # Download binaries only
#>
param(
[ValidateSet('build', 'up', 'down', 'reset', 'clean', 'fetch')]
[string]$Target = 'build',
[ValidateSet('x86_64', 'aarch64')]
[string]$Arch = 'x86_64',
[string]$CamoufoxVersion = '135.0.1',
[string]$CamoufoxRelease = 'beta.24',
[string]$ContainerName = 'camofox-browser',
[int]$HostPort = 9377
)
$ErrorActionPreference = 'Stop'
$ProjectRoot = Split-Path -Parent $PSCommandPath
$DistDir = Join-Path $ProjectRoot 'dist'
$CamoufoxZip = Join-Path $DistDir "camoufox-$Arch.zip"
$YtDlpBin = Join-Path $DistDir "yt-dlp-$Arch"
$ImageTag = "camofox-browser:$CamoufoxVersion-$Arch"
$ContainerPort = 9377
# Map architecture to upstream release filenames
if ($Arch -eq 'aarch64') {
$CamoufoxArch = 'arm64'
$YtDlpSuffix = '_aarch64'
} else {
$CamoufoxArch = 'x86_64'
$YtDlpSuffix = ''
}
$CamoufoxUrl = "https://github.com/daijro/camoufox/releases/download/v$CamoufoxVersion-$CamoufoxRelease/camoufox-$CamoufoxVersion-$CamoufoxRelease-lin.$CamoufoxArch.zip"
$YtDlpUrl = "https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_linux$YtDlpSuffix"
function Write-Step {
param([string]$Message)
Write-Host ">>> $Message" -ForegroundColor Cyan
}
function Invoke-Fetch {
Write-Step "Creating dist directory..."
New-Item -ItemType Directory -Path $DistDir -Force | Out-Null
if (-not (Test-Path $CamoufoxZip)) {
Write-Step "Downloading Camoufox browser ($CamoufoxArch)..."
Write-Host " URL: $CamoufoxUrl"
curl.exe -L -o $CamoufoxZip $CamoufoxUrl
Write-Host " Downloaded: $(Get-Item $CamoufoxZip | Select-Object -ExpandProperty Length) bytes"
} else {
Write-Host " [SKIP] Camoufox already downloaded"
}
if (-not (Test-Path $YtDlpBin)) {
Write-Step "Downloading yt-dlp ($Arch)..."
Write-Host " URL: $YtDlpUrl"
curl.exe -L -o $YtDlpBin $YtDlpUrl
Write-Host " Downloaded: $(Get-Item $YtDlpBin | Select-Object -ExpandProperty Length) bytes"
} else {
Write-Host " [SKIP] yt-dlp already downloaded"
}
}
function Invoke-Build {
Invoke-Fetch
Write-Step "Building Docker image: $ImageTag"
docker build `
--build-arg "ARCH=$Arch" `
--build-arg "CAMOUFOX_VERSION=$CamoufoxVersion" `
--build-arg "CAMOUFOX_RELEASE=$CamoufoxRelease" `
-t $ImageTag `
-f (Join-Path $ProjectRoot 'Dockerfile') `
$ProjectRoot
}
function Invoke-Up {
# Check if image exists
$imageExists = docker images -q $ImageTag 2>$null
if (-not $imageExists) {
Write-Step "Image not found — building first..."
Invoke-Build
}
# Stop & remove existing container
docker stop $ContainerName 2>$null | Out-Null
docker rm $ContainerName 2>$null | Out-Null
Write-Step "Starting container: $ContainerName on port $HostPort"
docker run -d `
--restart unless-stopped `
--name $ContainerName `
-p "${HostPort}:${ContainerPort}" `
$ImageTag
Write-Host "Container started. Server should be available at http://localhost:$HostPort" -ForegroundColor Green
Write-Host "Check logs: docker logs $ContainerName" -ForegroundColor Gray
}
function Invoke-Down {
Write-Step "Stopping container: $ContainerName"
docker stop $ContainerName 2>$null
docker rm $ContainerName 2>$null
Write-Host "Container stopped and removed." -ForegroundColor Green
}
function Invoke-Reset {
Invoke-Down
Write-Step "Removing Docker image: $ImageTag"
docker rmi $ImageTag 2>$null
Invoke-Build
Invoke-Up
}
function Invoke-Clean {
Write-Step "Removing dist directory..."
if (Test-Path $DistDir) {
Remove-Item -Recurse -Force $DistDir
Write-Host "Removed: $DistDir" -ForegroundColor Green
} else {
Write-Host "Nothing to clean." -ForegroundColor Yellow
}
}
# --- Main dispatch ---
switch ($Target) {
'build' { Invoke-Build }
'up' { Invoke-Up }
'down' { Invoke-Down }
'reset' { Invoke-Reset }
'clean' { Invoke-Clean }
'fetch' { Invoke-Fetch }
}