Files
errors.bitreport.pt/deploy/lxc/webhook-deploy.sh
David Santos ab992382bc fix(deploy): restart Fastify API on webhook promote + git safe.directory
BIT-1599 follow-up: recent-errors changes live in api/; restart
bitreport-error-reporting-api.service alongside other units.

Register ER_REPO_ROOT as a safe directory when root runs git against a
tree owned by error-reporting (avoids dubious ownership failure on
write-version-json / verify).

Paperclip: BIT-1599
Made-with: Cursor
2026-04-08 00:56:12 +00:00

50 lines
1.7 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
fi
echo "webhook-deploy: done"