简体   繁体   English

在 Docker 中运行的自定义 Azure DevOps 构建代理上安装了卷的测试容器

[英]Testcontainers with volume mounts on custom Azure DevOps build agent running in Docker

I am having trouble running some integration tests that use Testcontainers on a self-managed custom Azure DevOps agent that is already running in Docker.在已经在 Docker 中运行的自我管理的自定义 Azure DevOps 代理上运行一些使用 Testcontainers 的集成测试时遇到问题。

The host is an Ubuntu 20.04 Virtual Machine on Azure.主机是 Azure 上的 Ubuntu 20.04 虚拟机。 It has Docker installed and there are 2 docker images running, one for our Java-based builds and one for the Angular-based builds.它安装了 Docker,并运行了 2 个 docker 镜像,一个用于我们基于 Java 的构建,另一个用于基于 Angular 的构建。 Inside the Java-based one, we run Maven with Testcontainers.在基于 Java 的内部,我们使用 Testcontainers 运行 Maven。

The Docker image that is created for the build agent itself, is based on the documentation at https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/docker?view=azure-devops#linux .为构建代理本身创建的 Docker 映像基于https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/docker?view=azure-devops#linux上的文档。 It runs Ubuntu 18.04, has a WORKDIR /azp and ENTRYPOINT [ "./start.sh" ] .它运行 Ubuntu 18.04,有一个WORKDIR /azpENTRYPOINT [ "./start.sh" ]

The build agent is started manually on the host via:构建代理通过以下方式在主机上手动启动:

docker run -d --name build-agent-java-1 \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -e AZP_URL=https://dev.azure.com/my-organisation \
  -e AZP_TOKEN=<mytoken> \
  -e AZP_AGENT_NAME=agent-1 \ 
  custombuildagentcr.azurecr.io/ubuntu1804-java11

The -v /var/run/docker.sock:/var/run/docker.sock is added following the Testcontainers documentation -v /var/run/docker.sock:/var/run/docker.sockTestcontainers 文档之后添加

This works for some Testcontainers tests, but not for others.这适用于某些 Testcontainers 测试,但不适用于其他测试。 More specially, it does not work for a test where the container started by testcontainers needs access to the compiled class files (which are present on the build agent docker).更特别的是,它不适用于由 testcontainers 启动的容器需要访问已编译的类文件(存在于构建代理 docker 上)的测试。

After searching through a lot of other questions, I believe the problem is that the "inner docker" cannot "see" the files on the "outer docker" (the build agent).在搜索了很多其他问题之后,我认为问题在于“内部 docker”无法“看到”“外部 docker”(构建代理)上的文件。 See Docker volume mounts not working in Azure DevOps Pipeline and Selfhosted Azure DevOps Agents volume mapping请参阅Docker 卷挂载在 Azure DevOps Pipeline自托管 Azure DevOps 代理卷映射中不起作用

However, it is not clear to me how to apply this exactly.但是,我不清楚如何准确地应用它。

I tried to add -v $PWD:$PWD -w $PWD when starting the build agent Docker (Because the Testcontainer documentation indicates this).我尝试在启动构建代理 Docker 时添加-v $PWD:$PWD -w $PWD (因为 Testcontainer 文档表明了这一点)。 However, this makes the image fail to start as ./start.sh as ENTRYPOINT no longer can be resolved as the WORKDIR is changed.但是,这会导致图像无法启动,因为./start.sh因为 ENTRYPOINT 不再可以在 WORKDIR 更改时解析。

I also tried to change the ENTRYPOINT to use an absolute path /azp/start.sh (and also do a cd /azp inside that start.sh file), but that still does not work.我还尝试将 ENTRYPOINT 更改为使用绝对路径/azp/start.sh (并在该start.sh文件中执行cd /azp ),但这仍然不起作用。

If I check the mounts that are available, it returns this:如果我检查可用的安装,它会返回:

devops-agent-host-user@shared-devops-agent-host:~$ docker inspect build-agent-java-1 | jq '.[0].Mounts'
[
  {
    "Type": "bind",
    "Source": "/home/devops-agent-host-user",
    "Destination": "/home/devops-agent-host-user",
    "Mode": "",
    "RW": true,
    "Propagation": "rprivate"
  },
  {
    "Type": "bind",
    "Source": "/var/run/docker.sock",
    "Destination": "/var/run/docker.sock",
    "Mode": "",
    "RW": true,
    "Propagation": "rprivate"
  }
]

Azure itself has Mounting volumes using Docker within a Docker container , but I unfortunately fail to understand how to apply this to my situation. Azure 本身在 Docker 容器中使用 Docker 挂载卷,但不幸的是,我无法理解如何将其应用于我的情况。

我没有通用的解决方案,但是我用testcontainers-keycloak 1.9.0 解决了我的问题,因为它不再使用绑定挂载,而是将类文件复制到容器中(请参阅https://github.com)。 com/dasniko/testcontainers-keycloak/issues/44 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AKS Azure DevOps 构建代理 - AKS Azure DevOps Build Agent 托管代理失败的 Azure DevOps 构建管道 - Azure DevOps build pipeline with hosted agent failing Azure DevOps 托管生成代理 MSI - Azure DevOps Hosted Build Agent MSI 在自托管代理上运行容器作业时 Azure DevOps YAML 构建失败 - Azure DevOps YAML build fail when running container jobs on self hosted agent 作为 NetworkService 运行的自托管 Azure DevOps 代理无法完成 npm install 和 npm build - Selfhosted Azure DevOps Agent running as NetworkService not able to complete npm install and npm build 在 Service Fabric 中运行 Azure DevOps 自托管构建代理时“无法解析远程名称” - “The remote name could not be resolved” when running an Azure DevOps self-hosted build agent in Service Fabric 我可以在Azure虚拟机上安装Azure Devops Build Agent吗? - Can I install Azure Devops Build Agent on Azure Virtual Machine? 通过 Azure DevOps 构建一个加密的 Docker 容器 - Build an encrypted Docker container via Azure DevOps Azure DevOps 自托管构建代理 - Kaniko - Azure DevOps self-hosted build agent - Kaniko Azure DevOps 构建代理在其令牌缓存中没有访问令牌 - Azure DevOps build agent does not have accesstokens in its tokencache
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM