Home > OS >  Azure Devops pipelines and multiple project docker
Azure Devops pipelines and multiple project docker

Time:08-30

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)

CodePudding user response:

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.

  • Related