Om met Azure DevOps te automatiseren is het handig om je eigen agents te hosten, hierdoor heb je volledig controle over welke tooling en software je wil gebruiken in je agent. Hieronder staat beschreven hoe ik mijn eigen DevOps agent maak. Dit heb ik gedaan met behulp van de referentie documentatie van Microsoft
# syntax=docker/dockerfile:1FROMubuntu:22.04ENVTARGETARCH="linux-x64"ARGPSVERSION="7.5.3"ARGOSVERSION="jammy"ARGOSNUMBER="22.04"ARGTARGETARCH
# set timezone prerequisitesRUNln-fs/usr/share/zoneinfo/Europe/Amsterdam/etc/localtime
# install prerequisites and toolsRUNaptupdate&&aptupgrade-y&&aptinstall-y--no-install-recommendstzdata&&aptinstall-ywgetcurlca-certificatesgpggitjqlibicu70apt-transport-httpsgnupg
# docker repo keysRUNinstall-m0755-d/etc/apt/keyrings
RUNcurl-fsSLhttps://download.docker.com/linux/ubuntu/gpg-o/etc/apt/keyrings/docker.asc
RUNchmoda+r/etc/apt/keyrings/docker.asc
# google-kubernetes keysRUNcurl-fsSLhttps://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key|gpg--dearmor-o/etc/apt/keyrings/kubernetes-apt-keyring.gpg
RUNchmod644/etc/apt/keyrings/kubernetes-apt-keyring.gpg
# Add the docker repository to Apt sources:RUNecho"deb [arch=$(dpkg--print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(./etc/os-release&&echo"${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable"|tee/etc/apt/sources.list.d/docker.list
# Add the kubernetes repository to Apt sourcesRUNecho'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.30/deb/ /'|tee/etc/apt/sources.list.d/kubernetes.list&&chmod644/etc/apt/sources.list.d/kubernetes.list
#create directoriesRUNmkdir/downloads&&mkdir/scripts&&\mkdir/data&&\mkdir/logs&&\mkdir/azp&&\mkdir/client&&\mkdir/.dotnet&&\mkdir-p/opt/microsoft/powershell/7&&\mkdir-p/etc/apt/keyrings&&\mkdir/root/.docker
# install needed binaries and toolsRUNaptupdate&&\aptinstall-yapt-transport-https\software-properties-common\apt-utils\ca-certificates\iputils-ping\libcurl4\libunwind8\netcat\libssl-dev\mono-complete\nuget\zip\python3\python-is-python3\graphviz\pip\dotnet-sdk-6.0\libc6\liblttng-ust1\zlib1g\docker-ce\docker-ce-cli\containerd.io\docker-buildx-plugin\docker-compose-plugin\kubectl&&\apt-getautoclean
# Run pip installs for Python packagesRUNpipinstall\mkdocs\mkdocs-awesome-pages-plugin\mkdocs-bootstrap386\mkdocs-cinder\mkdocs-diagrams\mkdocs-ivory\mkdocs-material\mkdocs-material-extensions\mkdocs-static-i18n\mkdocs-include-markdown-plugin\mkdocstrings
# copy predefined configsCOPYkube.config/root/.kube/config
COPYjarvis/root/.docker/buildx/instances/jarvis
#run specific setup script# This script will install PowerShell and Bicep based on the architectureCOPYsetup.sh/setup.sh
RUNchmod+x/setup.sh
RUN/setup.sh$TARGETARCH$PSVERSIONRUNchmod+x/opt/microsoft/powershell/7/pwsh&&\chmod+x./bicep&&mv./bicep/usr/local/bin/bicep
RUNln-s/opt/microsoft/powershell/7/pwsh/usr/bin/pwsh
# Install Azure CLIRUNcurl-sLhttps://aka.ms/InstallAzureCLIDeb|bash
WORKDIR/azp/COPY./start.sh./
RUNchmod+x./start.sh
#Expose volumes for data, scripts, logs, and PowerShell modules# The volumes are used to persist data, scripts, logs, and PowerShell modules across containersVOLUME/dataVOLUME/scriptsVOLUME/logsVOLUME/root/.local/share/powershell/ModulesENVPATH="$PATH:/.dotnet"# Create agent user and set up home directoryRUNuseradd-m-d/home/agentagent
COPYkube.config/home/agent/.kube/config
COPYjarvis/home/agent/.docker/buildx/instances/jarvis
RUNchown-Ragent:agent/azp/home/agent
USERagent# Another option is to run the agent as root.# ENV AGENT_ALLOW_RUNASROOT="true"ENTRYPOINT["./start.sh"]