97 lines
4.0 KiB
Bash
Executable File
97 lines
4.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT="/data/aios-gitops"
|
|
WORKSPACE="$ROOT/workspace"
|
|
NGINX_SITE="/etc/nginx/sites-enabled/aios-user-portal.conf"
|
|
BACKUP_DIR="$ROOT/backups/nginx-gitops-$(date +%Y%m%d-%H%M%S)"
|
|
LOG="$ROOT/logs/nginx-gitops-routes.log"
|
|
mkdir -p "$BACKUP_DIR" "$ROOT/logs" "$WORKSPACE/deploy/nginx"
|
|
exec > >(tee -a "$LOG") 2>&1
|
|
|
|
cd "$WORKSPACE"
|
|
|
|
cat > deploy/nginx/aios-gitops-locations.conf <<'EOF'
|
|
# BEGIN AIOS V1R1C0 GitOps short links
|
|
location = /git { return 302 /git/; }
|
|
location /git/ {
|
|
proxy_pass http://127.0.0.1:3000/;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
proxy_set_header X-Forwarded-Host $host;
|
|
proxy_set_header X-Forwarded-Prefix /git;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection $connection_upgrade;
|
|
proxy_redirect off;
|
|
}
|
|
|
|
location = /api { return 302 /api/; }
|
|
location /api/ {
|
|
proxy_pass http://127.0.0.1:18890/api/;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
location = /base { proxy_pass http://127.0.0.1:18890/base; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; }
|
|
location = /ver { proxy_pass http://127.0.0.1:18890/ver; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; }
|
|
location = /diff { proxy_pass http://127.0.0.1:18890/diff; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; }
|
|
location = /patch { proxy_pass http://127.0.0.1:18890/patch; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; }
|
|
location = /model { proxy_pass http://127.0.0.1:18890/model; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; }
|
|
location = /run { proxy_pass http://127.0.0.1:18890/run; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; }
|
|
location = /hook { proxy_pass http://127.0.0.1:18890/hook; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; }
|
|
location /hook/ {
|
|
proxy_pass http://127.0.0.1:18890/hook/;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
# END AIOS V1R1C0 GitOps short links
|
|
EOF
|
|
|
|
git add deploy/nginx/aios-gitops-locations.conf active-runtime/app/aios_gitops_model_api.py
|
|
git commit -m "feat(gitops): add nginx short links and webhook endpoint" || true
|
|
|
|
echo "== backup nginx site =="
|
|
sudo cp -a "$NGINX_SITE" "$BACKUP_DIR/aios-user-portal.conf"
|
|
|
|
echo "== insert locations =="
|
|
python3 - <<'PY'
|
|
from pathlib import Path
|
|
|
|
site = Path("/etc/nginx/sites-enabled/aios-user-portal.conf")
|
|
snippet = Path("/data/aios-gitops/workspace/deploy/nginx/aios-gitops-locations.conf").read_text()
|
|
text = site.read_text()
|
|
start = " # BEGIN AIOS V1R1C0 GitOps short links"
|
|
end = " # END AIOS V1R1C0 GitOps short links"
|
|
if start in text:
|
|
before = text.split(start)[0]
|
|
after = text.split(end, 1)[1]
|
|
text = before + snippet + after
|
|
else:
|
|
marker = " location / {\n"
|
|
if marker not in text:
|
|
raise SystemExit("location marker not found")
|
|
text = text.replace(marker, snippet + "\n" + marker, 1)
|
|
Path("/tmp/aios-user-portal.conf.gitops").write_text(text)
|
|
PY
|
|
sudo cp /tmp/aios-user-portal.conf.gitops "$NGINX_SITE"
|
|
|
|
echo "== nginx test and reload =="
|
|
sudo nginx -t
|
|
sudo systemctl reload nginx
|
|
|
|
echo "== local route checks =="
|
|
for path in /git/ /base /ver /model /run /hook /api/status; do
|
|
echo "== ${path} =="
|
|
curl -k -sS -I --resolve cnnetmkt.top:443:127.0.0.1 "https://cnnetmkt.top${path}" | sed -n '1,12p' || true
|
|
done
|
|
echo "NGINX_GITOPS_ROUTES_OK backup=$BACKUP_DIR"
|