.Net Core ARM Build Agent for Azure Dev Ops

If you want to compile your .Net Core app or build a Docker Image to run on an ARM device, you will need an ARM build agent. There are a few ways to do this, such as using QEMU on Linux to emulate a Raspberry Pi. This is fairly straightforward to do, however does not work well on a Hyper-V virtual machine due to issues with audio.

This solution uses a real Raspberry Pi, and describes how to add it to your Azure Dev Ops build agent pool. The instructions for creating a Linux x86 or x64 build agent are broadly the same, and you can follow these steps but taking care to use the correct downloads for your target architecture.

Install Raspbian

  • Using your Windows or Mac desktop, download the latest Raspbian Lite and extract the zip. NOTE: There is currently a dependency issue with Debian Buster which prevents .Net Core SDK installing, so probably best to stick with Stretch for now.
  • Download Balena Etcher (or your favourite image writing tool)
  • Write the image to a MicroSD card, ideally you'll want one that is 64GB or more, particularly if creating Docker images
  • Put the SD card into your Pi, power it up and you should end up at a login prompt. The default username is 'pi' with password 'raspberry'
  • Update the package list, and upgrade everything


    sudo apt update
    sudo apt upgrade

Initial Configuration

  • Start the config tool


    sudo raspi-config

  • Enable SSH by starting the config utility and going to Interfacing Options → SSH
  • Set the host name to something sensible (e.g. pi-azdo-build) in Network Options → Hostname
  • Change the password by going to Change User Password
  • You can now disconnect the Pi from your monitor and connect via SSH if you prefer using XShell or your other favourite client software.

Install .Net Core SDK

  • Download, unzip and configure the SDK. Go to the .Net Core downloads page and get the URL for the latest Linux ARM 32-bit SDK.


    sudo wget (path to download)
    mkdir -p $HOME/dotnet && tar zxf (filename of download)-linux-arm.tar.gz -C $HOME/dotnet
    sudo nano /etc/profile

  • Add the dotnet folder to your PATH variable. Open the file using the command below and add :$HOME/dotnet on the end.


    sudo nano /etc/profile

Install Build Agent

  • In Azure Dev Ops go to Organization Settings → Pools → New Agent and select 'Linux' / 'ARM'. This will give you the URL for the latest build agent binaries. Create a folder, download the zip file and extract everything. The build agent will require Git to grab the source code, so install that too.


    sudo mkdir /agent
    cd /agent
    sudo wget https://vstsagentpackage.azureedge.net/agent/2.155.1/vsts-agent-linux-arm-2.155.1.tar.gz
    sudo tar zxvf vsts-agent-linux-arm-2.155.1.tar.gz
    sudo apt install git

  • Install agent dependencies


    sudo ./bin/installdependencies.sh

  • Create a Personal Access Token. Go to Azure Dev Ops, click your profile avatar in the top right corner and select 'Azure Dev Ops Profile' Click on Personal Access Tokens on the left hand menu, under 'Security'. Create a token and make a note of it.
  • Configure the agent without sudo. You will be asked for your server url, authentication type (Personal Access Token) and various other things. Mostly the defaults will be fine, unless you have specific requirements.


    ./config.sh

  • Set the agent to run as a service


    sudo ./svc.sh install
    sudo ./svc.sh start

  • A snapshot of salient environment variables is taken by the agent on install. At this point it is usually worth refreshing this snapshot


    ./env.sh
    sudo ./svc.sh stop
    sudo ./svc.sh start

At this point, reboot your Raspberry Pi and when it comes back up you should have a fully functioning ARM build agent available to your Azure Dev Ops instance.

Build ARM Compatible Docker Images

To also build an ARM-compatible Docker image using your new build agent, you will need to install Docker and configure some permissions.

  • Install Docker


    sudo apt install docker

  • To get Docker to work without needing sudo, first a add the docker group if it doesn't already exist, and add the current (Pi) user to it. The final command will make the grouop changes take hold, but you could just as easily log out and back in again.


    sudo groupadd docker
    sudo gpasswd -a $USER docker
    newgrp docker

  • Test that Docker is working correctly by running the following commands. If the first command shows access denied or permissions errors in the second section, this is usually because the commands above have not been run.


    docker version
    docker run hello-world

Your build agent will now be able to create an ARM compatible image. You can actually run an ARM image on your x86 installation of Docker for Desktop on Windows or Mac due to a clever shim that uses QEMU to emulate the ARM architecture - just use 'docker run' in the usual way.