GitHub Self-Hosted Runner inside a container

EDIT (02/03/2021): You can use tmate action inside a Windows runner.

If you are using GitHub Actions, you have four choices for the runner:

  1. Windows Runner
  2. Ubuntu Runner
  3. MacOS Runner (Preview)
  4. Self-Hosted Runner

GitHub Actions for Microsoft Power Platform support only Windows Runner (as of Dec 2020). If you are building some workflows using the GitHub hosted runner, the only way you can troubleshoot the workflow is by using the logs, that can be turned on using the ACTIONS_RUNNER_DEBUG and ACTIONS_STEP_DEBUG environment variables.

You cannot use act or tmate because you are using Windows Runner. One way to work around the jam is to use self-hosted runner, if you are troubleshooting the Action. Rather than configuring the runner on your local machine, what if you could run it inside a container? This way you can run multiple runners on the same machine, all using the same underlying Windows Servercore image.

You need to install the following in your local machine:

  1. Docker Desktop
  2. VSCode
  3. Docker Extension for VSCode

During or after installation of Docker, switch to Windows Container, rather than Linux containers, as we need to use the Windows Servercore image. Now, clone this repo https://github.com/rajyraman/docker-github-self-hosted-runner on your local machine. Next, go to https://github.com/settings/tokens and create a Personal Access Token with repo scope.

Personal Access Token

Once you have the token, you can run the runner-setup PowerShell script to create the environment file for the container that has the repo url where the Actions with self-hosted runner will run, and the personal access token required to connect to the GitHub API.

PowerShell to configure env file

Now run docker-compose up –build and you should see the container being built and started with the GitHub Runner.

Building the container
Actions Runner

You should now be able to see the runner on the repo that you setup the env file for.

Now let us create a new workflow that utilises the self-hosted runner. The key this here is to mention the self-hosted runner on “runs-on”.

Sample Workflow

Since this workflow uses workflow_dispatch trigger, you can run it manually. If you now run the workflow, you should start see the logs appear on the container’s console.

Action Logs

With the latest version of the Docker extension for VSCode, you can also explore the container’s file system, which is quite handy, in case you want to inspect the artifacts produced by the workflow.

Exploring container’s file system

I hope this tip will help you when you are stuck building workflows with Power Platform Actions.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s