0
votes

I have project in dotnet I would like to containerize in Azure DevOps. I used https://github.com/MicrosoftDocs/mslearn-tailspin-spacegame-web-deploy (and the tutorial: https://docs.microsoft.com/en-us/learn/modules/create-multi-stage-pipeline/6-promote-staging ) as a test. I wanted to keep the original multistage pipeline that contained the DotNetCoreCLI@2 restore, build and publish commands, and I would just want to copy the artifact to the container, pointing at the right dll.

My dockerfile looks like this:

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

Even if I use the /$workdir which is a passed argument in the docker task, it looks for the $workdir within the temporary docker environment:

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

Is there a way to reuse the artifact with Docker without publishing it to Azure Artifacts and downloading it again from the internet?

Here is my artifact publish and Docker task in case of confusion:

    - 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)"'
1

1 Answers

0
votes

When you have COPY instructions in your Dockerfile, the path is relative to the build context. You've not set the build context in your Docker task inputs, so it's defaulting to **, the same directory as your Dockerfile. If the only content you need to copy is contained in $(Build.ArtifactStagingDirectory), then I think you should be able to set that directory as the build context. You'd also need to modify the Dockerfile to not use workdir anymore since it's just contained directly from the build context.

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)'