Skip to content

Commit 2780d75

Browse files
authored
Merge pull request #12 from nod-ai/users/eliasj42/transfer-arc-windows-runner
added windows-arc-runner to Github arc setup
2 parents 78d530d + c279bf5 commit 2780d75

File tree

6 files changed

+339
-0
lines changed

6 files changed

+339
-0
lines changed

.github/workflows/docker-image.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Copyright (c) 2023 Ken Muse
2+
# Copyright (c) Advanced Micro Devices, Inc. All rights reserved.
3+
# SPDX-License-Identifier: MIT
4+
5+
name: Docker Image Build
6+
7+
on:
8+
push:
9+
branches: [ main ]
10+
11+
permissions:
12+
contents: read
13+
packages: write
14+
id-token: write
15+
16+
env:
17+
REGISTRY: ghcr.io
18+
IMAGE_NAME: nod-ai/arc-windows-runner
19+
20+
jobs:
21+
build:
22+
runs-on: windows-2022
23+
steps:
24+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
25+
26+
- name: Log into registry ${{ env.REGISTRY }}
27+
if: github.event_name != 'pull_request'
28+
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
29+
with:
30+
registry: ${{ env.REGISTRY }}
31+
username: ${{ github.actor }}
32+
password: ${{ secrets.GITHUB_TOKEN }}
33+
34+
# BuildX is not supported and should not be installed or configured
35+
# Features such as multistage builds and cache support are not available
36+
- name: Get Versions
37+
id: versions
38+
env:
39+
AUTH: Bearer ${{ github.token }}
40+
REPO_OWNER: ${{ github.event.repository.owner.login }}
41+
REPO_NAME: ${{ github.event.repository.name }}
42+
REPO_ORG: ${{ github.event.organization.login }}
43+
run: |
44+
$repoOwner = $env:REPO_OWNER
45+
$repoName = $env:REPO_NAME
46+
$orgName = $env:REPO_ORG
47+
48+
# The URL is different for personal or organization endpoints, so resolve the correct one
49+
# The org variable should be non-empty and match the owner name if this is an organization.
50+
$packageUrl = ($repoOwner -eq $orgName) ? "https://api.github.com/orgs/$repoOwner/packages/container/$repoName/versions" : "https://api.github.com/users/$repoOwner/packages/container/$repoName/versions"
51+
52+
# PowerShell 7 syntax to avoid raising an exception.
53+
$apiResults = Invoke-WebRequest -Headers @{ "Authorization"=$env:AUTH } -Uri $packageUrl -SkipHttpErrorCheck
54+
if ($apiResults.StatusCode -eq 200) {
55+
$content = $apiResults.Content | ConvertFrom-Json
56+
}
57+
elseif ($apiResults.StatusCode -eq 404) {
58+
$content = @()
59+
}
60+
else {
61+
Write-Host "Status Code: ${apiResults.StatusCode}"
62+
Write-Host "Error: ${apiResults.Content}"
63+
exit $apiResults.StatusCode
64+
}
65+
66+
$publishedImageVersions = $($apiResults.Content | ConvertFrom-Json) | %{ [PSCustomObject]@{ Id=$_.id; Url=$_.url;Tags=$_.metadata.container.tags } } | %{ $_.tags }
67+
$currentRunnerVersion = ((Invoke-WebRequest -Uri https://api.github.com/repos/actions/runner/releases/latest).Content | ConvertFrom-Json).tag_name -replace 'v',''
68+
$currentHooksVersion = ((Invoke-WebRequest -Uri https://api.github.com/repos/actions/runner-container-hooks/releases/latest).Content | ConvertFrom-Json).tag_name -replace 'v',''
69+
70+
# Convert the values to step outputs
71+
echo "PUBLISHED=$($publishedImageVersions -Contains "v${currentRunnerVersion}")" >> ${env:GITHUB_OUTPUT}
72+
echo "RUNNER_VERSION=${currentRunnerVersion}" >> ${env:GITHUB_OUTPUT}
73+
echo "RUNNER_HOOKS_VERSION=${currentHooksVersion}" >> ${env:GITHUB_OUTPUT}
74+
75+
# Output details to the step summary
76+
echo "**Current Runner version :** v${currentRunnerVersion}" >> ${env:GITHUB_STEP_SUMMARY}
77+
echo "**Current Runner hooks version:** v${currentHooksVersion}" >> ${env:GITHUB_STEP_SUMMARY}
78+
echo "**Published New Image:** $($publishedImageVersions -Contains "v${currentRunnerVersion}")" >> ${env:GITHUB_STEP_SUMMARY}
79+
- name: Docker Build
80+
if: ${{ steps.versions.outputs.PUBLISHED != 'True' }}
81+
env:
82+
RUNNER_VERSION: ${{ steps.versions.outputs.RUNNER_VERSION }}
83+
RUNNER_HOOKS_VERSION: ${{ steps.versions.outputs.RUNNER_HOOKS_VERSION }}
84+
run: |
85+
$currentRunnerVersion = $env:RUNNER_VERSION
86+
$currentHooksVersion = $env:RUNNER_HOOKS_VERSION
87+
docker build --build-arg RUNNER_CONTAINER_HOOKS_VERSION=$currentHooksVersion --build-arg RUNNER_VERSION=$currentRunnerVersion -f windows-arc-runner/Dockerfile -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:"v${currentRunnerVersion}" .
88+
- name: Docker Push
89+
if: ${{ github.event_name != 'pull_request' && steps.versions.outputs.PUBLISHED != 'True' }}
90+
run: |
91+
docker push -a ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
92+
93+

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Advanced Micro Devices, Inc. All rights reserved.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

windows-arc-runner/Dockerfile

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Copyright (c) 2023 Ken Muse
2+
# Copyright (c) Advanced Micro Devices, Inc. All rights reserved.
3+
# SPDX-License-Identifier: MIT
4+
5+
# escape=`
6+
7+
FROM mcr.microsoft.com/windows/servercore:ltsc2022
8+
ARG RUNNER_OS=win
9+
ARG RUNNER_ARCH=x64
10+
ARG RUNNER_VERSION
11+
ARG RUNNER_CONTAINER_HOOKS_VERSION=0.6.1
12+
13+
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';$ProgressPreference='silentlyContinue';"]
14+
15+
WORKDIR /home/runner
16+
17+
SHELL ["cmd", "/C"]
18+
19+
RUN setx /M PATH "%PATH%;C:/home/runner"
20+
21+
RUN echo $Env:PATH
22+
23+
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';$ProgressPreference='silentlyContinue';"]
24+
25+
RUN `
26+
###############################################################################################
27+
# Install Actions Runner
28+
# You must always install the runner, and you want the latest version to avoid the restrictions
29+
# applied to out-of-date runners.
30+
# https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/autoscaling-with-self-hosted-runners#:~:text=Warning,-Any%20updates%20released
31+
###############################################################################################
32+
Invoke-WebRequest -Uri https://github.com/actions/runner/releases/download/v${env:RUNNER_VERSION}/actions-runner-${env:RUNNER_OS}-${env:RUNNER_ARCH}-${env:RUNNER_VERSION}.zip -OutFile actions-runner.zip;`
33+
Add-Type -AssemblyName System.IO.Compression.FileSystem;`
34+
[System.IO.Compression.ZipFile]::ExtractToDirectory('actions-runner.zip', $PWD);`
35+
Remove-Item -Path actions-runner.zip -Force;`
36+
###############################################################################################
37+
# Install Runner Container Hooks
38+
# While it is possible to include these hooks, Windows runners can't use these today.
39+
# GitHub documents that you must use Linux runners for Docker container actions, job containers,
40+
# or service containers.
41+
# See also https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_idservices
42+
# and https://github.com/actions/runner/issues/904
43+
###############################################################################################
44+
# Invoke-WebRequest -OutFile runner-container-hooks.zip -Uri https://github.com/actions/runner-container-hooks/releases/download/v${env:RUNNER_CONTAINER_HOOKS_VERSION}/actions-runner-hooks-k8s-${env:RUNNER_CONTAINER_HOOKS_VERSION}.zip;`
45+
# [System.IO.Compression.ZipFile]::ExtractToDirectory('runner-container-hooks.zip', (Join-Path -Path $PWD -ChildPath 'k8s'));`
46+
# Remove-Item -Path runner-container-hooks.zip -Force;`
47+
###############################################################################################
48+
# Install Git Using Choco
49+
# Runners should have access to the latest version of Git and Git LFS, which we can
50+
# install using Choco. This also makes a Bash shell available on Windows for scripting.
51+
# You may want to include other tools and script engines as well.
52+
###############################################################################################
53+
Set-ExecutionPolicy Bypass -Scope Process -Force;`
54+
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;`
55+
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'));`
56+
choco install -y git.install gh powershell-core azure-cli;`
57+
choco feature enable -n allowGlobalConfirmation;`
58+
###############################################################################################
59+
# Install Docker CLI Using Choco
60+
# It's important to know that Windows doesn't support nested containers, so you can't
61+
# use a Docker-in-Docker on Windows. That frequently limits the value of having the
62+
# Docker CLI available on your images.
63+
###############################################################################################
64+
choco install docker-cli docker-compose -force;
65+
66+
# Append Git\bin to $PATH so bash.exe can be used.
67+
RUN setx /M PATH $($Env:PATH + ';C:\Program Files\Git\bin')
68+
69+
RUN New-ItemProperty -Path "HKLM:\\SYSTEM\\CurrentControlSet\\Control\\FileSystem" -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force
70+
71+
# Download vswhere.exe from the official GitHub releases
72+
RUN Invoke-WebRequest -Uri "https://github.com/microsoft/vswhere/releases/download/2.8.4/vswhere.exe" -OutFile "vswhere.exe"
73+
74+
RUN .\vswhere.exe
75+
RUN vswhere
76+
# Set the entrypoint to cmd.exe so you can run vswhere
77+
78+
# Restore the default Windows shell for correct batch processing.
79+
SHELL ["cmd", "/S", "/C"]
80+
81+
RUN `
82+
# Download the Build Tools bootstrapper.
83+
curl -SL --output vs_buildtools.exe https://aka.ms/vs/17/release/vs_buildtools.exe `
84+
`
85+
# Install Build Tools with the Microsoft.VisualStudio.Workload.AzureBuildTools workload, excluding workloads and components with known issues.
86+
&& (start /w vs_buildtools.exe --quiet --wait --norestart --nocache `
87+
--installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2022\BuildTools" `
88+
--add Microsoft.VisualStudio.Workload.AzureBuildTools `
89+
--remove Microsoft.VisualStudio.Component.Windows10SDK.10240 `
90+
--remove Microsoft.VisualStudio.Component.Windows10SDK.10586 `
91+
--remove Microsoft.VisualStudio.Component.Windows10SDK.14393 `
92+
--remove Microsoft.VisualStudio.Component.Windows81SDK `
93+
|| IF "%ERRORLEVEL%"=="3010" EXIT 0) `
94+
`
95+
# Cleanup
96+
&& del /q vs_buildtools.exe
97+
98+
# Define the entry point for the docker container.
99+
# This entry point starts the developer command prompt and launches the PowerShell shell.
100+
RUN choco install cmake --version=3.31.0 -y --no-progress --installargs '"ADD_CMAKE_TO_PATH=System"'
101+
RUN choco install python --version=3.13.7 -y --no-progress
102+
RUN python -m pip install --upgrade certifi
103+
RUN setx SSL_CERT_FILE "C:\Users\ContainerAdministrator\AppData\Local\Programs\Python\Python310\Lib\site-packages\certifi\cacert.pem"
104+
RUN certutil -generateSSTFromWU certs.sst
105+
RUN certutil -addstore -f ROOT certs.sst
106+
RUN del certs.sst
107+
RUN choco install visualstudio2022-workload-vctools "--add Microsoft.VisualStudio.Component.ATL" -y --no-progress
108+
RUN python -m pip install setuptools
109+
RUN choco install visualstudio2022buildtools -y
110+
RUN choco install visualstudio2022community --package-parameters "--add Microsoft.VisualStudio.Workload.CoreEditor --add Microsoft.VisualStudio.Workload.ManagedDesktop --add Microsoft.VisualStudio.Workload.DesktopDevelopmentWithC++" -y
111+
RUN choco install visualstudio2022-workload-nativedesktop -y
112+
RUN git clone https://github.com/microsoft/vcpkg.git C:\vcpkg `
113+
&& cd C:\vcpkg `
114+
&& bootstrap-vcpkg.bat `
115+
&& SETX /M PATH "C:\vcpkg;%PATH%" `
116+
&& vcpkg install zlib:x64-windows --clean-after-build `
117+
&& vcpkg remove zlib:x64-windows
118+
119+
ENTRYPOINT ["C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Auxiliary\\Build\\vcvars64.bat", "&&", "powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright (c) 2023 Ken Muse
2+
# Copyright (c) Advanced Micro Devices, Inc. All rights reserved.
3+
# SPDX-License-Identifier: MIT
4+
5+
#This script invokes GitHub-CLI (Pre-installed on container image)
6+
Param (
7+
[Parameter(Mandatory = $false)]
8+
[string]$owner = $env:GH_OWNER,
9+
[Parameter(Mandatory = $false)]
10+
[string]$repo = $env:GH_REPOSITORY,
11+
[Parameter(Mandatory = $false)]
12+
[string]$pat = $env:GH_TOKEN
13+
)
14+
15+
#Use --with-token to pass in a PAT token on standard input. The minimum required scopes for the token are: "repo", "read:org".
16+
#Alternatively, gh will use the authentication token found in environment variables. See gh help environment for more info.
17+
#To use gh in GitHub Actions, add GH_TOKEN: $ to "env". on Docker run: Docker run -e GH_TOKEN='myPatToken'
18+
gh auth login --with-token $pat
19+
20+
#Cleanup#
21+
#Look for any old/stale dockerNode- registrations to clean up
22+
#Windows containers cannot gracefully remove registration via powershell due to issue: https://github.com/moby/moby/issues/25982#
23+
#For this reason we can use this scrip to cleanup old offline instances/registrations
24+
$runnerBaseName = "dockerNode-"
25+
$runnerListJson = gh api -H "Accept: application/vnd.github.v3+json" "/repos/$owner/$repo/actions/runners"
26+
$runnerList = (ConvertFrom-Json -InputObject $runnerListJson).runners
27+
28+
Foreach ($runner in $runnerList) {
29+
try {
30+
If (($runner.name -like "$runnerBaseName*") -and ($runner.status -eq "offline")) {
31+
write-host "Unregsitering old stale runner: $($runner.name)"
32+
gh api --method DELETE -H "Accept: application/vnd.github.v3+json" "/repos/$owner/$repo/actions/runners/$($runner.id)"
33+
}
34+
}
35+
catch {
36+
Write-Error $_.Exception.Message
37+
}
38+
}
39+
40+
#Remove PAT token after cleanup
41+
$pat=$null
42+
$env:GH_TOKEN=$null
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (c) 2023 Ken Muse
2+
# Copyright (c) Advanced Micro Devices, Inc. All rights reserved.
3+
# SPDX-License-Identifier: MIT
4+
5+
$securityProtocolSettingsOriginal = [System.Net.ServicePointManager]::SecurityProtocol
6+
try {
7+
# Set TLS 1.2 (3072), then TLS 1.1 (768), then TLS 1.0 (192), finally SSL 3.0 (48)
8+
# Use integers because the enumeration values for TLS 1.2 and TLS 1.1 won’t
9+
# exist in .NET 4.0, even though they are addressable if .NET 4.5+ is
10+
# installed (.NET 4.5 is an in-place upgrade).
11+
[System.Net.ServicePointManager]::SecurityProtocol = 3072 -bor 768 -bor 192 -bor 48
12+
}
13+
catch {
14+
Write-Warning "Unable to set PowerShell to use TLS 1.2 and TLS 1.1 check .NET Framework installed. If you see underlying connection closed or trust errors, try the following: (1) upgrade to .NET Framework 4.5 (2) specify internal Chocolatey package location (set $env:chocolateyDownloadUrl prior to install or host the package internally), (3) use the Download + PowerShell method of install. See https://chocolatey.org/install for all install options."
15+
}
16+
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
17+
[System.Net.ServicePointManager]::SecurityProtocol = $securityProtocolSettingsOriginal
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright (c) 2023 Ken Muse
2+
# Copyright (c) Advanced Micro Devices, Inc. All rights reserved.
3+
# SPDX-License-Identifier: MIT
4+
5+
#This script invokes GitHub-CLI (Already installed on container image)
6+
#To use this entrypoint script run: Docker run -e GH_TOKEN='myPatToken' -e GH_OWNER='orgName' -e GH_REPOSITORY='repoName' -d imageName
7+
Param (
8+
[Parameter(Mandatory = $false)]
9+
[string]$owner = $env:GH_OWNER,
10+
[Parameter(Mandatory = $false)]
11+
[string]$repo = $env:GH_REPOSITORY,
12+
[Parameter(Mandatory = $false)]
13+
[string]$pat = $env:GH_TOKEN
14+
)
15+
16+
#Use --with-token to pass in a PAT token on standard input. The minimum required scopes for the token are: "repo", "read:org".
17+
#Alternatively, gh will use the authentication token found in environment variables. See gh help environment for more info.
18+
#To use gh in GitHub Actions, add GH_TOKEN: $ to "env". on Docker run: Docker run -e GH_TOKEN='myPatToken'
19+
gh auth login
20+
21+
#Get Runner registration Token
22+
$jsonObj = gh api --method POST -H "Accept: application/vnd.github.v3+json" "/repos/$owner/$repo/actions/runners/registration-token"
23+
$regToken = (ConvertFrom-Json -InputObject $jsonObj).token
24+
$runnerBaseName = "dockerNode-"
25+
$runnerName = $runnerBaseName + (((New-Guid).Guid).replace("-", "")).substring(0, 5)
26+
27+
try {
28+
#Register new runner instance
29+
write-host "Registering GitHub Self Hosted Runner on: $owner/$repo"
30+
./config.cmd --unattended --url "https://github.com/$owner/$repo" --token $regToken --name $runnerName
31+
32+
#Remove PAT token after registering new instance
33+
$pat=$null
34+
$env:GH_TOKEN=$null
35+
36+
#Start runner listener for jobs
37+
./run.cmd
38+
}
39+
catch {
40+
Write-Error $_.Exception.Message
41+
}
42+
finally {
43+
# Trap signal with finally - cleanup (When docker container is stopped remove runner registration from GitHub)
44+
# Does not currently work due to issue: https://github.com/moby/moby/issues/25982#
45+
# Perform manual cleanup of stale runners using Cleanup-Runners.ps1
46+
./config.cmd remove --unattended --token $regToken
47+
}

0 commit comments

Comments
 (0)