From dfeaea32839b4777bd1d85c8ad236b1e10519913 Mon Sep 17 00:00:00 2001 From: Alexandre Pires Date: Fri, 3 Jul 2026 23:56:19 +0200 Subject: [PATCH] Refactor Windows Gitea runner Dockerfiles and update CI configuration --- .../windows-runners/Dockerfile.windows-base | 2 +- .../windows-runners/Dockerfile.windows-cpp | 3 +- .../windows-runners/Dockerfile.windows-dotnet | 3 +- .../windows-runners/Dockerfile.windows-go | 3 +- .../Dockerfile.windows-image-build | 9 +++++ ansible/host_vars/ci-01.lab.alexpires.me.yml | 39 +++++++++++++++++++ .../tasks/runner.yml | 30 +++++++++++++- 7 files changed, 80 insertions(+), 9 deletions(-) create mode 100644 ansible/files/dockerfiles/windows-runners/Dockerfile.windows-image-build diff --git a/ansible/files/dockerfiles/windows-runners/Dockerfile.windows-base b/ansible/files/dockerfiles/windows-runners/Dockerfile.windows-base index fae10ec..204a2d7 100644 --- a/ansible/files/dockerfiles/windows-runners/Dockerfile.windows-base +++ b/ansible/files/dockerfiles/windows-runners/Dockerfile.windows-base @@ -2,7 +2,7 @@ FROM mcr.microsoft.com/windows/servercore:ltsc2022 SHELL ["powershell", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command"] -# Base image for Windows Gitea runners with Git for Windows tools and gitea runner. +# Base image for Windows Gitea runners with Git tools and gitea runner. ARG ACT_RUNNER_VERSION=2.0.0 RUN Set-StrictMode -Version Latest; \ $ErrorActionPreference = 'Stop'; \ diff --git a/ansible/files/dockerfiles/windows-runners/Dockerfile.windows-cpp b/ansible/files/dockerfiles/windows-runners/Dockerfile.windows-cpp index a9e8ba1..b356611 100644 --- a/ansible/files/dockerfiles/windows-runners/Dockerfile.windows-cpp +++ b/ansible/files/dockerfiles/windows-runners/Dockerfile.windows-cpp @@ -5,5 +5,4 @@ SHELL ["powershell", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command"] # C/C++ profile with cmake and ninja. RUN choco feature enable -n allowGlobalConfirmation; \ choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System'; \ - choco install ninja; \ - choco clean --yes + choco install ninja \ No newline at end of file diff --git a/ansible/files/dockerfiles/windows-runners/Dockerfile.windows-dotnet b/ansible/files/dockerfiles/windows-runners/Dockerfile.windows-dotnet index db7d659..c0c44c8 100644 --- a/ansible/files/dockerfiles/windows-runners/Dockerfile.windows-dotnet +++ b/ansible/files/dockerfiles/windows-runners/Dockerfile.windows-dotnet @@ -4,5 +4,4 @@ SHELL ["powershell", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command"] # .NET profile for building and testing managed workloads. RUN choco feature enable -n allowGlobalConfirmation; \ - choco install dotnet-sdk --version=8.0.204; \ - choco clean --yes + choco install dotnet-sdk --version=8.0.204 diff --git a/ansible/files/dockerfiles/windows-runners/Dockerfile.windows-go b/ansible/files/dockerfiles/windows-runners/Dockerfile.windows-go index 2d2ec7c..bd28073 100644 --- a/ansible/files/dockerfiles/windows-runners/Dockerfile.windows-go +++ b/ansible/files/dockerfiles/windows-runners/Dockerfile.windows-go @@ -4,5 +4,4 @@ SHELL ["powershell", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command"] # Go profile for Windows builds. RUN choco feature enable -n allowGlobalConfirmation; \ - choco install golang --version=1.22.4; \ - choco clean --yes + choco install golang --version=1.22.4 \ No newline at end of file diff --git a/ansible/files/dockerfiles/windows-runners/Dockerfile.windows-image-build b/ansible/files/dockerfiles/windows-runners/Dockerfile.windows-image-build new file mode 100644 index 0000000..4c3c1e7 --- /dev/null +++ b/ansible/files/dockerfiles/windows-runners/Dockerfile.windows-image-build @@ -0,0 +1,9 @@ +FROM local/gitea-windows-runner:windows-msys + +SHELL ["powershell", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command"] + +# Dedicated profile for image builds. Docker daemon access is provided at runtime +# through the host named pipe mount configured in host_vars. +RUN Set-StrictMode -Version Latest; \ + $ErrorActionPreference = 'Stop'; \ + choco install docker-cli --yes --no-progress --limit-output diff --git a/ansible/host_vars/ci-01.lab.alexpires.me.yml b/ansible/host_vars/ci-01.lab.alexpires.me.yml index 0b5af9a..a55d044 100644 --- a/ansible/host_vars/ci-01.lab.alexpires.me.yml +++ b/ansible/host_vars/ci-01.lab.alexpires.me.yml @@ -181,3 +181,42 @@ windows_gitea_runner_windows_runners: config_file: "D:\\GiteaRunner\\windows-msys\\config.yaml" data_dir: "D:\\GiteaRunner\\windows-msys\\data" log_dir: "D:\\Logs\\GiteaRunner\\windows-msys" + - profile: windows-cpp + name: "gitea-runner-windows-cpp" + container_name: "gitea-runner-windows-cpp" + image: "local/gitea-windows-runner:windows-cpp" + dockerfile_src: "Dockerfile.windows-cpp" + labels: "windows:host,windows-cpp" + config_file: "D:\\GiteaRunner\\windows-cpp\\config.yaml" + data_dir: "D:\\GiteaRunner\\windows-cpp\\data" + log_dir: "D:\\Logs\\GiteaRunner\\windows-cpp" + - profile: windows-go + name: "gitea-runner-windows-go" + container_name: "gitea-runner-windows-go" + image: "local/gitea-windows-runner:windows-go" + dockerfile_src: "Dockerfile.windows-go" + labels: "windows:host,windows-go" + config_file: "D:\\GiteaRunner\\windows-go\\config.yaml" + data_dir: "D:\\GiteaRunner\\windows-go\\data" + log_dir: "D:\\Logs\\GiteaRunner\\windows-go" + - profile: windows-dotnet + name: "gitea-runner-windows-dotnet" + container_name: "gitea-runner-windows-dotnet" + image: "local/gitea-windows-runner:windows-dotnet" + dockerfile_src: "Dockerfile.windows-dotnet" + labels: "windows:host,windows-dotnet" + config_file: "D:\\GiteaRunner\\windows-dotnet\\config.yaml" + data_dir: "D:\\GiteaRunner\\windows-dotnet\\data" + log_dir: "D:\\Logs\\GiteaRunner\\windows-dotnet" + - profile: windows-image-build + name: "gitea-runner-windows-image-build" + container_name: "gitea-runner-windows-image-build" + image: "local/gitea-windows-runner:windows-image-build" + dockerfile_src: "Dockerfile.windows-image-build" + labels: "windows:host,windows-image-build" + config_file: "D:\\GiteaRunner\\windows-image-build\\config.yaml" + data_dir: "D:\\GiteaRunner\\windows-image-build\\data" + log_dir: "D:\\Logs\\GiteaRunner\\windows-image-build" + run_args: + - "-v" + - "\\\\.\\pipe\\docker_engine:\\\\.\\pipe\\docker_engine" diff --git a/ansible/roles/windows_gitea_runner_windows/tasks/runner.yml b/ansible/roles/windows_gitea_runner_windows/tasks/runner.yml index 4c1a15c..0ef6eff 100644 --- a/ansible/roles/windows_gitea_runner_windows/tasks/runner.yml +++ b/ansible/roles/windows_gitea_runner_windows/tasks/runner.yml @@ -311,6 +311,19 @@ $ErrorActionPreference = "Stop" $docker = "{{ windows_gitea_runner_windows_runtime_bin }}" $name = "{{ __windows_gitea_runner_windows_container_name }}" + $runArgsJson = '{{ __windows_gitea_runner_windows_run_args | to_json }}' + $runArgs = @() + if (-not [string]::IsNullOrWhiteSpace($runArgsJson)) { + $parsedRunArgs = $runArgsJson | ConvertFrom-Json + if ($null -ne $parsedRunArgs) { + if ($parsedRunArgs -is [System.Array]) { + $runArgs = @($parsedRunArgs) + } + else { + $runArgs = @($parsedRunArgs) + } + } + } if (Get-Variable -Name PSNativeCommandUseErrorActionPreference -ErrorAction SilentlyContinue) { $PSNativeCommandUseErrorActionPreference = $false } @@ -331,7 +344,7 @@ $env:GITEA_RUNNER_LABELS = {{ __windows_gitea_runner_windows_labels | to_json }} & $docker run -d --name $name --restart "{{ windows_gitea_runner_windows_restart_policy }}" ` - @({{ __windows_gitea_runner_windows_run_args | map('to_json') | join(', ') }}) ` + @($runArgs) ` --label "{{ windows_gitea_runner_windows_container_hash_label }}={{ __windows_gitea_runner_windows_desired_container_hash }}" ` @@ -364,6 +377,19 @@ $image = "{{ __windows_gitea_runner_windows_image }}" $hostData = "{{ __windows_gitea_runner_windows_data_dir }}" $hostConfig = "{{ __windows_gitea_runner_windows_runtime_config_file }}" + $runArgsJson = '{{ __windows_gitea_runner_windows_run_args | to_json }}' + $runArgs = @() + if (-not [string]::IsNullOrWhiteSpace($runArgsJson)) { + $parsedRunArgs = $runArgsJson | ConvertFrom-Json + if ($null -ne $parsedRunArgs) { + if ($parsedRunArgs -is [System.Array]) { + $runArgs = @($parsedRunArgs) + } + else { + $runArgs = @($parsedRunArgs) + } + } + } if (Get-Variable -Name PSNativeCommandUseErrorActionPreference -ErrorAction SilentlyContinue) { $PSNativeCommandUseErrorActionPreference = $false @@ -399,7 +425,7 @@ $diagName = "$name-diag-$([guid]::NewGuid().ToString('N').Substring(0, 8))" $diagRun = & $docker run --rm --name $diagName ` --entrypoint "C:\Windows\System32\cmd.exe" ` - @({{ __windows_gitea_runner_windows_run_args | map('to_json') | join(', ') }}) ` + @($runArgs) ` --mount "type=bind,source={{ __windows_gitea_runner_windows_data_dir }},target=C:\runner-data" ` -e "CONFIG_FILE=C:\runner-data\config.yaml" ` -e "GITEA_INSTANCE_URL={{ windows_gitea_runner_windows_instance_url }}" `