CI — Test & Build / 🧪 Run Tests & Generate Reports (push) Waiting to run
CI — Test & Build / 🏗️ Build Docker Image (push) Blocked by required conditions
CI — Test & Build / 🐳 Docker integration & API E2E (push) Blocked by required conditions
CI — Test & Build / 🌐 Staging Playwright smoke (push) Waiting to run
99 lines
3.2 KiB
Bash
99 lines
3.2 KiB
Bash
#!/usr/bin/env bash
|
|
# Install and register a repository-scoped Gitea Actions runner on a dedicated Linux CI host.
|
|
# This script must be run on the CI host, not on the Gitea application server.
|
|
|
|
set -Eeuo pipefail
|
|
|
|
readonly RUNNER_VERSION="${RUNNER_VERSION:-0.2.11}"
|
|
readonly RUNNER_USER="${RUNNER_USER:-gitea-runner}"
|
|
readonly RUNNER_HOME="${RUNNER_HOME:-/opt/gitea-runner}"
|
|
readonly INSTANCE_URL="${INSTANCE_URL:-https://git.mozdit.hu}"
|
|
readonly RUNNER_NAME="${RUNNER_NAME:-mozdit-ci-01}"
|
|
readonly RUNNER_LABELS="${RUNNER_LABELS:-ubuntu-latest:host}"
|
|
|
|
fail() {
|
|
printf 'HIBA: %s\n' "$*" >&2
|
|
exit 1
|
|
}
|
|
|
|
require_command() {
|
|
command -v "$1" >/dev/null 2>&1 || fail "Hiányzó parancs: $1"
|
|
}
|
|
|
|
if [[ "${EUID}" -ne 0 ]]; then
|
|
fail "Futtasd sudo-val: sudo ./scripts/install-gitea-runner.sh"
|
|
fi
|
|
|
|
require_command curl
|
|
require_command docker
|
|
require_command node
|
|
require_command npm
|
|
|
|
docker info >/dev/null 2>&1 || fail "A Docker daemon nem érhető el. Indítsd el, majd futtasd újra a scriptet."
|
|
docker compose version >/dev/null 2>&1 || fail "Hiányzik a Docker Compose v2 (docker compose)."
|
|
|
|
case "$(uname -m)" in
|
|
x86_64) runner_arch="amd64" ;;
|
|
aarch64|arm64) runner_arch="arm64" ;;
|
|
*) fail "Nem támogatott CPU-architektúra: $(uname -m)" ;;
|
|
esac
|
|
|
|
readonly RUNNER_ARCH="${runner_arch}"
|
|
readonly RUNNER_URL="https://dl.gitea.com/gitea-runner/${RUNNER_VERSION}/act_runner-${RUNNER_VERSION}-linux-${RUNNER_ARCH}"
|
|
|
|
if ! id -u "${RUNNER_USER}" >/dev/null 2>&1; then
|
|
useradd --system --create-home --home-dir "${RUNNER_HOME}" --shell /usr/sbin/nologin "${RUNNER_USER}"
|
|
fi
|
|
|
|
usermod -aG docker "${RUNNER_USER}"
|
|
install -d -o "${RUNNER_USER}" -g "${RUNNER_USER}" -m 0750 "${RUNNER_HOME}"
|
|
|
|
tmp_binary="$(mktemp)"
|
|
trap 'rm -f "${tmp_binary}"' EXIT
|
|
curl --fail --location --retry 3 --output "${tmp_binary}" "${RUNNER_URL}"
|
|
install -o root -g root -m 0755 "${tmp_binary}" "${RUNNER_HOME}/act_runner"
|
|
|
|
"${RUNNER_HOME}/act_runner" --version
|
|
|
|
if [[ ! -f "${RUNNER_HOME}/.runner" ]]; then
|
|
if [[ -z "${GITEA_RUNNER_REGISTRATION_TOKEN:-}" ]]; then
|
|
read -r -s -p "Gitea runner regisztrációs token: " GITEA_RUNNER_REGISTRATION_TOKEN
|
|
printf '\n'
|
|
fi
|
|
[[ -n "${GITEA_RUNNER_REGISTRATION_TOKEN}" ]] || fail "Üres regisztrációs token."
|
|
|
|
# The token is intentionally neither written to disk nor printed by this script.
|
|
runuser -u "${RUNNER_USER}" -- "${RUNNER_HOME}/act_runner" register --no-interactive \
|
|
--instance "${INSTANCE_URL}" \
|
|
--token "${GITEA_RUNNER_REGISTRATION_TOKEN}" \
|
|
--name "${RUNNER_NAME}" \
|
|
--labels "${RUNNER_LABELS}"
|
|
else
|
|
printf 'A runner már regisztrálva van, a regisztráció kihagyva.\n'
|
|
fi
|
|
|
|
install -m 0644 /dev/stdin /etc/systemd/system/gitea-act-runner.service <<EOF
|
|
[Unit]
|
|
Description=Gitea Actions Runner (${RUNNER_NAME})
|
|
After=network-online.target docker.service
|
|
Wants=network-online.target
|
|
|
|
[Service]
|
|
User=${RUNNER_USER}
|
|
WorkingDirectory=${RUNNER_HOME}
|
|
ExecStart=${RUNNER_HOME}/act_runner daemon
|
|
Restart=always
|
|
RestartSec=5
|
|
NoNewPrivileges=true
|
|
PrivateTmp=true
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
systemctl daemon-reload
|
|
systemctl enable --now gitea-act-runner.service
|
|
systemctl --no-pager --full status gitea-act-runner.service
|
|
|
|
printf '\nKész. Ellenőrizd a Gitea felületén: Settings → Actions → Runners; az állapotnak Idle-nak kell lennie.\n'
|