diff --git a/.github/actions/setup-docker-environment/action.yaml b/.github/actions/setup-docker-environment/action.yaml index 2418fdd4dc..53f2de4bbe 100644 --- a/.github/actions/setup-docker-environment/action.yaml +++ b/.github/actions/setup-docker-environment/action.yaml @@ -13,6 +13,10 @@ inputs: ghcr_password: description: "GHCR password. Usually set from the secrets.GITHUB_TOKEN variable" required: true + platform: + description: "Platform (either linux or windows)." + default: linux + required: false runs: using: "composite" @@ -24,9 +28,11 @@ runs: shell: bash - name: Set up QEMU + if: inputs.platform == 'linux' uses: docker/setup-qemu-action@v2 - name: Set up Docker Buildx + if: inputs.platform == 'linux' uses: docker/setup-buildx-action@v2 with: version: latest diff --git a/.github/workflows/runners.yaml b/.github/workflows/runners.yaml index 91f1c3143f..29fdc7be20 100644 --- a/.github/workflows/runners.yaml +++ b/.github/workflows/runners.yaml @@ -83,3 +83,51 @@ jobs: ghcr.io/${{ github.repository }}/${{ matrix.name }}:v${{ env.RUNNER_VERSION }}-${{ matrix.os-name }}-${{ matrix.os-version }}-${{ env.sha_short }} cache-from: type=gha,scope=build-${{ matrix.name }} cache-to: type=gha,mode=max,scope=build-${{ matrix.name }} + + build-runners-win2019: + name: Build ${{ matrix.name }}-${{ matrix.os-name }}-${{ matrix.os-version }} + runs-on: windows-2019 + permissions: + packages: write + contents: read + strategy: + fail-fast: false + matrix: + include: + - name: actions-runner-windows + os-name: win + os-version: 2019 + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup Docker Environment + id: vars + uses: ./.github/actions/setup-docker-environment + with: + username: ${{ env.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKER_ACCESS_TOKEN }} + ghcr_username: ${{ github.actor }} + ghcr_password: ${{ secrets.GITHUB_TOKEN }} + platform: windows + - name: Build + shell: bash + run: | + cd runner + docker build --build-arg RUNNER_VERSION=${{ env.RUNNER_VERSION }} -t ${{ matrix.name }} -f ${{ matrix.name }}.dockerfile . + - name: Tag and Push + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} + shell: bash + run: | + tags=( \ + "${{ env.DOCKERHUB_USERNAME }}/${{ matrix.name }}:v${{ env.RUNNER_VERSION }}-${{ matrix.os-name }}-${{ matrix.os-version }}" \ + "${{ env.DOCKERHUB_USERNAME }}/${{ matrix.name }}:v${{ env.RUNNER_VERSION }}-${{ matrix.os-name }}-${{ matrix.os-version }}-${{ env.sha_short }}" \ + "${{ env.DOCKERHUB_USERNAME }}/${{ matrix.name }}:latest" \ + "ghcr.io/${{ github.repository }}/${{ matrix.name }}:latest" \ + "ghcr.io/${{ github.repository }}/${{ matrix.name }}:v${{ env.RUNNER_VERSION }}-${{ matrix.os-name }}-${{ matrix.os-version }}" \ + "ghcr.io/${{ github.repository }}/${{ matrix.name }}:v${{ env.RUNNER_VERSION }}-${{ matrix.os-name }}-${{ matrix.os-version }}-${{ env.sha_short }}" \ + ) + + for tag in "${tags[@]}" ; do + docker tag ${{ matrix.name }}:latest "$tag" + docker push "$tag" + done diff --git a/runner/Makefile b/runner/Makefile index 930caf5592..3492d5b544 100644 --- a/runner/Makefile +++ b/runner/Makefile @@ -1,6 +1,7 @@ DOCKER_USER ?= summerwind DOCKER ?= docker NAME ?= ${DOCKER_USER}/actions-runner +WIN_RUNNER_NAME ?= ${DOCKER_USER}/actions-runner-windows DIND_RUNNER_NAME ?= ${DOCKER_USER}/actions-runner-dind TAG ?= latest TARGETPLATFORM ?= $(shell arch) @@ -65,3 +66,13 @@ docker-buildx-ubuntu: -f actions-runner-dind.dockerfile \ -t "${DIND_RUNNER_NAME}:${TAG}" \ . ${PUSH_ARG} + + +docker-build-windows: + ${DOCKER} build \ + --build-arg RUNNER_VERSION=${RUNNER_VERSION} \ + -f actions-runner-windows.dockerfile \ + -t ${WIN_RUNNER_NAME}:${TAG} . + +docker-push-windows: + ${DOCKER} push ${WIN_RUNNER_NAME}:${TAG} diff --git a/runner/actions-runner-windows.dockerfile b/runner/actions-runner-windows.dockerfile new file mode 100644 index 0000000000..11588962c7 --- /dev/null +++ b/runner/actions-runner-windows.dockerfile @@ -0,0 +1,20 @@ +FROM mcr.microsoft.com/windows/servercore:ltsc2019 + +SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';$ProgressPreference='silentlyContinue';"] + +ARG RUNNER_VERSION=2.298.2 + +RUN Invoke-WebRequest \ + -Uri 'https://aka.ms/install-powershell.ps1' \ + -OutFile install-powershell.ps1; \ + powershell -ExecutionPolicy Unrestricted -File ./install-powershell.ps1 -AddToPath + +RUN Invoke-WebRequest \ + -Uri https://github.com/actions/runner/releases/download/v$env:RUNNER_VERSION/actions-runner-win-x64-$env:RUNNER_VERSION.zip \ + -OutFile runner.zip; \ + Expand-Archive -Path C:/runner.zip -DestinationPath C:/actions-runner; \ + Remove-Item -Path C:\runner.zip; \ + setx /M PATH $(${Env:PATH} + \";${Env:ProgramFiles}\Git\bin\") + +ADD runner.ps1 C:/runner.ps1 +CMD ["pwsh", "-ExecutionPolicy", "Unrestricted", "-File", ".\\runner.ps1"] diff --git a/runner/runner.ps1 b/runner/runner.ps1 new file mode 100644 index 0000000000..1d30fd38ee --- /dev/null +++ b/runner/runner.ps1 @@ -0,0 +1,2 @@ +.\actions-runner\config.cmd --unattended --replace --url https://github.com/${env:RUNNER_REPO} --token $env:RUNNER_TOKEN --name $env:RUNNER_NAME --work $env:RUNNER_WORKDIR; +.\actions-runner\run.cmd;