mirror of
https://github.com/GoodOlClint/PSProxmoxVE.git
synced 2026-07-26 07:58:14 +00:00
feat(infra): add self-hosted GitHub Actions runner setup
Bash setup script for Debian/Ubuntu, Dockerfile for containerized runners, and comprehensive documentation. Installs .NET SDK, PowerShell, Terraform, and configures the GitHub Actions runner as a systemd service with proxmox/integration labels. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
# =============================================================================
|
||||
# Dockerfile
|
||||
# Self-hosted GitHub Actions runner for PSProxmoxVE integration tests.
|
||||
#
|
||||
# Build:
|
||||
# docker build -t psproxmoxve-runner .
|
||||
#
|
||||
# Run:
|
||||
# docker run -d \
|
||||
# -e REPO_URL=https://github.com/GoodOlClint/PSProxmoxVE \
|
||||
# -e RUNNER_TOKEN=AXXXXXXXXXXXXXXXXXXXXXXXXXXXX \
|
||||
# -e RUNNER_LABELS=self-hosted,proxmox,integration \
|
||||
# -e RUNNER_NAME=docker-proxmox-runner \
|
||||
# --name psproxmoxve-runner \
|
||||
# psproxmoxve-runner
|
||||
#
|
||||
# The container must have network access to the Proxmox VE API under test.
|
||||
# =============================================================================
|
||||
FROM ubuntu:24.04
|
||||
|
||||
LABEL maintainer="GoodOlClint"
|
||||
LABEL description="Self-hosted GitHub Actions runner for PSProxmoxVE integration tests"
|
||||
|
||||
# Avoid interactive prompts during package installation.
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 1. System packages
|
||||
# ---------------------------------------------------------------------------
|
||||
RUN apt-get update -qq && \
|
||||
apt-get install -y -qq --no-install-recommends \
|
||||
curl \
|
||||
jq \
|
||||
git \
|
||||
wget \
|
||||
apt-transport-https \
|
||||
software-properties-common \
|
||||
lsb-release \
|
||||
ca-certificates \
|
||||
gnupg \
|
||||
unzip \
|
||||
sudo \
|
||||
iputils-ping \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 2. .NET SDK 10.0
|
||||
# ---------------------------------------------------------------------------
|
||||
RUN wget -q "https://packages.microsoft.com/config/ubuntu/24.04/packages-microsoft-prod.deb" \
|
||||
-O /tmp/packages-microsoft-prod.deb && \
|
||||
dpkg -i /tmp/packages-microsoft-prod.deb && \
|
||||
rm -f /tmp/packages-microsoft-prod.deb && \
|
||||
apt-get update -qq && \
|
||||
apt-get install -y -qq --no-install-recommends dotnet-sdk-10.0 && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 3. PowerShell 7.x
|
||||
# ---------------------------------------------------------------------------
|
||||
RUN apt-get update -qq && \
|
||||
apt-get install -y -qq --no-install-recommends powershell && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 4. Terraform
|
||||
# ---------------------------------------------------------------------------
|
||||
RUN wget -qO- https://apt.releases.hashicorp.com/gpg | \
|
||||
gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg && \
|
||||
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com noble main" \
|
||||
> /etc/apt/sources.list.d/hashicorp.list && \
|
||||
apt-get update -qq && \
|
||||
apt-get install -y -qq --no-install-recommends terraform && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 5. Create runner user
|
||||
# ---------------------------------------------------------------------------
|
||||
RUN useradd -m -s /bin/bash github-runner && \
|
||||
echo "github-runner ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/github-runner
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 6. Download GitHub Actions runner
|
||||
# ---------------------------------------------------------------------------
|
||||
ENV RUNNER_DIR=/opt/github-runner
|
||||
|
||||
RUN mkdir -p "$RUNNER_DIR" && \
|
||||
RUNNER_VERSION=$(curl -fsSL https://api.github.com/repos/actions/runner/releases/latest | jq -r '.tag_name' | sed 's/^v//') && \
|
||||
curl -fsSL "https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz" \
|
||||
-o /tmp/runner.tar.gz && \
|
||||
tar xzf /tmp/runner.tar.gz -C "$RUNNER_DIR" && \
|
||||
rm -f /tmp/runner.tar.gz && \
|
||||
chown -R github-runner:github-runner "$RUNNER_DIR"
|
||||
|
||||
# Install runner dependencies (the runner ships a script for this).
|
||||
RUN "$RUNNER_DIR/bin/installdependencies.sh"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 7. Entrypoint
|
||||
# ---------------------------------------------------------------------------
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
|
||||
USER github-runner
|
||||
WORKDIR /opt/github-runner
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
@@ -0,0 +1,205 @@
|
||||
# Self-Hosted GitHub Actions Runner for PSProxmoxVE
|
||||
|
||||
## Overview
|
||||
|
||||
The PSProxmoxVE integration tests require network access to a live Proxmox VE API. A self-hosted GitHub Actions runner, deployed on or near your Proxmox host, lets pushes to GitHub automatically trigger these tests without exposing your PVE management interface to the public internet.
|
||||
|
||||
This directory contains everything needed to set up such a runner.
|
||||
|
||||
## Option A: LXC Container (Recommended)
|
||||
|
||||
Running the runner inside an LXC container on the Proxmox host itself is the simplest approach. The container has direct network access to the PVE API with no extra networking required.
|
||||
|
||||
### 1. Create the LXC container
|
||||
|
||||
From the Proxmox host shell (or the web UI):
|
||||
|
||||
```bash
|
||||
# Download a Debian 12 template if you don't already have one
|
||||
pveam download local debian-12-standard_12.7-1_amd64.tar.zst
|
||||
|
||||
# Create a privileged container
|
||||
pct create 900 local:vztmpl/debian-12-standard_12.7-1_amd64.tar.zst \
|
||||
--hostname github-runner \
|
||||
--cores 2 \
|
||||
--memory 4096 \
|
||||
--swap 1024 \
|
||||
--rootfs local-lvm:20 \
|
||||
--net0 name=eth0,bridge=vmbr0,ip=dhcp \
|
||||
--unprivileged 0 \
|
||||
--features nesting=1 \
|
||||
--start 1
|
||||
```
|
||||
|
||||
Adjust the container ID (900), storage, and network bridge to match your environment.
|
||||
|
||||
**Recommended resources:**
|
||||
- 2 CPU cores
|
||||
- 4 GB RAM
|
||||
- 20 GB disk
|
||||
|
||||
### 2. Run the setup script
|
||||
|
||||
Enter the container and run the setup script:
|
||||
|
||||
```bash
|
||||
pct enter 900
|
||||
|
||||
apt-get update && apt-get install -y curl
|
||||
curl -fsSL https://raw.githubusercontent.com/GoodOlClint/PSProxmoxVE/main/tests/infrastructure/runner/setup-runner.sh \
|
||||
-o /tmp/setup-runner.sh
|
||||
chmod +x /tmp/setup-runner.sh
|
||||
|
||||
/tmp/setup-runner.sh \
|
||||
--repo GoodOlClint/PSProxmoxVE \
|
||||
--token <YOUR_REGISTRATION_TOKEN> \
|
||||
--labels self-hosted,proxmox,integration
|
||||
```
|
||||
|
||||
See [GitHub Configuration](#github-configuration) below for how to obtain the registration token.
|
||||
|
||||
### 3. Verify
|
||||
|
||||
The runner should appear as **Online** in your repository under **Settings > Actions > Runners** within a minute.
|
||||
|
||||
## Option B: Docker Container
|
||||
|
||||
If you prefer Docker, or want to run the runner on a different machine that has network access to your PVE host:
|
||||
|
||||
### 1. Build the image
|
||||
|
||||
```bash
|
||||
cd tests/infrastructure/runner
|
||||
docker build -t psproxmoxve-runner .
|
||||
```
|
||||
|
||||
### 2. Run the container
|
||||
|
||||
```bash
|
||||
docker run -d \
|
||||
-e REPO_URL=https://github.com/GoodOlClint/PSProxmoxVE \
|
||||
-e RUNNER_TOKEN=<YOUR_REGISTRATION_TOKEN> \
|
||||
-e RUNNER_LABELS=self-hosted,proxmox,integration \
|
||||
-e RUNNER_NAME=docker-proxmox-runner \
|
||||
--name psproxmoxve-runner \
|
||||
--restart unless-stopped \
|
||||
psproxmoxve-runner
|
||||
```
|
||||
|
||||
For ephemeral (single-job) mode, add `-e EPHEMERAL=true`. The container will exit after completing one job; combine with `--restart always` to re-register automatically for the next job.
|
||||
|
||||
### 3. Verify
|
||||
|
||||
```bash
|
||||
docker logs -f psproxmoxve-runner
|
||||
```
|
||||
|
||||
You should see the runner register and begin listening for jobs.
|
||||
|
||||
## GitHub Configuration
|
||||
|
||||
### Obtaining a Registration Token
|
||||
|
||||
1. Navigate to your repository on GitHub.
|
||||
2. Go to **Settings > Actions > Runners**.
|
||||
3. Click **New self-hosted runner**.
|
||||
4. Copy the registration token shown in the configuration instructions.
|
||||
|
||||
> **Note:** Registration tokens expire after one hour. Generate a new one if yours has expired.
|
||||
|
||||
### Required Labels
|
||||
|
||||
The integration test workflow targets runners with the label `integration`. The setup script applies the following labels by default:
|
||||
|
||||
- `self-hosted`
|
||||
- `proxmox`
|
||||
- `integration`
|
||||
|
||||
You can override these with the `--labels` flag or `RUNNER_LABELS` environment variable.
|
||||
|
||||
## Repository Secrets
|
||||
|
||||
The integration tests read connection details from GitHub Actions secrets. Configure these in **Settings > Secrets and variables > Actions**:
|
||||
|
||||
| Secret | Description | Example |
|
||||
|---|---|---|
|
||||
| `PVETEST_HOST` | IP or hostname of the Proxmox VE host (or a nested test PVE instance) | `192.168.1.100` |
|
||||
| `PVETEST_PORT` | PVE API port | `8006` |
|
||||
| `PVETEST_APITOKEN` | API token in `user@realm!tokenid=secret` format | `testuser@pve!ci=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` |
|
||||
| `PVETEST_NODE` | Proxmox node name to run tests against | `pve` |
|
||||
| `PVETEST_STORAGE` | Storage ID for upload/ISO tests | `local` |
|
||||
| `PVETEST_ISO_PATH` | Path on the runner to a small test ISO file | `/opt/test-assets/test.iso` |
|
||||
|
||||
### Creating a Dedicated API Token
|
||||
|
||||
It is strongly recommended to create a dedicated, least-privilege API token for testing:
|
||||
|
||||
```bash
|
||||
# On the Proxmox host
|
||||
pveum user add testuser@pve --password <password>
|
||||
pveum role add CITestRole --privs "VM.Allocate VM.Audit VM.Config.Disk VM.Config.CPU VM.Config.Memory VM.Config.Network VM.Config.Options VM.PowerMgmt Datastore.AllocateSpace Datastore.Audit SDN.Use"
|
||||
pveum aclmod / --user testuser@pve --role CITestRole
|
||||
pveum user token add testuser@pve ci --privsep 0
|
||||
```
|
||||
|
||||
The last command outputs the token secret -- store it as the `PVETEST_APITOKEN` secret.
|
||||
|
||||
## Security Considerations
|
||||
|
||||
- **Network isolation.** The runner has access to your local network. If possible, place it on a dedicated test VLAN that can only reach the PVE API and the internet (for downloading runner updates and GitHub communication).
|
||||
|
||||
- **Dedicated API token.** Use a purpose-built API token with only the permissions the tests need. Never use `root@pam`.
|
||||
|
||||
- **Registration token is single-use.** The GitHub registration token is consumed during setup and cannot be reused. A new token is needed only to re-register or remove the runner.
|
||||
|
||||
- **Ephemeral runners.** For stronger isolation, use `--ephemeral` (setup script) or `-e EPHEMERAL=true` (Docker). The runner handles one job and then deregisters. This prevents state leakage between workflow runs.
|
||||
|
||||
- **Repository scope.** Self-hosted runners registered at the repository level only receive jobs from that repository. Do not register at the organization level unless you understand the implications.
|
||||
|
||||
- **Keep the host updated.** Regularly apply OS security patches to the runner container or VM.
|
||||
|
||||
## Maintenance
|
||||
|
||||
### Runner Auto-Updates
|
||||
|
||||
The GitHub Actions runner automatically updates itself when GitHub releases a new version. No manual intervention is required.
|
||||
|
||||
### Checking Runner Status
|
||||
|
||||
```bash
|
||||
# LXC / bare metal (systemd service)
|
||||
systemctl status actions.runner.*
|
||||
|
||||
# Docker
|
||||
docker logs psproxmoxve-runner
|
||||
```
|
||||
|
||||
### Removing the Runner
|
||||
|
||||
**LXC / bare metal:**
|
||||
|
||||
```bash
|
||||
cd /opt/github-runner
|
||||
sudo ./svc.sh stop
|
||||
sudo ./svc.sh uninstall
|
||||
./config.sh remove --token <NEW_REMOVAL_TOKEN>
|
||||
```
|
||||
|
||||
Generate a removal token from **Settings > Actions > Runners** by clicking the runner name.
|
||||
|
||||
**Docker:**
|
||||
|
||||
```bash
|
||||
docker stop psproxmoxve-runner
|
||||
docker rm psproxmoxve-runner
|
||||
```
|
||||
|
||||
If the container was not stopped gracefully (which triggers automatic deregistration), remove the runner manually from **Settings > Actions > Runners** in the GitHub UI.
|
||||
|
||||
### Reinstalling / Re-registering
|
||||
|
||||
If you need to re-register the runner (e.g., after moving it to a new host):
|
||||
|
||||
1. Remove the old registration (see above).
|
||||
2. Generate a new registration token from GitHub.
|
||||
3. Run the setup script or Docker container again with the new token.
|
||||
Executable
+79
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env bash
|
||||
# =============================================================================
|
||||
# entrypoint.sh
|
||||
# Docker entrypoint for the self-hosted GitHub Actions runner.
|
||||
#
|
||||
# Required environment variables:
|
||||
# REPO_URL - Full GitHub repository URL (e.g. https://github.com/GoodOlClint/PSProxmoxVE)
|
||||
# RUNNER_TOKEN - Registration token from GitHub Settings > Actions > Runners
|
||||
#
|
||||
# Optional environment variables:
|
||||
# RUNNER_LABELS - Comma-separated labels (default: self-hosted,proxmox,integration)
|
||||
# RUNNER_NAME - Runner name (default: hostname)
|
||||
# RUNNER_GROUP - Runner group (default: Default)
|
||||
# EPHEMERAL - Set to "true" for single-job ephemeral mode (default: false)
|
||||
# =============================================================================
|
||||
set -euo pipefail
|
||||
|
||||
RUNNER_LABELS="${RUNNER_LABELS:-self-hosted,proxmox,integration}"
|
||||
RUNNER_NAME="${RUNNER_NAME:-$(hostname)}"
|
||||
RUNNER_GROUP="${RUNNER_GROUP:-Default}"
|
||||
EPHEMERAL="${EPHEMERAL:-false}"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Validate required environment variables
|
||||
# ---------------------------------------------------------------------------
|
||||
if [[ -z "${REPO_URL:-}" ]]; then
|
||||
echo "ERROR: REPO_URL environment variable is required."
|
||||
echo " Example: -e REPO_URL=https://github.com/GoodOlClint/PSProxmoxVE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z "${RUNNER_TOKEN:-}" ]]; then
|
||||
echo "ERROR: RUNNER_TOKEN environment variable is required."
|
||||
echo " Get one from: ${REPO_URL}/settings/actions/runners/new"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Configure the runner
|
||||
# ---------------------------------------------------------------------------
|
||||
CONFIG_ARGS=(
|
||||
--url "$REPO_URL"
|
||||
--token "$RUNNER_TOKEN"
|
||||
--labels "$RUNNER_LABELS"
|
||||
--name "$RUNNER_NAME"
|
||||
--runnergroup "$RUNNER_GROUP"
|
||||
--work _work
|
||||
--unattended
|
||||
--replace
|
||||
)
|
||||
|
||||
if [[ "$EPHEMERAL" == "true" ]]; then
|
||||
CONFIG_ARGS+=(--ephemeral)
|
||||
echo "Ephemeral mode enabled -- runner will exit after one job."
|
||||
fi
|
||||
|
||||
echo "Configuring runner..."
|
||||
echo " Repository: $REPO_URL"
|
||||
echo " Name: $RUNNER_NAME"
|
||||
echo " Labels: $RUNNER_LABELS"
|
||||
|
||||
/opt/github-runner/config.sh "${CONFIG_ARGS[@]}"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Deregister on shutdown (best-effort)
|
||||
# ---------------------------------------------------------------------------
|
||||
cleanup() {
|
||||
echo ""
|
||||
echo "Caught signal -- removing runner registration..."
|
||||
/opt/github-runner/config.sh remove --token "$RUNNER_TOKEN" || true
|
||||
}
|
||||
trap cleanup SIGTERM SIGINT
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Start the runner
|
||||
# ---------------------------------------------------------------------------
|
||||
echo "Starting runner..."
|
||||
/opt/github-runner/run.sh &
|
||||
wait $!
|
||||
Executable
+206
@@ -0,0 +1,206 @@
|
||||
#!/usr/bin/env bash
|
||||
# =============================================================================
|
||||
# setup-runner.sh
|
||||
# Sets up a self-hosted GitHub Actions runner for PSProxmoxVE integration tests.
|
||||
#
|
||||
# Intended to run inside a Debian 12 or Ubuntu 24.04 environment (LXC, VM, or
|
||||
# bare metal) that has network access to the Proxmox VE API under test.
|
||||
#
|
||||
# Prerequisites: root or sudo access, internet connectivity.
|
||||
#
|
||||
# Usage:
|
||||
# sudo ./setup-runner.sh \
|
||||
# --repo GoodOlClint/PSProxmoxVE \
|
||||
# --token AXXXXXXXXXXXXXXXXXXXXXXXXXXXX \
|
||||
# --labels self-hosted,proxmox,integration
|
||||
#
|
||||
# Read through the script before running it -- no surprises.
|
||||
# =============================================================================
|
||||
set -euo pipefail
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Parse arguments
|
||||
# ---------------------------------------------------------------------------
|
||||
REPO=""
|
||||
TOKEN=""
|
||||
LABELS="self-hosted,proxmox,integration"
|
||||
RUNNER_DIR="/opt/github-runner"
|
||||
RUNNER_USER="github-runner"
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--repo) REPO="$2"; shift 2 ;;
|
||||
--token) TOKEN="$2"; shift 2 ;;
|
||||
--labels) LABELS="$2"; shift 2 ;;
|
||||
--help|-h)
|
||||
echo "Usage: $0 --repo OWNER/REPO --token TOKEN [--labels LABELS]"
|
||||
echo ""
|
||||
echo " --repo GitHub repository (e.g. GoodOlClint/PSProxmoxVE)"
|
||||
echo " --token Runner registration token from GitHub Settings > Actions > Runners"
|
||||
echo " --labels Comma-separated labels (default: self-hosted,proxmox,integration)"
|
||||
exit 0
|
||||
;;
|
||||
*) echo "Unknown option: $1"; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Validate required arguments
|
||||
# ---------------------------------------------------------------------------
|
||||
[[ -z "$REPO" ]] && { echo "ERROR: --repo required (e.g. GoodOlClint/PSProxmoxVE)"; exit 1; }
|
||||
[[ -z "$TOKEN" ]] && { echo "ERROR: --token required (get from GitHub Settings > Actions > Runners)"; exit 1; }
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Detect OS
|
||||
# ---------------------------------------------------------------------------
|
||||
if [[ -f /etc/os-release ]]; then
|
||||
# shellcheck disable=SC1091
|
||||
source /etc/os-release
|
||||
echo "Detected OS: $PRETTY_NAME"
|
||||
else
|
||||
echo "WARNING: Cannot detect OS. Proceeding assuming Debian/Ubuntu."
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Helper: retry a command up to N times
|
||||
# ---------------------------------------------------------------------------
|
||||
retry() {
|
||||
local retries=$1; shift
|
||||
local count=0
|
||||
until "$@"; do
|
||||
count=$((count + 1))
|
||||
if [[ $count -ge $retries ]]; then
|
||||
echo "ERROR: Command failed after $retries attempts: $*"
|
||||
return 1
|
||||
fi
|
||||
echo "Retry $count/$retries..."
|
||||
sleep 3
|
||||
done
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 1. System packages
|
||||
# ---------------------------------------------------------------------------
|
||||
echo ""
|
||||
echo "=== Installing system prerequisites ==="
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
apt-get update -qq
|
||||
apt-get install -y -qq curl jq git wget apt-transport-https software-properties-common \
|
||||
lsb-release ca-certificates gnupg unzip
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 2. .NET SDK 10.0
|
||||
# ---------------------------------------------------------------------------
|
||||
echo ""
|
||||
echo "=== Installing .NET SDK 10.0 ==="
|
||||
# Microsoft package repository
|
||||
wget -q "https://packages.microsoft.com/config/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/$(lsb_release -rs)/packages-microsoft-prod.deb" \
|
||||
-O /tmp/packages-microsoft-prod.deb
|
||||
dpkg -i /tmp/packages-microsoft-prod.deb
|
||||
rm -f /tmp/packages-microsoft-prod.deb
|
||||
apt-get update -qq
|
||||
apt-get install -y -qq dotnet-sdk-10.0
|
||||
|
||||
echo " .NET version: $(dotnet --version)"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 3. PowerShell 7.x
|
||||
# ---------------------------------------------------------------------------
|
||||
echo ""
|
||||
echo "=== Installing PowerShell 7.x ==="
|
||||
# PowerShell is available from the Microsoft repository added above.
|
||||
apt-get install -y -qq powershell
|
||||
|
||||
echo " PowerShell version: $(pwsh -NoProfile -Command '$PSVersionTable.PSVersion.ToString()')"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 4. Terraform
|
||||
# ---------------------------------------------------------------------------
|
||||
echo ""
|
||||
echo "=== Installing Terraform ==="
|
||||
wget -qO- https://apt.releases.hashicorp.com/gpg | gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
|
||||
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" \
|
||||
> /etc/apt/sources.list.d/hashicorp.list
|
||||
apt-get update -qq
|
||||
apt-get install -y -qq terraform
|
||||
|
||||
echo " Terraform version: $(terraform version -json | jq -r '.terraform_version')"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 5. Create runner service account
|
||||
# ---------------------------------------------------------------------------
|
||||
echo ""
|
||||
echo "=== Creating runner service account ==="
|
||||
if ! id "$RUNNER_USER" &>/dev/null; then
|
||||
useradd -m -s /bin/bash "$RUNNER_USER"
|
||||
echo " Created user: $RUNNER_USER"
|
||||
else
|
||||
echo " User $RUNNER_USER already exists"
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 6. Download and configure GitHub Actions runner
|
||||
# ---------------------------------------------------------------------------
|
||||
echo ""
|
||||
echo "=== Downloading GitHub Actions runner ==="
|
||||
mkdir -p "$RUNNER_DIR"
|
||||
|
||||
# Determine the latest runner version from the GitHub API.
|
||||
RUNNER_VERSION=$(curl -fsSL https://api.github.com/repos/actions/runner/releases/latest | jq -r '.tag_name' | sed 's/^v//')
|
||||
RUNNER_ARCH="x64"
|
||||
RUNNER_TAR="actions-runner-linux-${RUNNER_ARCH}-${RUNNER_VERSION}.tar.gz"
|
||||
RUNNER_URL="https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/${RUNNER_TAR}"
|
||||
|
||||
echo " Runner version: $RUNNER_VERSION"
|
||||
echo " Download URL: $RUNNER_URL"
|
||||
|
||||
if [[ ! -f "$RUNNER_DIR/.runner" ]]; then
|
||||
curl -fsSL "$RUNNER_URL" -o "/tmp/$RUNNER_TAR"
|
||||
tar xzf "/tmp/$RUNNER_TAR" -C "$RUNNER_DIR"
|
||||
rm -f "/tmp/$RUNNER_TAR"
|
||||
else
|
||||
echo " Runner already extracted -- skipping download"
|
||||
fi
|
||||
|
||||
chown -R "$RUNNER_USER":"$RUNNER_USER" "$RUNNER_DIR"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 7. Configure the runner
|
||||
# ---------------------------------------------------------------------------
|
||||
echo ""
|
||||
echo "=== Configuring runner ==="
|
||||
cd "$RUNNER_DIR"
|
||||
|
||||
# Run config as the service account.
|
||||
sudo -u "$RUNNER_USER" ./config.sh \
|
||||
--url "https://github.com/$REPO" \
|
||||
--token "$TOKEN" \
|
||||
--labels "$LABELS" \
|
||||
--name "$(hostname)-proxmox-runner" \
|
||||
--work _work \
|
||||
--unattended \
|
||||
--replace
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 8. Install and start the systemd service
|
||||
# ---------------------------------------------------------------------------
|
||||
echo ""
|
||||
echo "=== Installing as systemd service ==="
|
||||
./svc.sh install "$RUNNER_USER"
|
||||
./svc.sh start
|
||||
|
||||
echo ""
|
||||
echo "=== Runner setup complete ==="
|
||||
echo " Runner directory: $RUNNER_DIR"
|
||||
echo " Service user: $RUNNER_USER"
|
||||
echo " Labels: $LABELS"
|
||||
echo " Repository: https://github.com/$REPO"
|
||||
echo ""
|
||||
echo "Verify the runner appears in your repository under:"
|
||||
echo " Settings > Actions > Runners"
|
||||
echo ""
|
||||
echo "To remove this runner later:"
|
||||
echo " cd $RUNNER_DIR"
|
||||
echo " ./svc.sh stop"
|
||||
echo " ./svc.sh uninstall"
|
||||
echo " ./config.sh remove --token <NEW_TOKEN>"
|
||||
Reference in New Issue
Block a user