You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.8 KiB
65 lines
2.8 KiB
# Fase 2+3: cutover Docker stack + redirect 301 legacy subdomain |
|
# Usage: .\scripts\cutover-geonet-console.ps1 |
|
|
|
$ErrorActionPreference = "Stop" |
|
|
|
$HostAddr = "10.100.1.24" |
|
$SshPort = 22 |
|
$SshMac = "hmac-sha1" |
|
$SshUser = "root" |
|
$OldStack = "/opt/stacks/databaselist" |
|
$NewStack = "/opt/stacks/geonet-console" |
|
$ProjectRoot = Split-Path $PSScriptRoot -Parent |
|
$StackDir = Join-Path $ProjectRoot "geonet-console" |
|
$Tarball = Join-Path $ProjectRoot "geonet-console-deploy.tar.gz" |
|
|
|
Write-Host "==> [Fase 2] Pack + upload geonet-console..." |
|
Push-Location $StackDir |
|
tar -czf $Tarball --exclude=".env" --exclude="vendor" --exclude="node_modules" . |
|
Pop-Location |
|
|
|
scp -o BatchMode=yes -o MACs=$SshMac -P $SshPort $Tarball "${SshUser}@${HostAddr}:/tmp/geonet-console-deploy.tar.gz" |
|
|
|
Write-Host "==> [Fase 2] Prepare stack on server..." |
|
$PrepareCmd = @" |
|
set -e |
|
mkdir -p $NewStack |
|
cd $NewStack |
|
tar -xzf /tmp/geonet-console-deploy.tar.gz |
|
find docker -name '*.sh' -exec sed -i 's/\r$//' {} + 2>/dev/null || true |
|
chmod +x docker/postgres-init/*.sh 2>/dev/null || true |
|
cp $OldStack/.env $NewStack/.env |
|
sed -i 's/^APP_NAME=.*/APP_NAME=\"Geonet Console\"/' $NewStack/.env |
|
sed -i 's|^APP_URL=.*|APP_URL=https://console.gisportal.id|' $NewStack/.env |
|
grep -E '^APP_NAME=|^APP_URL=' $NewStack/.env |
|
"@ |
|
ssh -o BatchMode=yes -m $SshMac "${SshUser}@${HostAddr}" -p $SshPort $PrepareCmd |
|
|
|
Write-Host "==> [Fase 2] Build new image..." |
|
ssh -o BatchMode=yes -m $SshMac "${SshUser}@${HostAddr}" -p $SshPort "cd $NewStack && docker compose build" |
|
|
|
Write-Host "==> [Fase 2] Stop old stack, start geonet-console (~30s downtime)..." |
|
ssh -o BatchMode=yes -m $SshMac "${SshUser}@${HostAddr}" -p $SshPort @" |
|
set -e |
|
cd $OldStack && docker compose stop |
|
cd $NewStack && docker compose up -d |
|
sleep 12 |
|
curl -sf -o /dev/null -w 'localhost /up: %{http_code}\n' http://127.0.0.1:8091/up |
|
docker ps --filter name=geonet-console --format 'table {{.Names}}\t{{.Status}}' |
|
"@ |
|
|
|
Write-Host "==> [Fase 3] Deploy redirect 301 databaselist -> console..." |
|
$RedirectConf = Join-Path $StackDir "nginx\databaselist-redirect.conf" |
|
scp -o BatchMode=yes -o MACs=$SshMac -P $SshPort $RedirectConf "${SshUser}@${HostAddr}:/etc/nginx/conf.d/production/databaselist.conf" |
|
ssh -o BatchMode=yes -m $SshMac "${SshUser}@${HostAddr}" -p $SshPort "nginx -t && systemctl reload nginx" |
|
|
|
Write-Host "==> Verify..." |
|
ssh -o BatchMode=yes -m $SshMac "${SshUser}@${HostAddr}" -p $SshPort @" |
|
curl -sk -o /dev/null -w 'console /up: %{http_code}\n' https://console.gisportal.id/up |
|
curl -sk -o /dev/null -w 'legacy redirect: %{http_code} -> %{redirect_url}\n' -L --max-redirs 0 https://databaselist.gisportal.id/ 2>/dev/null || curl -sk -I https://databaselist.gisportal.id/ | head -5 |
|
"@ |
|
|
|
Write-Host "" |
|
Write-Host "Cutover Fase 2+3 selesai." |
|
Write-Host " Production: https://console.gisportal.id" |
|
Write-Host " Legacy: https://databaselist.gisportal.id -> 301 console"
|
|
|