1

I'm giving my first steps in DevOps.

SCENARIO

I've setup a very simple/silly example app. As you can see in the picture, the solution contains 4 .net core APIS with it's Dockerfile and at the solution level there is a docker-compose.yml file. All of dockerfiles and docker-compose files were added using the visual studio for mac ide.

My goal is publish each image to the Azure Container Registry (ACR) using Azure Devops Pipelines.

overview

THE CODE

the source code can be found at this repo

THE PROBLEM

In my local dev environment everything works great, if I type docker compose up I can play around with all of the APIs.

The problem arise when running my azure devops pipeline I'm receiving

COPY failed: file not found in build context or excluded by .dockerignore: stat Services/AdditionAPI/AdditionAPI.csproj: file does not exist

I've notice many devs face this problem but I don't understand the correct way to solve it since I would like to keep my local dev env integrated with the IDE and easy to debug, and of course, pipelines for building and releasing.

I would really appreciate if a kind soul could take some minutes to explain the solution and its point of view.

Thanks all in advance.

TROUBLE SHOOTING

1- I've added as suggested in line 16

 dockerfilePath: $(Build.SourcesDirectory)/src/Services/AdditionAPI/Dockerfile'

2- I've added an extra step to see the folder structure of the agent

- task: CmdLine@2
  inputs:
    script: |         
      echo "Build.ArtifactStagingDirectory:" 
      
      echo "$(Build.ArtifactStagingDirectory)"
      
      echo "Build.BinariesDirectory:" 
      
      echo "$(Build.BinariesDirectory)"
      
      echo "Build.SourcesDirectory:"
      
      echo "$(Build.SourcesDirectory)"

       echo "Structure of work folder of this pipeline:"
      tree $(Agent.WorkFolder)

3- I've received this error

##[error]COPY failed: file not found in build context or excluded by .dockerignore: stat Services/AdditionAPI/AdditionAPI.csproj: file does not exist
> COPY failed: file not found in build context or excluded by

.dockerignore: stat Services/AdditionAPI/AdditionAPI.csproj: file does not exist

4- And the folder structure is

/home/vsts/work
├── 1
│   ├── TestResults
│   ├── a
│   ├── b
│   └── s
│       ├── DockerCompose.yml
│       ├── LICENSE
│       ├── README.md
│       ├── img
│       │   └── overview.png
│       ├── pipelines
│       │   ├── DockerCompose.yml
│       │   └── SubstractionApiImg.yml
│       └── src
│           ├── ClientGateway
│           │   ├── ClientGateway.csproj
│           │   ├── Ocelot.json
│           │   ├── Program.cs
│           │   ├── Properties
│           │   │   └── launchSettings.json
│           │   ├── appsettings.Development.json
│           │   ├── appsettings.json
│           │   └── web.config
│           ├── Services
│           │   ├── AdditionAPI
│           │   │   ├── AdditionAPI.csproj
│           │   │   ├── Commands
│           │   │   │   └── AdditionCommand.cs
│           │   │   ├── Controllers
│           │   │   │   └── IntegerOperationController.cs
│           │   │   ├── Dockerfile

As we can see Dockerfile is there...

  1. This is the current Docker action:

- task: Docker@2
      displayName: Build and push an image to container registry
      inputs:
        command: buildAndPush
        repository: $(imageRepository)
        dockerfile: src/Services/AdditionAPI/Dockerfile
        buildContext: $(Build.SourcesDirectory)/src/Services/AdditionAPI
        containerRegistry: $(dockerRegistryServiceConnection)
        tags: |
          $(tag)

1
  • 1
    Please don't include links to assets, include the actual text. This question will not be useful to future visitors if you remove the repository in the future. Commented Aug 27, 2022 at 17:31

1 Answer 1

0

You need to provide the buildContext parameter to ensure that your docker build command is running out of the correct subdirectory. The root of the cloned repo will be in the $(Build.SourcesDirectory) system variable. Proceed from there. Something like $(Build.SourcesDirectory)/src/Services/AdditionAPI will probably work.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for your answer @Daniel Mann, I've changed line 16 of the pipeline to dockerfilePath: $(Build.SourcesDirectory)/src/Services/AdditionAPI/Dockerfile' but it seems not to ben finding the Dockerfile. Notice the new step I've added to see the folder structure of the agent.
@HoracioValdez I didn't recommend that you change the dockerFilePath parameter. That was fine. I recommended that you set the buildContext parameter.
Same error... I pasted the piepline code into the the point #5 of troubleshooting. Any suggestion? Thanks
Your dockerfile is looking for the path Services/AdditionAPI/AdditionAPI.csproj. So your build context should be $(Build.SourcesDirectory)/src/.
That was the key, the path in dockerfile! thanks you for taking the time to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.