Working tree is now the canonical repo. Off-chain play-money + trustless on-chain (FPMM AMM + CLOB via UMA settlement), AI market factory, creator/social/distribution, mobile shell + push, one-command demo + deploy-kit. Secrets excluded (see ENV-AND-KEYS.md). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
125 lines
4.6 KiB
PowerShell
125 lines
4.6 KiB
PowerShell
# Deploy backend API to dev environment (Windows)
|
|
# Run from: c:\Projects\manifold\backend\api
|
|
# Usage: .\deploy-dev-windows.ps1
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
Write-Host "=== Starting dev deployment ===" -ForegroundColor Cyan
|
|
Write-Host "Time: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')"
|
|
|
|
$REDIS_URL = ""
|
|
$DISABLE_REDIS_CACHE = "true"
|
|
|
|
# Check Docker is running
|
|
$dockerStatus = docker info 2>&1
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "ERROR: Docker is not running. Start Docker Desktop first." -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
# Step 1: Build TypeScript
|
|
Write-Host "`n=== Step 1: Building TypeScript ===" -ForegroundColor Yellow
|
|
|
|
Set-Location $PSScriptRoot
|
|
Write-Host "Running tsc -b..."
|
|
yarn tsc -b
|
|
if ($LASTEXITCODE -ne 0) { Write-Host "tsc -b failed" -ForegroundColor Red; exit 1 }
|
|
|
|
Set-Location "$PSScriptRoot\..\..\common"
|
|
Write-Host "Running tsc-alias in common..."
|
|
yarn tsc-alias
|
|
if ($LASTEXITCODE -ne 0) { Write-Host "tsc-alias failed in common" -ForegroundColor Red; exit 1 }
|
|
|
|
Set-Location "$PSScriptRoot\..\shared"
|
|
Write-Host "Running tsc-alias in shared..."
|
|
yarn tsc-alias
|
|
if ($LASTEXITCODE -ne 0) { Write-Host "tsc-alias failed in shared" -ForegroundColor Red; exit 1 }
|
|
|
|
Set-Location $PSScriptRoot
|
|
Write-Host "Running tsc-alias in api..."
|
|
yarn tsc-alias
|
|
if ($LASTEXITCODE -ne 0) { Write-Host "tsc-alias failed in api" -ForegroundColor Red; exit 1 }
|
|
|
|
# Step 2: Prepare dist folder
|
|
Write-Host "`n=== Step 2: Preparing dist folder ===" -ForegroundColor Yellow
|
|
|
|
Set-Location $PSScriptRoot
|
|
if (Test-Path "dist") { Remove-Item -Recurse -Force "dist" }
|
|
New-Item -ItemType Directory -Force -Path "dist\common\lib" | Out-Null
|
|
New-Item -ItemType Directory -Force -Path "dist\backend\shared\lib" | Out-Null
|
|
New-Item -ItemType Directory -Force -Path "dist\backend\api\lib" | Out-Null
|
|
|
|
Copy-Item -Recurse -Force "..\..\common\lib\*" "dist\common\lib\"
|
|
Copy-Item -Recurse -Force "..\shared\lib\*" "dist\backend\shared\lib\"
|
|
Copy-Item -Recurse -Force ".\lib\*" "dist\backend\api\lib\"
|
|
Copy-Item "..\..\yarn.lock" "dist\"
|
|
Copy-Item "package.json" "dist\"
|
|
|
|
Write-Host "dist folder prepared"
|
|
|
|
# Step 3: Build and push Docker image
|
|
Write-Host "`n=== Step 3: Building Docker image ===" -ForegroundColor Yellow
|
|
|
|
$GIT_REVISION = git rev-parse --short HEAD
|
|
$TIMESTAMP = [int][double]::Parse((Get-Date -UFormat %s))
|
|
$IMAGE_TAG = "$TIMESTAMP-$GIT_REVISION"
|
|
$IMAGE_URL = "us-east4-docker.pkg.dev/dev-mantic-markets/builds/api:$IMAGE_TAG"
|
|
|
|
Write-Host "Building image: $IMAGE_URL"
|
|
docker build . --tag $IMAGE_URL --platform linux/amd64
|
|
if ($LASTEXITCODE -ne 0) { Write-Host "Docker build failed" -ForegroundColor Red; exit 1 }
|
|
|
|
Write-Host "`n=== Step 4: Pushing Docker image ===" -ForegroundColor Yellow
|
|
docker push $IMAGE_URL
|
|
if ($LASTEXITCODE -ne 0) { Write-Host "Docker push failed" -ForegroundColor Red; exit 1 }
|
|
|
|
# Step 5: Create instance template
|
|
Write-Host "`n=== Step 5: Creating instance template ===" -ForegroundColor Yellow
|
|
|
|
$TEMPLATE_NAME = "api-$IMAGE_TAG"
|
|
Write-Host "Creating template: $TEMPLATE_NAME"
|
|
|
|
gcloud compute instance-templates create-with-container $TEMPLATE_NAME `
|
|
--project=dev-mantic-markets `
|
|
--image-project="cos-cloud" `
|
|
--image-family="cos-121-lts" `
|
|
--container-image=$IMAGE_URL `
|
|
--machine-type=e2-small `
|
|
--boot-disk-size=100GB `
|
|
--container-env="NEXT_PUBLIC_FIREBASE_ENV=DEV,GOOGLE_CLOUD_PROJECT=dev-mantic-markets,REDIS_URL=$REDIS_URL,DISABLE_REDIS_CACHE=$DISABLE_REDIS_CACHE" `
|
|
--no-user-output-enabled `
|
|
--scopes="default,cloud-platform" `
|
|
--tags=lb-health-check
|
|
|
|
if ($LASTEXITCODE -ne 0) { Write-Host "Template creation failed" -ForegroundColor Red; exit 1 }
|
|
|
|
# Step 6: Start rollout
|
|
Write-Host "`n=== Step 6: Starting rollout ===" -ForegroundColor Yellow
|
|
|
|
gcloud compute instance-groups managed rolling-action start-update api-group-east `
|
|
--project=dev-mantic-markets `
|
|
--zone=us-east4-a `
|
|
--version=template=$TEMPLATE_NAME `
|
|
--no-user-output-enabled `
|
|
--max-unavailable=0 `
|
|
--max-surge=1
|
|
|
|
if ($LASTEXITCODE -ne 0) { Write-Host "Rollout failed to start" -ForegroundColor Red; exit 1 }
|
|
|
|
# Step 7: Wait for completion
|
|
Write-Host "`n=== Step 7: Waiting for rollout to complete ===" -ForegroundColor Yellow
|
|
Write-Host "This usually takes 2-5 minutes..."
|
|
|
|
gcloud compute instance-groups managed wait-until --stable api-group-east `
|
|
--project=dev-mantic-markets `
|
|
--zone=us-east4-a
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "Rollout may have failed. Check GCP console." -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "`n=== Deployment complete! ===" -ForegroundColor Green
|
|
Write-Host "Time: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')"
|
|
Write-Host "Your backend changes are now live on dev."
|