gitea version (first attempt)
This commit is contained in:
15
.github/workflows/publish.yml
vendored
15
.github/workflows/publish.yml
vendored
@@ -10,21 +10,12 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Build & push (ltsc2022)
|
||||
- name: Build & push
|
||||
uses: mr-smithers-excellent/docker-build-push@v6
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
image: tiobesoftware/github-runner-windows
|
||||
tags: ${{ github.ref_name }}-20H2
|
||||
registry: docker.io
|
||||
buildArgs: SERVERCORE_VERSION="ltsc2022",RUNNER_VERSION="${{ github.ref_name }}"
|
||||
- name: Build & push (20H2)
|
||||
uses: mr-smithers-excellent/docker-build-push@v6
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
image: tiobesoftware/github-runner-windows
|
||||
image: ${{ github.repository_owner }}/gitea-runner-windows
|
||||
tags: ${{ github.ref_name }}, latest
|
||||
registry: docker.io
|
||||
buildArgs: SERVERCORE_VERSION="20H2",RUNNER_VERSION="${{ github.ref_name }}"
|
||||
buildArgs: SERVERCORE_VERSION="ltsc2022",RUNNER_VERSION="${{ github.ref_name }}"
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
ARG SERVERCORE_VERSION="ltsc2022"
|
||||
ARG RUNNER_VERSION="2.319.1"
|
||||
ARG RUNNER_VERSION="0.2.11"
|
||||
|
||||
FROM mcr.microsoft.com/windows/servercore:${SERVERCORE_VERSION}
|
||||
|
||||
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
|
||||
|
||||
# disable telemetry
|
||||
ENV POWERSHELL_TELEMETRY_OPTOUT="1"
|
||||
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /actions-runner
|
||||
|
||||
@@ -31,9 +35,9 @@ RUN choco install -y visualstudio2022buildtools --package-parameters \" \
|
||||
# Add MSBuild to the path
|
||||
RUN [Environment]::SetEnvironmentVariable(\"Path\", $env:Path + \";C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\", \"Machine\")
|
||||
|
||||
ENV RUNNER_VERSION=${RUNNER_VERSION}
|
||||
COPY install-runner.ps1 .
|
||||
RUN .\install-runner.ps1; Remove-Item .\install-runner.ps1 -Force
|
||||
|
||||
COPY entrypoint.ps1 .
|
||||
|
||||
ENTRYPOINT ["pwsh.exe", ".\\entrypoint.ps1"]
|
||||
28
README.md
28
README.md
@@ -1,24 +1,16 @@
|
||||
# Windows Docker GitHub Runner
|
||||
# Windows Docker Gitea Runner
|
||||
|
||||
This repository is a Windows version of the [myoung34/docker-github-actions-runner](https://github.com/myoung34/docker-github-actions-runner) runner for Linux. Tried has been to keep the usage as close as possible.
|
||||
This repository is a Gitea version of the [tiobe/docker-github-runner-windows](https://github.com/tiobe/docker-github-runner-windows) runner for GitHub.
|
||||
|
||||
This repository will run the [self-hosted github actions runners](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/hosting-your-own-runners) for Windows with [Visual Studio 2022 buildtools](https://community.chocolatey.org/packages/visualstudio2022buildtools) installed by default.
|
||||
This repository will run the [self-hosted gitea actions runners](https://gitea.com/gitea/act_runner) for Windows with [Visual Studio 2022 buildtools](https://community.chocolatey.org/packages/visualstudio2022buildtools) installed by default.
|
||||
|
||||
The build images can be found on [Docker Hub](https://hub.docker.com/r/tiobesoftware/github-runner-windows).
|
||||
The build images can be found on [Docker Hub](https://hub.docker.com/r/fidarit/gitea-runner-windows).
|
||||
|
||||
## Environment variables
|
||||
|
||||
| Environment Variable | Description |
|
||||
| --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `RUNNER_NAME` | The name of the runner to use. Overrides `RUNNER_NAME_PREFIX` |
|
||||
| `RUNNER_NAME_PREFIX` | A prefix for runner name. Note: will be overridden by `RUNNER_NAME` if provided. Defaults to `windows-runner` |
|
||||
| `ACCESS_TOKEN` | A [github PAT](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) to use to generate `RUNNER_TOKEN` dynamically at container start. Not using this requires a valid `RUNNER_TOKEN` |
|
||||
| `RUNNER_TOKEN` | If not using a PAT for `ACCESS_TOKEN` this will be the runner token provided by the Add Runner UI (a manual process). Note: This token is short lived and will change frequently. `ACCESS_TOKEN` is likely preferred. |
|
||||
| `RUNNER_SCOPE` | The scope the runner will be registered on. Valid values are `repo`, `org` and `enterprise`. For 'org' and 'enterprise' the `REPO_URL` is unnecessary. If 'org', requires `ORG_NAME`; if 'enterprise', requires `ENTERPRISE_NAME`. Default is 'repo'. |
|
||||
| `ORG_NAME` | The organization name for the runner to register under. Requires `RUNNER_SCOPE` to be 'org'. No default value. |
|
||||
| `ENTERPRISE_NAME` | The enterprise name for the runner to register under. Requires `RUNNER_SCOPE` to be 'enterprise'. No default value. |
|
||||
| `LABELS` | A comma separated string to indicate the labels. Default is 'default' |
|
||||
| `REPO_URL` | If using a non-organization runner this is the full repository url to register under such as 'https://github.com/tiobe/repo' |
|
||||
| `RUNNER_GROUP` | Name of the runner group to add this runner to (defaults to the default runner group) |
|
||||
| `GITHUB_HOST` | Optional URL of the Github Enterprise server e.g github.mycompany.com. Defaults to `github.com`. |
|
||||
| `DISABLE_AUTO_UPDATE` | Optional environment variable to [disable auto updates](https://github.blog/changelog/2022-02-01-github-actions-self-hosted-runners-can-now-disable-automatic-updates/). Auto updates are enabled by default to preserve past behavior. Any value is considered truthy and will disable them. |
|
||||
| Environment Variable | Description |
|
||||
| --------------------------------- | ------------------------------------------------------------------------------------------------- |
|
||||
| `GITEA_RUNNER_NAME` | The name of the runner to use. |
|
||||
| `GITEA_RUNNER_REGISTRATION_TOKEN` | The format of the registration token is a random string D0gvfu2iHfUjNqCYVljVyRV14fISpJxxxxxxxxxx. |
|
||||
| `GITEA_RUNNER_LABELS` | A comma separated string to indicate the labels. Default is 'windows:host' |
|
||||
| `GITEA_INSTANCE_URL` | URL of the Gitea server e.g gitea.mycompany.com. |
|
||||
|
||||
126
entrypoint.ps1
126
entrypoint.ps1
@@ -1,130 +1,22 @@
|
||||
|
||||
# Set the runner name
|
||||
if ($null -ne $env:RUNNER_NAME) {
|
||||
$RUNNER_NAME = $env:RUNNER_NAME
|
||||
} else {
|
||||
if ($null -ne $env:RUNNER_NAME_PREFIX) {
|
||||
$RUNNER_NAME = $env:RUNNER_NAME_PREFIX
|
||||
} else {
|
||||
$RUNNER_NAME = "windows-runner"
|
||||
}
|
||||
|
||||
$RUNNER_NAME += "-" + (((New-Guid).Guid).replace("-", "")).substring(0, 8)
|
||||
}
|
||||
|
||||
# Set GitHub host if not set
|
||||
if ($null -ne $env:GITHUB_HOST) {
|
||||
$GITHUB_HOST = $env:GITHUB_HOST
|
||||
} else {
|
||||
$GITHUB_HOST = 'github.com'
|
||||
}
|
||||
|
||||
# Set the api url
|
||||
if ('github.com' -eq $GITHUB_HOST) {
|
||||
$URI = "https://api.$GITHUB_HOST"
|
||||
} else {
|
||||
$URI = "https://$GITHUB_HOST/api/v3"
|
||||
}
|
||||
|
||||
# Set the api to get the access token from
|
||||
switch ($env:RUNNER_SCOPE) {
|
||||
org {
|
||||
if ($null -eq $env:ORG_NAME) {
|
||||
Write-Error "ORG_NAME required for organisational runners"
|
||||
exit 1
|
||||
}
|
||||
Write-Host "Setting up GitHub Self Hosted Runner for organisation: $env:ORG_NAME"
|
||||
$TOKEN_URL = "$URI/orgs/$env:ORG_NAME/actions/runners/registration-token"
|
||||
$CONFIG_URL = "https://$GITHUB_HOST/$env:ORG_NAME"
|
||||
}
|
||||
|
||||
enterprise {
|
||||
if ($null -eq $env:ENTERPRISE_NAME) {
|
||||
Write-Error "ENTERPRISE_NAME required for enterprise runners"
|
||||
exit
|
||||
}
|
||||
Write-Host "Setting up GitHub Self Hosted Runner for enterprise: $env:ENTERPRISE_NAME"
|
||||
$TOKEN_URL = "$URI/enterprises/$env:ENTERPRISE_NAME/actions/runners/registration-token"
|
||||
$CONFIG_URL = "https://$GITHUB_HOST/enterprises/$env:ENTERPRISE_NAME"
|
||||
}
|
||||
|
||||
default {
|
||||
if ($null -eq $env:REPO_URL) {
|
||||
Write-Error "REPO_URL required for repository runners"
|
||||
exit
|
||||
}
|
||||
if ($null -ne $env:RUNNER_TOKEN) {
|
||||
$RUNNER_TOKEN = $env:RUNNER_TOKEN
|
||||
} elseif ($null -ne $env:ACCESS_TOKEN) {
|
||||
$PATTERN = "https://(?:[^/]+/)?([^/]+)/([^/]+)"
|
||||
if ($env:REPO_URL -match $PATTERN) {
|
||||
|
||||
$OWNER = $Matches[1]
|
||||
$REPO = $Matches[2]
|
||||
|
||||
$TOKEN_URL = "$URI/repos/$OWNER/$REPO/actions/runners/registration-token"
|
||||
} else {
|
||||
Write-Error "URL format not recognized: $env:REPO_URL"
|
||||
}
|
||||
} else {
|
||||
Write-Error "ACCESS_TOKEN or RUNNER_TOKEN required for repository runners"
|
||||
exit
|
||||
}
|
||||
Write-Host "Setting up GitHub Self Hosted Runner for repository: $env:REPO_URL"
|
||||
|
||||
$CONFIG_URL = $env:REPO_URL
|
||||
}
|
||||
}
|
||||
|
||||
if ($null -ne $TOKEN_URL) {
|
||||
$HEADERS = @{
|
||||
'Accept' = 'application/vnd.github.v3+json';
|
||||
'Authorization' = "token $env:ACCESS_TOKEN";
|
||||
'Content-Length' = '0';
|
||||
}
|
||||
|
||||
try {
|
||||
Write-Host "Obtaining the token for the runner"
|
||||
$RUNNER_TOKEN = ((Invoke-WebRequest -Uri $TOKEN_URL -Method "POST" -Headers $HEADERS).Content | ConvertFrom-Json).token
|
||||
}
|
||||
catch {
|
||||
Write-Error "Cannot obtain the token => $_"
|
||||
exit
|
||||
}
|
||||
}
|
||||
|
||||
# Set the labels if given
|
||||
if ($null -ne $env:LABELS) {
|
||||
$LABELS = $env:LABELS
|
||||
if ($null -ne $env:GITEA_RUNNER_LABELS) {
|
||||
$LABELS = $env:GITEA_RUNNER_LABELS
|
||||
} else {
|
||||
$LABELS = 'default'
|
||||
$LABELS = 'windows:host'
|
||||
}
|
||||
|
||||
# Set the labels if given
|
||||
if ($null -ne $env:RUNNER_GROUP) {
|
||||
$RUNNER_GROUP = $env:RUNNER_GROUP
|
||||
} else {
|
||||
$RUNNER_GROUP = 'Default'
|
||||
}
|
||||
|
||||
$EXTRA_ARGS=''
|
||||
|
||||
# Disable auto update if set
|
||||
if ($null -ne $env:DISABLE_AUTO_UPDATE) {
|
||||
Write-Host "Auto updating is disabled"
|
||||
$EXTRA_ARGS += " --disableupdate"
|
||||
}
|
||||
$GITEA_RUNNER_NAME = $env:GITEA_RUNNER_NAME
|
||||
$GITEA_INSTANCE_URL = $env:GITEA_INSTANCE_URL
|
||||
$GITEA_RUNNER_REGISTRATION_TOKEN = $env:GITEA_RUNNER_REGISTRATION_TOKEN
|
||||
|
||||
try {
|
||||
Write-Host "Configuring runner: $RUNNER_NAME"
|
||||
./config.cmd --unattended --replace --url $CONFIG_URL --token $RUNNER_TOKEN --name $RUNNER_NAME --labels $LABELS --runnergroup $RUNNER_GROUP $EXTRA_ARGS
|
||||
Write-Host "Configuring runner: $GITEA_RUNNER_NAME"
|
||||
./act_runner.exe register --no-interactive --instance $GITEA_INSTANCE_URL --token $GITEA_RUNNER_REGISTRATION_TOKEN --name $GITEA_RUNNER_NAME --labels $LABELS
|
||||
|
||||
# Remove access token for security reasons
|
||||
$env:ACCESS_TOKEN=$null
|
||||
|
||||
./run.cmd
|
||||
./act_runner.exe daemon
|
||||
} catch {
|
||||
Write-Error $_.Exception.Message
|
||||
} finally {
|
||||
./config.cmd remove --unattended --token $RUNNER_TOKEN
|
||||
}
|
||||
@@ -1,2 +1 @@
|
||||
Invoke-WebRequest -Uri "https://github.com/actions/runner/releases/download/v$env:RUNNER_VERSION/actions-runner-win-x64-$env:RUNNER_VERSION.zip" -OutFile "actions-runner.zip"
|
||||
Expand-Archive -Path ".\\actions-runner.zip" -DestinationPath '.'
|
||||
Invoke-WebRequest -Uri "https://gitea.com/gitea/act_runner/releases/download/v$env:RUNNER_VERSION/act_runner-$env:RUNNER_VERSION-windows-amd64.exe" -OutFile "act_runner.exe"
|
||||
Reference in New Issue
Block a user