first commit
This commit is contained in:
commit
a8557e9cdb
4 changed files with 111 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
run.ps1
|
||||||
26
Dockerfile
Normal file
26
Dockerfile
Normal file
|
|
@ -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"]
|
||||||
4
build.ps1
Normal file
4
build.ps1
Normal file
|
|
@ -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
|
||||||
80
gitea-runner.ps1
Normal file
80
gitea-runner.ps1
Normal file
|
|
@ -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"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue