Aller au contenu principal

Azure DevOps Self-Host Agent

Deploy a self-host agent on my Proxmox server:

  • Create an LXC with Docker
  • Update system and install common tools
  • Install .Net SDK
  • Create agent user
  • Install and configure agent
  • Start agent as a service
  • Optimize Docker cache
  • Fill image cache
  • Install .Net tools

Create LXC

Using Proxmox VE Helper-Scripts, create a LXC with Debian/Docker:

  • CPU: 4 cores
  • Memory: 4096 Mo
  • Swap: 2048 Mo

Update system

apt-get update && apt-get upgrade -y

apt-get install -y \
curl \
wget \
git \
unzip \
apt-transport-https \
ca-certificates \
gnupg \
lsb-release \
software-properties-common

Install .Net SDK

# Add Microsoft repository
wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb

# Install .NET SDK
apt-get update
apt-get install -y dotnet-sdk-9.0

# Check
dotnet --version

Create agent user

# Create user for agent
useradd -m -s /bin/bash azureuser
usermod -aG docker azureuser
usermod -aG sudo azureuser

# Config passwordless sudo for the agent (optionnel)
echo "azureuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/azureuser

# Check
su - azureuser
whoami # Must display : azureuser
docker ps # Check if all permission is OK
exit

Install and configure agent

# Switch to azureuser
su - azureuser

# Create agent folder
mkdir ~/azagent && cd ~/azagent

# Download the agent (current version: 4.258.1)
wget https://download.agent.dev.azure.com/agent/4.258.1/vsts-agent-linux-x64-4.258.1.tar.gz

# Extract
tar zxvf vsts-agent-linux-x64-4.258.1.tar.gz
rm vsts-agent-linux-x64-4.258.1.tar.gz

# Check
ls -la

# Configure
./config.sh

# Answer to the prompts :
# Server URL: https://dev.azure.com/YOUR-NAME
# Authentication type: PAT
# Personal access token: VOTRE_PAT_TOKEN (created on DevOps portal)
# Agent pool: (name of the pool created on DevOps portal)
# Agent name: (by default, it's the hostname of the LXC)
# Work folder: (default value: _work)

Start agent as a service

# Retour en root pour installer le service
exit # Sortir de azureuser
cd /home/azureuser/azagent

# Installation du service
sudo ./svc.sh install azureuser

# Démarrage du service
sudo ./svc.sh start

# Vérification du service
sudo ./svc.sh status

Optimize Docker cache

# Docker configuiration for optimal cache
cat > /etc/docker/daemon.json << 'EOF'
{
"storage-driver": "overlay2",
"max-concurrent-downloads": 10,
"max-concurrent-uploads": 5,
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "3"
},
"registry-mirrors": []
}
EOF

systemctl restart docker

Fill image cache

docker pull mcr.microsoft.com/dotnet/sdk:9.0
docker pull mcr.microsoft.com/dotnet/aspnet:9.0
docker pull mcr.microsoft.com/dotnet/aspnet:9.0-alpine

docker pull alpine:latest
docker pull ubuntu:22.04
docker pull ubuntu:24.04

Install .Net tools

su - azureuser -c 'dotnet tool install --global dotnet-ef'
su - azureuser -c 'dotnet tool install --global dotnet-sonarscanner'
su - azureuser -c 'dotnet tool install --global dotnet-reportgenerator-globaltool'

# Check
su - azureuser -c 'dotnet tool list --global'