0

This post describes how to create docker hosted devops build agent. The only change I made was for the Dockerfile to use FROM mcr.microsoft.com/dotnet/sdk:7.0 as the base image rather than vanilla ubuntu.

I've run through this and it works great to build a dotnet console app, using a container running in Azure container apps. However, if I use the same agent for a devops pipeline that builds an Azure Function app, I get the following error:

[error]/home/agentuser/.nuget/packages/microsoft.net.sdk.functions/4.1.1/build/Microsoft.NET.Sdk.Functions.Build.targets(32,5): Error : You must install or update .NET to run this application.

I guess this is because there are SDKs missing from the base image.

This blog post describes how "packer" can be used to create a VHD with the required dependencies. Has anyone followed something similar to create an agent running in a docker container rather than a VM?

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
Rob Bowman
  • 7,632
  • 22
  • 93
  • 200
  • You can just install the missing sdk during your pipeline, no? – Shayki Abramczyk Jul 15 '23 at 17:55
  • Packer is a tool for building out virtual machine base images, it has no relationship with Docker and wouldn't make sense to use in conjunction with Docker. They are both tools for including instructions for how to build out an environment, except one is a VM image and the other is a container image. The issue here isn't that you're using the wrong tool, it's that you're using the right tool incorrectly. You're missing some dependencies in your Docker image, probably the Azure Functions SDK or something similar. – Daniel Mann Jul 16 '23 at 02:09
  • @DanielMann I think you've answered my question, thank you. Shayki, I think that may be possible but I guess there could be a long list of dependencies. One of the reasons for the question was to determine if anyone has already solved the problem of building many types of Azure paas components (including Azure functions) with a self-hosted DevOps agent running in docker. – Rob Bowman Jul 16 '23 at 07:11

1 Answers1

0

My advice is to refer to the official Microsoft documentation about using a Azure Agent in a docker container; it's very clear and simply.

We are using a Azure Hosted Agent as container agent in a on premise VM. As explained by docs you need to create a folder, copy the Dockerfile and script file (start.sh file) and start the container directly with docker run and the necessary variables.

If you want to simplify the startup of one or more agents you can create a docker-compose.yaml file:

version: "3.9"

services:

  azure-agent:
    build:
      context: yourfolder
      dockerfile: Dockerfile
    container_name: azure-agent
    restart: always
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - AZP_URL=https://dev.azure.com/ourcompany
      - AZP_TOKEN=yourlongtoken
      - AZP_AGENT_NAME=My Docker Agent
      - AZP_POOL=Company Agent

and then simply start it docker compose -f ./docker-compose.yml up -d.

In this docker-compose.yaml file the tricky part is the

volumes:
      - /var/run/docker.sock:/var/run/docker.sock

that permits you also to deploy your pipeline built apps in the same docker instance as docker containers. But keep in mind that

Doing this has serious security implications. The code inside the container can now run as root on your Docker host.

E.Benedos
  • 1,585
  • 14
  • 41