Files
errors.bitreport.pt/deploy/lxc/webhook-deploy.sh
T
David Santos 37ab9f1ccb
CI / Test api (push) Successful in 1m8s
CI / Test ingest-api (push) Successful in 1m9s
CI / Lint and typecheck admin-ui (push) Successful in 1m30s
CI / Validate Docker build (push) Successful in 5m22s
fix(hub): BIT-25223 add fix-duplicate-logo.js resolve pattern + auto-apply on deploy
- resolveFixedPatterns.ts: add '%fix-duplicate-logo.js%' entry so any
  Chrome-style CRM JS error that reaches the hub is auto-resolved on deploy
- webhook-deploy.sh: call resolve-fixed-patterns after every service restart
  so code fixes clear stale hub incidents automatically (uses ERROR_RESOLVE_API_KEY
  from /etc/error-reporting/env which is already sourced by the script)

The 5 open incidents for ERRCLUSTER:33b4e527d8fd were bulk-resolved directly
(IDs 747145, 747381, 753209, 753550, 753551). Client-side noise filter (CRM PR #684)
prevents new occurrences.
2026-07-17 22:20:18 +00:00

72 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Example promote script for Gitea webhook → LXC (BIT-465). Adjust branches, users, and
# restart policy for your host. Run as the user that owns the repo (often root on first setup).
set -euo pipefail
_ENV_FILE="/etc/error-reporting/env"
if [[ ! -f "${_ENV_FILE}" ]]; then
echo "webhook-deploy: missing ${_ENV_FILE}" >&2
exit 1
fi
set -a
# shellcheck disable=SC1090
source "${_ENV_FILE}"
set +a
_ROOT="${ER_REPO_ROOT:?ER_REPO_ROOT must be set in ${_ENV_FILE}}"
cd "${_ROOT}"
# Avoid `fatal: detected dubious ownership` when root runs git on a tree owned by error-reporting.
git config --global --add safe.directory "${_ROOT}" 2>/dev/null || true
# Match your deploy branch (repository uses master today).
_DEPLOY_BRANCH="${ER_DEPLOY_BRANCH:-master}"
git fetch origin "${_DEPLOY_BRANCH}"
git checkout "${_DEPLOY_BRANCH}"
git merge --ff-only "origin/${_DEPLOY_BRANCH}"
echo "webhook-deploy: npm ci + build (ingest-api, admin-ui, collector-worker, api)"
(cd "${_ROOT}/ingest-api" && npm ci && npm run build)
(cd "${_ROOT}/admin-ui" && npm ci && npm run build)
(cd "${_ROOT}/collector-worker" && npm ci && npm run build)
(cd "${_ROOT}/api" && npm ci && npm run build)
if getent passwd error-reporting >/dev/null 2>&1; then
chown -R error-reporting:error-reporting "${_ROOT}"
fi
"${_ROOT}/deploy/lxc/write-version-json.sh"
"${_ROOT}/deploy/lxc/verify.sh"
if [[ "${ER_WEBHOOK_RESTART_SERVICES:-1}" == "1" ]]; then
systemctl restart bitreport-error-reporting-ingest-api.service
systemctl restart bitreport-error-reporting-admin-ui.service
systemctl restart bitreport-error-reporting-collector-worker.service
systemctl restart bitreport-error-reporting-api.service
# Auto-apply resolve-fixed-patterns after every deploy so code fixes clear stale incidents.
if [[ -n "${ERROR_RESOLVE_API_KEY:-}" ]]; then
_api_port="${ER_API_PORT:-3200}"
_ready=0
for _i in $(seq 1 20); do
if curl -sf "http://localhost:${_api_port}/health" >/dev/null 2>&1; then
_ready=1; break
fi
sleep 3
done
if [[ "${_ready}" == "1" ]]; then
curl -sf -X POST "http://localhost:${_api_port}/api/error-monitoring/resolve-fixed-patterns" \
-H "Content-Type: application/json" \
-d "{\"api_key\":\"${ERROR_RESOLVE_API_KEY}\"}" \
>/dev/null 2>&1 \
&& echo "webhook-deploy: resolve-fixed-patterns applied" \
|| echo "webhook-deploy: WARN resolve-fixed-patterns failed (non-fatal)"
else
echo "webhook-deploy: WARN API not ready after 60s, skipping resolve-fixed-patterns"
fi
fi
fi
echo "webhook-deploy: done"