From a8557e9cdb298751fdf53a2597c1fbb59f8121bc Mon Sep 17 00:00:00 2001 From: yourfriendoss Date: Sun, 19 Oct 2025 16:52:53 +0300 Subject: [PATCH] first commit --- .gitignore | 1 + Dockerfile | 26 ++++++++++++++++ build.ps1 | 4 +++ gitea-runner.ps1 | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 build.ps1 create mode 100644 gitea-runner.ps1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6469fc0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +run.ps1 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..79f8ef3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM mcr.microsoft.com/windows/servercore:ltsc2022 + +WORKDIR C:/app + +RUN mkdir C:\data +RUN mkdir C:\temp + +COPY gitea-runner.ps1 C:/app/gitea-runner.ps1 +ADD https://dl.gitea.com/act_runner/0.2.13/act_runner-0.2.13-windows-amd64.exe C:/act_runner.exe + +SHELL ["powershell", "-NoProfile", "-Command"] +RUN Set-ExecutionPolicy Bypass -Scope Process -Force; \ + [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; \ + Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')); \ + choco install git -y; \ + choco install nodejs --version=20.10.0 -y; + +SHELL ["cmd", "/S", "/C"] + +# Default environment variables +ENV RUNNER_STATE_FILE=".runner" +ENV GITEA_MAX_REG_ATTEMPTS=10 + +VOLUME ["C:/data"] + +ENTRYPOINT ["powershell.exe", "-NoProfile", "-File", "C:/app/gitea-runner.ps1"] diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..6f3abb2 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,4 @@ +docker login git.sad.ovh + +docker build -t git.sad.ovh/sophie/act-runner-windows-cursed:latest . +docker push git.sad.ovh/sophie/act-runner-windows-cursed:latest diff --git a/gitea-runner.ps1 b/gitea-runner.ps1 new file mode 100644 index 0000000..0361286 --- /dev/null +++ b/gitea-runner.ps1 @@ -0,0 +1,80 @@ +# Ensure /data equivalent exists +$DataDir = "C:\data" +if (-not (Test-Path $DataDir)) { + New-Item -ItemType Directory -Path $DataDir | Out-Null +} + +Set-Location $DataDir + +# State file +$RUNNER_STATE_FILE = $env:RUNNER_STATE_FILE +if (-not $RUNNER_STATE_FILE) { $RUNNER_STATE_FILE = ".runner" } + +# Config argument +$CONFIG_ARG = "" +if ($env:CONFIG_FILE) { + $CONFIG_ARG = "--config $($env:CONFIG_FILE)" +} + +# Extra arguments +$EXTRA_ARGS = "" +if ($env:GITEA_RUNNER_LABELS) { + $EXTRA_ARGS += " --labels $($env:GITEA_RUNNER_LABELS)" +} +if ($env:GITEA_RUNNER_EPHEMERAL) { + $EXTRA_ARGS += " --ephemeral" +} + +# Run arguments +$RUN_ARGS = "" +if ($env:GITEA_RUNNER_ONCE) { + $RUN_ARGS = "--once" +} + +# Read token from file if not set +if (-not $env:GITEA_RUNNER_REGISTRATION_TOKEN -and (Test-Path $env:GITEA_RUNNER_REGISTRATION_TOKEN_FILE)) { + $env:GITEA_RUNNER_REGISTRATION_TOKEN = Get-Content $env:GITEA_RUNNER_REGISTRATION_TOKEN_FILE -Raw +} + +# Check state file +if (-not (Test-Path $RUNNER_STATE_FILE -PathType Leaf)) { + Write-Host "$RUNNER_STATE_FILE is missing or not a regular file" +} + +# Initialize variables for registration loop +$try = 0 +$success = $false + +if (-not (Get-Item $RUNNER_STATE_FILE).Length) { + $maxAttempts = if ($env:GITEA_MAX_REG_ATTEMPTS) { [int]$env:GITEA_MAX_REG_ATTEMPTS } else { 10 } + + while (-not $success -and $try -lt $maxAttempts) { + $try++ + Write-Host "Attempt #$try to register runner..." + + # Build the full command as a string + $regCommand = "C:\act_runner.exe register --instance `"$env:GITEA_INSTANCE_URL`" --token `"$env:GITEA_RUNNER_REGISTRATION_TOKEN`" --name `"$($env:GITEA_RUNNER_NAME -or $env:COMPUTERNAME)`" $CONFIG_ARG $EXTRA_ARGS --no-interactive" + + # Execute the command + $regOutput = Invoke-Expression "$regCommand 2>&1" + + # Log output + $regOutput | Tee-Object -FilePath "C:\temp\reg.log" + + if ($regOutput -match "Runner registered successfully") { + Write-Host "SUCCESS" + $success = $true + } else { + Write-Host "Waiting to retry ..." + Start-Sleep -Seconds 5 + } + } +} + +# Unset sensitive env vars +Remove-Item Env:\GITEA_RUNNER_REGISTRATION_TOKEN -ErrorAction SilentlyContinue +Remove-Item Env:\GITEA_RUNNER_REGISTRATION_TOKEN_FILE -ErrorAction SilentlyContinue + +# Start daemon +$daemonCommand = "C:\act_runner.exe daemon $CONFIG_ARG $RUN_ARGS" +Invoke-Expression "$daemonCommand"