Add sync agent to go_example_1.ps1 for automatic P2P replication
The go script now builds and starts the can-sync agent alongside CAN service and Paste UI. Any machine that clones the repo and runs the script will auto-discover other instances via iroh's relay network using the shared passphrase "duke-canman-sync" — no port forwarding or manual peer configuration needed. Changes: - Add sync_api_key to root config.yaml (enables sync API) - Update can-sync config.yaml with matching key and shared passphrase - Update go_example_1.ps1 to build and launch can-sync agent - Script now manages 3 processes: CAN service, Paste UI, sync agent Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
7b54bbe892
commit
23e5e0712e
@ -3,3 +3,4 @@ admin_token: "super_secret_rebuild"
|
|||||||
enable_thumbnail_cache: true
|
enable_thumbnail_cache: true
|
||||||
rebuild_error_threshold: 50
|
rebuild_error_threshold: 50
|
||||||
verify_interval_hours: 12
|
verify_interval_hours: 12
|
||||||
|
sync_api_key: "can-sync-default-key"
|
||||||
|
|||||||
@ -1,13 +1,20 @@
|
|||||||
# CAN Sync v2 configuration
|
# CAN Sync v2 configuration
|
||||||
|
#
|
||||||
|
# This config is used by the go_example_1.ps1 script.
|
||||||
|
# All machines that clone this repo and run the script will
|
||||||
|
# auto-discover each other via iroh's relay network as long
|
||||||
|
# as they share the same sync_passphrase.
|
||||||
|
|
||||||
# URL of the local CAN Service (sync API is at /sync/*)
|
# URL of the local CAN Service (sync API is at /sync/*)
|
||||||
can_service_url: "http://127.0.0.1:3210"
|
can_service_url: "http://127.0.0.1:3210"
|
||||||
|
|
||||||
# API key for CAN service's sync endpoints (must match sync_api_key in CAN config)
|
# API key for CAN service's sync endpoints (must match sync_api_key in CAN config)
|
||||||
sync_api_key: "changeme"
|
sync_api_key: "can-sync-default-key"
|
||||||
|
|
||||||
# Shared passphrase for peer discovery (all peers must use the same one)
|
# Shared passphrase for peer discovery — all peers with the same passphrase
|
||||||
sync_passphrase: "my-shared-secret"
|
# find each other automatically over the internet via iroh relay servers.
|
||||||
|
# Change this to something unique to your team/project.
|
||||||
|
sync_passphrase: "duke-canman-sync"
|
||||||
|
|
||||||
# Seconds between polls for new local assets
|
# Seconds between fallback polls (SSE handles instant sync, this is a safety net)
|
||||||
poll_interval_secs: 3
|
poll_interval_secs: 30
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
# go_example_1.ps1 — Start CanService + Paste example, open browser
|
# go_example_1.ps1 — Start CanService + Paste + Sync agent, open browser
|
||||||
|
#
|
||||||
|
# Run on multiple machines (after git clone) and they will auto-sync
|
||||||
|
# all ingested assets via iroh's relay network. No port forwarding needed.
|
||||||
|
|
||||||
$ErrorActionPreference = "Stop"
|
$ErrorActionPreference = "Stop"
|
||||||
$root = $PSScriptRoot
|
$root = $PSScriptRoot
|
||||||
@ -11,13 +14,19 @@ Get-NetTCPConnection -LocalPort 3211 -ErrorAction SilentlyContinue |
|
|||||||
ForEach-Object { Stop-Process -Id $_.OwningProcess -Force -ErrorAction SilentlyContinue }
|
ForEach-Object { Stop-Process -Id $_.OwningProcess -Force -ErrorAction SilentlyContinue }
|
||||||
Start-Sleep -Milliseconds 500
|
Start-Sleep -Milliseconds 500
|
||||||
|
|
||||||
|
# --- Build everything ---
|
||||||
|
|
||||||
Write-Host "Building CanService..." -ForegroundColor Cyan
|
Write-Host "Building CanService..." -ForegroundColor Cyan
|
||||||
cargo build --manifest-path "$root\Cargo.toml"
|
cargo build --manifest-path "$root\Cargo.toml"
|
||||||
|
|
||||||
Write-Host "Building Paste example..." -ForegroundColor Cyan
|
Write-Host "Building Paste example..." -ForegroundColor Cyan
|
||||||
cargo build --manifest-path "$root\examples\paste\Cargo.toml"
|
cargo build --manifest-path "$root\examples\paste\Cargo.toml"
|
||||||
|
|
||||||
# Start CanService in background
|
Write-Host "Building CAN Sync agent..." -ForegroundColor Cyan
|
||||||
|
cargo build --manifest-path "$root\examples\can-sync\Cargo.toml" --bin can-sync
|
||||||
|
|
||||||
|
# --- Start CanService ---
|
||||||
|
|
||||||
Write-Host "Starting CanService on port 3210..." -ForegroundColor Green
|
Write-Host "Starting CanService on port 3210..." -ForegroundColor Green
|
||||||
$canService = Start-Process -FilePath "cargo" `
|
$canService = Start-Process -FilePath "cargo" `
|
||||||
-ArgumentList "run --manifest-path `"$root\Cargo.toml`"" `
|
-ArgumentList "run --manifest-path `"$root\Cargo.toml`"" `
|
||||||
@ -43,7 +52,20 @@ if (-not $ready) {
|
|||||||
}
|
}
|
||||||
Write-Host "CanService ready." -ForegroundColor Green
|
Write-Host "CanService ready." -ForegroundColor Green
|
||||||
|
|
||||||
# Start Paste example (it opens the browser itself)
|
# --- Start Sync agent ---
|
||||||
|
|
||||||
|
$syncConfig = "$root\examples\can-sync\config.yaml"
|
||||||
|
Write-Host "Starting CAN Sync agent (P2P replication)..." -ForegroundColor Green
|
||||||
|
$syncAgent = Start-Process -FilePath "cargo" `
|
||||||
|
-ArgumentList "run --manifest-path `"$root\examples\can-sync\Cargo.toml`" --bin can-sync -- `"$syncConfig`"" `
|
||||||
|
-WorkingDirectory $root `
|
||||||
|
-PassThru -NoNewWindow
|
||||||
|
|
||||||
|
# Give sync agent a moment to connect to CAN service
|
||||||
|
Start-Sleep -Seconds 2
|
||||||
|
|
||||||
|
# --- Start Paste example ---
|
||||||
|
|
||||||
Write-Host "Starting Paste on port 3211..." -ForegroundColor Green
|
Write-Host "Starting Paste on port 3211..." -ForegroundColor Green
|
||||||
$paste = Start-Process -FilePath "cargo" `
|
$paste = Start-Process -FilePath "cargo" `
|
||||||
-ArgumentList "run --manifest-path `"$root\examples\paste\Cargo.toml`"" `
|
-ArgumentList "run --manifest-path `"$root\examples\paste\Cargo.toml`"" `
|
||||||
@ -54,16 +76,22 @@ Write-Host ""
|
|||||||
Write-Host "Running:" -ForegroundColor Cyan
|
Write-Host "Running:" -ForegroundColor Cyan
|
||||||
Write-Host " CanService -> http://127.0.0.1:3210"
|
Write-Host " CanService -> http://127.0.0.1:3210"
|
||||||
Write-Host " Paste UI -> http://127.0.0.1:3211"
|
Write-Host " Paste UI -> http://127.0.0.1:3211"
|
||||||
|
Write-Host " CAN Sync -> P2P replication active (iroh relay)" -ForegroundColor Magenta
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
Write-Host "Press Ctrl+C to stop both." -ForegroundColor Yellow
|
Write-Host "Sync passphrase: 'duke-canman-sync'" -ForegroundColor Magenta
|
||||||
|
Write-Host "Any other machine running this script with the same passphrase" -ForegroundColor Magenta
|
||||||
|
Write-Host "will automatically discover this instance and sync all assets." -ForegroundColor Magenta
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "Press Ctrl+C to stop all services." -ForegroundColor Yellow
|
||||||
|
|
||||||
# Wait for either process to exit, then clean up both
|
# Wait for any process to exit, then clean up all
|
||||||
try {
|
try {
|
||||||
while (-not $canService.HasExited -and -not $paste.HasExited) {
|
while (-not $canService.HasExited -and -not $paste.HasExited -and -not $syncAgent.HasExited) {
|
||||||
Start-Sleep -Seconds 1
|
Start-Sleep -Seconds 1
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
Write-Host "Shutting down..." -ForegroundColor Yellow
|
Write-Host "Shutting down..." -ForegroundColor Yellow
|
||||||
Stop-Process -Id $canService.Id -Force -ErrorAction SilentlyContinue
|
Stop-Process -Id $canService.Id -Force -ErrorAction SilentlyContinue
|
||||||
Stop-Process -Id $paste.Id -Force -ErrorAction SilentlyContinue
|
Stop-Process -Id $paste.Id -Force -ErrorAction SilentlyContinue
|
||||||
|
Stop-Process -Id $syncAgent.Id -Force -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user