🗃️ Committing everything that changed 🗃️
Some checks failed
release-tag / release-image (push) Failing after 11m59s

rootfs/root/docker/setup/06-post.sh
rootfs/usr/local/bin/start-runners
rootfs/usr/local/etc/docker/init.d/05-dockerd.sh
rootfs/usr/local/etc/docker/init.d/zz-act_runner.sh
This commit is contained in:
casjay
2025-09-17 18:55:06 -04:00
parent 1c46cb0eb9
commit ac86c62c64
4 changed files with 280 additions and 288 deletions

View File

@@ -27,7 +27,7 @@ exitCode=0
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Main script
mkdir -p /var/lib/docker
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set the exit code
exitCode=$?

View File

@@ -1,23 +1,21 @@
#!/bin/bash
#!/usr/bin/env bash
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
set -e
# Function to log messages with timestamp
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Function to __log messages with timestamp
__log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Function to cleanup child processes on exit
cleanup() {
log "Shutting down runners..."
__cleanup() {
__log "Shutting down runners..."
kill $(jobs -p) 2>/dev/null || true
wait
log "All runners stopped"
__log "All runners stopped"
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set up signal handling
trap cleanup SIGTERM SIGINT
trap __cleanup SIGTERM SIGINT
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Validate required environment variables
if [ -n "$SERVER_ADDRESS" ]; then
if ! echo "$SERVER_ADDRESS" | grep -q '://'; then
@@ -26,65 +24,58 @@ if [ -n "$SERVER_ADDRESS" ]; then
else
SERVER_ADDRESS=http://$HOSTNAME
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -z "$SERVER_TOKEN" ]; then
log "ERROR: SERVER_TOKEN environment variable is required"
__log "ERROR: SERVER_TOKEN environment variable is required"
exit 1
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
RUNNER_LABELS="${RUNNER_LABELS:-ubuntu-latest:docker://node:16-bullseye,ubuntu-22.04:docker://node:16-bullseye}"
# Determine number of runners to start
RUNNERS_COUNT=${RUNNERS_ENABLE:-1}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Validate RUNNERS_COUNT is a positive integer
if ! [[ "$RUNNERS_COUNT" =~ ^[0-9]+$ ]] || [ "$RUNNERS_COUNT" -lt 1 ]; then
log "WARNING: Invalid RUNNERS_ENABLE value '$RUNNERS_ENABLE', defaulting to 1"
__log "WARNING: Invalid RUNNERS_ENABLE value '$RUNNERS_ENABLE', defaulting to 1"
RUNNERS_COUNT=1
fi
log "Starting $RUNNERS_COUNT act_runner instance(s)"
log "Server Address: $SERVER_ADDRESS"
log "Runner Name Prefix: ${RUNNER_NAME_PREFIX:-runner}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__log "Starting $RUNNERS_COUNT act_runner instance(s)"
__log "Server Address: $SERVER_ADDRESS"
__log "Runner Name Prefix: ${RUNNER_NAME_PREFIX:-runner}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Function to start a single runner
start_runner() {
__start_runner() {
local runner_id=$1
local runner_name="${RUNNER_NAME_PREFIX:-runner}-${runner_id}"
local runner_dir="/data/runner-${runner_id}"
local runner_dir="/config/act_runner/reg/${runner_name}"
# Create runner directory
mkdir -p "$runner_dir"
cd "$runner_dir"
log "Starting runner: $runner_name (ID: $runner_id)"
__log "Starting runner: $runner_name (ID: $runner_id)"
# Register the runner (this creates the .runner file)
log "Registering runner: $runner_name"
act_runner register \
--instance "$SERVER_ADDRESS" \
--token "$SERVER_TOKEN" \
--name "$runner_name" \
--labels "$RUNNER_LABELS" \
--no-interactive
__log "Registering runner: $runner_name"
act_runner register --instance "$SERVER_ADDRESS" --token "$SERVER_TOKEN" --name "$runner_name" --labels "$RUNNER_LABELS" --no-interactive
if [ $? -ne 0 ]; then
log "ERROR: Failed to register runner $runner_name"
__log "ERROR: Failed to register runner $runner_name"
return 1
fi
# Start the daemon
log "Starting daemon for runner: $runner_name"
__log "Starting daemon for runner: $runner_name"
exec act_runner daemon --config .runner
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Start runners in background
for i in $(seq 1 $RUNNERS_COUNT); do
(start_runner $i) &
(__start_runner $i) &
sleep 2 # Small delay between starting runners
done
log "All $RUNNERS_COUNT runners started successfully"
log "Process IDs: $(jobs -p | tr '\n' ' ')"
unset i
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__log "All $RUNNERS_COUNT runners started successfully"
__log "Process IDs: $(jobs -p | tr '\n' ' ')"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Wait for all background processes
wait

View File

@@ -188,6 +188,7 @@ __run_pre_execute_checks() {
# Put command to execute in parentheses
{
[ -d "/etc/docker" ] || mkdir -p "/etc/docker"
[ -d "/data/docker" ] || mkdir -p "/data/docker"
[ -d "/config/docker" ] || mkdir -p "/config/docker"
[ -L "/config/docker/daemon.json" ] && unlink "/config/docker/daemon.json"
if [ -n "$DOCKER_REGISTRIES" ]; then

View File

@@ -362,7 +362,7 @@ __post_execute() {
local postMessageST="Running post commands for $SERVICE_NAME" # message to show at start
local postMessageEnd="Finished post commands for $SERVICE_NAME" # message to show at completion
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
export SERVER_ADDRESS="$INSTANCE_HOSTNAME" SERVER_TOKEN="${RUNNER_AUTH_TOKEN:-$SYS_AUTH_TOKEN}" RUNNERS_ENABLE="${RUNNERS_START:-5}" RUNNER_LABELS
export SERVER_ADDRESS="$RUNNER_IP_ADDRESS:$GITEA_PORT" SERVER_TOKEN="${RUNNER_AUTH_TOKEN:-$SYS_AUTH_TOKEN}" RUNNERS_ENABLE="${RUNNERS_START:-5}" RUNNER_LABELS
# wait
sleep $waitTime
# execute commands