【问题标题】:Pass artifact to Docker task in Azure DevOps将工件传递给 Azure DevOps 中的 Docker 任务
【发布时间】:2021-02-23 10:14:02
【问题描述】:

我在 dotnet 中有项目,我想在 Azure DevOps 中进行容器化。 我使用https://github.com/MicrosoftDocs/mslearn-tailspin-spacegame-web-deploy(和教程:https://docs.microsoft.com/en-us/learn/modules/create-multi-stage-pipeline/6-promote-staging)作为测试。我想保留包含 DotNetCoreCLI@2 恢复、构建和发布命令的原始多级管道,我只想将工件复制到容器中,并指向正确的 dll。

我的 dockerfile 看起来像这样:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
ARG workdir
COPY /$workdir App/
WORKDIR /App
ENTRYPOINT ["dotnet", "Tailspin.SpaceGame.Web.dll"]

即使我在 docker 任务中使用作为传递参数的 /$workdir,它也会在临时 docker 环境中查找 $workdir:

##[error]COPY failed: stat /var/lib/docker/tmp/docker-builder513641162/home/vsts/work/1/a/Release: no such file or directory

有没有办法通过 Docker 重用工件,而不将其发布到 Azure Artifacts 并从 Internet 再次下载?

这是我的工件发布和 Docker 任务,以防混淆:

    - publish: '$(Build.ArtifactStagingDirectory)'
      artifact: drop

    - task: Docker@2
      inputs:
        containerRegistry: 'ACR Service Connection'
        repository: 'Tailspin.SpaceGame-$(buildConfiguration)'
        command: 'build'
        Dockerfile: '**/Dockerfile'
        arguments: '--build-arg  workdir="$(Build.ArtifactStagingDirectory)/$(buildConfiguration)"'

【问题讨论】:

    标签: .net azure docker devops


    【解决方案1】:

    当您的 Dockerfile 中有 COPY 指令时,路径是相对于构建上下文的。您没有在 Docker 任务输入中设置构建上下文,因此它默认为 **,与 Dockerfile 相同的目录。如果您需要复制的唯一内容包含在$(Build.ArtifactStagingDirectory) 中,那么我认为您应该能够将该目录设置为构建上下文。您还需要修改 Dockerfile 以不再使用 workdir,因为它只是直接包含在构建上下文中。

    FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
    COPY . App/
    WORKDIR /App
    ENTRYPOINT ["dotnet", "Tailspin.SpaceGame.Web.dll"]
    
     - task: Docker@2
          inputs:
            containerRegistry: 'ACR Service Connection'
            repository: 'Tailspin.SpaceGame-$(buildConfiguration)'
            command: 'build'
            Dockerfile: '**/Dockerfile'
            buildContext: '$(Build.ArtifactStagingDirectory)/$(buildConfiguration)'
    

    【讨论】:

      猜你喜欢
      • 2020-04-03
      • 2019-06-29
      • 2020-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-29
      • 2022-06-29
      相关资源
      最近更新 更多