Skip to content

fok666/azure-devops-agent

Repository files navigation

azure-devops-agent

Azure DevOps Self-Hosted Linux Agent. General purpose Docker image with pre-installed tools.

CodeQL Dependabot Updates Docker Image CI

Goals:

  • Run anywhere
  • Auto scalable
  • Self-configurable
  • Feature rich
  • Customizable

Features

Bundled tools:

Build configuration

Multi-Stage Build Architecture

This project uses a multi-stage Docker build optimized for maximum layer reusability across different profiles. This architecture significantly improves build times and reduces cache storage requirements:

  • 40-60% cache improvement on shared base layers
  • 25-35% faster build times for subsequent builds
  • 55% reduction in build cache storage
  • NO increase in final image sizes

For technical details, see ARCHITECTURE.md.

Building Custom Images

To build a specific profile:

# Build minimal profile
docker build --target minimal -t azure-devops-agent:minimal .

# Build full profile  
docker build --target full -t azure-devops-agent:full .

# Build for specific architecture
docker buildx build --platform linux/amd64 --target full -t azure-devops-agent:full-amd64 .

Available Profiles

Pre-configured profiles are available for different use cases. Each profile is built as a separate Docker stage, allowing for optimal layer sharing and caching:

Profile Size Description Included Tools
minimal ~550 MB Lightweight profile with essential tools only Azure DevOps Agent, sudo
k8s ~850 MB Kubernetes-focused profile + Docker, kubectl, kubelogin, kustomize, Helm, jq, yq
iac ~1.75 GB Infrastructure as Code profile with bash-based tools + Docker, Azure CLI, AWS CLI, Terraform, OpenTofu, Terraspace, jq, yq
iac-pwsh ~2.25 GB Infrastructure as Code profile with PowerShell support + PowerShell (with Azure & AWS modules)
full ~2.45 GB Complete toolset with all available tools All tools from k8s + iac-pwsh profiles

Using Profiles

Pull a specific profile from the registry:

# Pull full profile (default)
docker pull ghcr.io/fok666/azure-devops-agent:latest-full

# Pull minimal profile
docker pull ghcr.io/fok666/azure-devops-agent:latest-minimal

# Pull k8s profile
docker pull ghcr.io/fok666/azure-devops-agent:latest-k8s

References

Azure Pipelines Agent

https://github.com/Microsoft/azure-pipelines-agent/

Docker Hub images

https://hub.docker.com/r/fok666/azuredevops

Azure DevOps Self-Hosted Reference

https://docs.microsoft.com/azure/devops/pipelines/agents/docker?view=azure-devops

Running

This agent is intended to run on virtual machines.
To be able to build Docker images with the agent, docker must be installed on the host and allowed to run in privileged mode.

# Docker install:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update -y
sudo apt-get install -y docker-ce docker-ce-cli containerd.io

# Docker startup:
sudo systemctl start docker
sudo systemctl enable docker

# Get the agent management scripts and make them executable:
sudo curl -sO https://raw.githubusercontent.com/fok666/azure-devops-agent/main/run.sh
sudo curl -sO https://raw.githubusercontent.com/fok666/azure-devops-agent/main/stop.sh
sudo curl -sO https://raw.githubusercontent.com/fok666/azure-devops-agent/main/vmss_monitor.sh
sudo curl -sO https://raw.githubusercontent.com/fok666/azure-devops-agent/main/ec2_monitor.sh
sudo chmod +x *.sh

# Set the parameters from Azure DevOps:
export AZP_URL="https://dev.azure.com/YOUR_ORG"
export AZP_TOKEN="xxxxxxxxxxxxxxxxxxxxxxxxxxx"
export AZP_POOL="YourLinuxAgentPool"

# Start the agents in privileged mode, one agent for each vCPU (default), using the parameters above:
sudo ./run.sh fok666/azuredevops:latest $AZP_URL $AZP_TOKEN $AZP_POOL

# Or specify a custom number of agents (e.g., 4 agents):
sudo ./run.sh fok666/azuredevops:latest $AZP_URL $AZP_TOKEN $AZP_POOL 4

Cloud Provider Support

This project supports graceful shutdown for multiple cloud providers:

Azure VMSS (Virtual Machine Scale Sets)

AWS EC2 Spot Instances

Setup

# Copy stop script to /opt for monitor scripts to use:
sudo cp stop.sh /opt/stop.sh
sudo chmod +x /opt/stop.sh

# For Azure VMSS - check every minute:
(crontab -l 2>/dev/null; echo "* * * * * /opt/vmss_monitor.sh >> /var/log/vmss_monitor.log 2>&1") | crontab -

# For AWS EC2 Spot - check every 5 seconds:
(crontab -l 2>/dev/null; echo "* * * * * /opt/ec2_monitor.sh >> /var/log/ec2_monitor.log 2>&1") | crontab -
(crontab -l 2>/dev/null; echo "* * * * * sleep 5; /opt/ec2_monitor.sh >> /var/log/ec2_monitor.log 2>&1") | crontab -
(crontab -l 2>/dev/null; echo "* * * * * sleep 10; /opt/ec2_monitor.sh >> /var/log/ec2_monitor.log 2>&1") | crontab -
(crontab -l 2>/dev/null; echo "* * * * * sleep 15; /opt/ec2_monitor.sh >> /var/log/ec2_monitor.log 2>&1") | crontab -

Both monitor scripts require curl and jq to be installed.

TO DO

  • Add Google Compute Cloud (GCP) CLI bundles
  • Add GKE auth support

About

Azure Dev Ops Self-Hosted Linux Agent

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors 3

  •  
  •  
  •