peppa/scripts/server-move/mac-route.sh
peppa-bot e83302c398
Some checks failed
peppa/lint lint: success за 1с
peppa/typecheck typecheck: success за 21с
peppa/build build: success за 15с
peppa/test test: failure за 693с
peppa-ci / ci (pull_request) Failing after 12m51s
PEP-231: продукты переезжают вместе с данными и без отчёта о выкладке
products-move.sh (Mac) и product-up.sh (сервер): та же версия, тома со сверкой сумм,
Postgres дампом, предпроверки и откат, превью, раннер проверок. Маршрут Mac: на сервер
идут только адреса продуктов — общее правило спорило со страницами Gitea.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-22 09:49:11 +05:00

72 lines
4.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# PEP-230: адреса *.telecom.quest приходят на Mac (туннель Cloudflare → Traefik). Этот скрипт ставит
# SSH-туннель Mac → сервер (launchd quest.telecom.peppa.tunnel) и маршрут в Traefik:
# mac-route.sh trial — только пробное имя peppa-srv.telecom.quest (живой сайт не трогает)
# mac-route.sh final — peppa.telecom.quest и адреса продуктов, которых на Mac больше нет, → сервер
# mac-route.sh routes — только переписать маршруты final (туннель не перезапускается)
# mac-route.sh off — убрать маршрут (откат: peppa.telecom.quest снова отвечает с Mac)
set -euo pipefail
MODE=${1:?trial|final|routes|off}
SRV=${PEPPA_SERVER:-vibe42@82.200.135.122}
KEY=${PEPPA_SSH_KEY:-$HOME/.peppa/ssh/id_ed25519}
DYN=${PEPPA_TRAEFIK_DYNAMIC:-/Users/timur/Dev/_Zorro/_INFRA/traefik/dynamic}
PL=$HOME/Library/LaunchAgents/quest.telecom.peppa.tunnel.plist
if [ "$MODE" = off ]; then
rm -f "$DYN/peppa-server.yml"; [ -f "$DYN/peppa.yml.before-server" ] && mv "$DYN/peppa.yml.before-server" "$DYN/peppa.yml"
echo "маршрут на сервер убран"; exit 0
fi
if [ "$MODE" != routes ]; then
cat > "$PL" <<P
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict>
<key>Label</key><string>quest.telecom.peppa.tunnel</string>
<key>ProgramArguments</key><array>
<string>/usr/bin/ssh</string><string>-i</string><string>$KEY</string>
<string>-o</string><string>BatchMode=yes</string><string>-o</string><string>ExitOnForwardFailure=yes</string>
<string>-o</string><string>ServerAliveInterval=15</string><string>-o</string><string>ServerAliveCountMax=3</string>
<string>-N</string><string>-L</string><string>127.0.0.1:18880:127.0.0.1:8880</string><string>$SRV</string>
</array>
<key>RunAtLoad</key><true/><key>KeepAlive</key><true/><key>ThrottleInterval</key><integer>5</integer>
<key>StandardErrorPath</key><string>$HOME/.peppa/tunnel.log</string><key>StandardOutPath</key><string>$HOME/.peppa/tunnel.log</string>
</dict></plist>
P
pkill -f "18880:127.0.0.1:8880" 2>/dev/null || true
launchctl bootout "gui/$(id -u)/quest.telecom.peppa.tunnel" 2>/dev/null || true
launchctl bootstrap "gui/$(id -u)" "$PL"
for i in 1 2 3 4 5 6 7 8 9 10; do curl -s -m 3 -o /dev/null http://127.0.0.1:18880/ && break; sleep 1; done
fi
if [ "$MODE" = trial ]; then RULE='Host(`peppa-srv.telecom.quest`)'; EXTRA=""; else
RULE='Host(`peppa.telecom.quest`) || Host(`peppa-srv.telecom.quest`)'
# PEP-231: адрес продукта (<slug>-staging|prod|pr<N>), у которого на Mac нет работающего контейнера,
# идёт на сервер. Приоритет 2: выше общего правила страниц Gitea на Mac (`pages`, приоритет 1 — оно
# ловит любой неизвестный *.telecom.quest), ниже маршрута самого контейнера (приоритет = длина правила).
# Правило «всё неизвестное → сервер» нельзя: оно спорило бы со страницами Gitea.
EXTRA='
peppa-server-products:
rule: "HostRegexp(`^[a-z0-9-]+-(staging|prod|pr[0-9]+)\\.telecom\\.quest$`)"
service: peppa-server
entryPoints: [web]
priority: 2'
[ -f "$DYN/peppa.yml" ] && mv "$DYN/peppa.yml" "$DYN/peppa.yml.before-server" || true
fi
cat > "$DYN/peppa-server.yml" <<Y
# Peppa FACTORY работает на сервере (PEP-230). Запросы уходят туда по SSH-туннелю
# (launchd quest.telecom.peppa.tunnel: Mac 127.0.0.1:18880 → сервер 127.0.0.1:8880, Traefik Peppa).
# Откат: scripts/server-move/mac-route.sh off
http:
routers:
peppa-server:
rule: "$RULE"
service: peppa-server
entryPoints: [web]
priority: 100000$EXTRA
services:
peppa-server:
loadBalancer:
servers:
- url: "http://host.docker.internal:18880"
Y
sleep 4
curl -s -m 15 -o /dev/null -w "peppa-srv.telecom.quest → %{http_code}\n" https://peppa-srv.telecom.quest/api/health