diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..1292985 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,31 @@ +name: Publish + +on: [release] + +jobs: + publish: + runs-on: windows-latest + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and push + uses: docker/build-push-action@v6 + with: + push: true + tags: tiobesoftware/github-runner-windows:${{ github.ref }} + build-args: | + SERVERCORE_VERSION="ltsc2022" + RUNNER_VERSION="${{ github.ref }}" + - name: Build and push + uses: docker/build-push-action@v6 + with: + push: true + tags: tiobesoftware/github-runner-windows:${{ github.ref }}-20H2 + build-args: | + SERVERCORE_VERSION="20H2" + RUNNER_VERSION="${{ github.ref }}" diff --git a/Dockerfile b/Dockerfile index 5248439..1f1565e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ -FROM mcr.microsoft.com/windows/servercore:ltsc2022 +ARG SERVERCORE_VERSION="ltsc2022" +ARG RUNNER_VERSION="2.319.1" -ARG RUNNER_VERSION="2.311.0" +FROM mcr.microsoft.com/windows/servercore:${SERVERCORE_VERSION} SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"] @@ -15,6 +16,7 @@ RUN choco install -y \ git \ gh \ powershell-core \ + docker-cli \ python RUN choco install -y visualstudio2022buildtools --package-parameters \" \ diff --git a/README.md b/README.md index 9505fed..9fbf511 100644 --- a/README.md +++ b/README.md @@ -4,19 +4,21 @@ This repository is a Windows version of the [myoung34/docker-github-actions-runn 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. +The build images can be found on [Docker Hub](https://hub.docker.com/r/tiobesoftware/github-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. | \ No newline at end of file +| 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. | diff --git a/entrypoint.ps1 b/entrypoint.ps1 index 8bfe912..9d93fe9 100644 --- a/entrypoint.ps1 +++ b/entrypoint.ps1 @@ -88,7 +88,7 @@ if ($null -ne $TOKEN_URL) { $RUNNER_TOKEN = ((Invoke-WebRequest -Uri $TOKEN_URL -Method "POST" -Headers $HEADERS).Content | ConvertFrom-Json).token } catch { - Write-Error "Cannot obtain the token => $_.Exception.Message" + Write-Error "Cannot obtain the token => $_" exit } } diff --git a/install-runner.ps1 b/install-runner.ps1 index fa0652a..ef28a81 100644 --- a/install-runner.ps1 +++ b/install-runner.ps1 @@ -1,3 +1,2 @@ -# (New-Object System.Net.WebClient).DownloadFile("https://github.com/actions/runner/releases/download/v$env:RUNNER_VERSION/actions-runner-win-x64-$env:RUNNER_VERSION.zip","actions-runner.zip") 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 '.' \ No newline at end of file