En Azure DevOps estoy tratando de crear un pipeline que haga la build de una imagen docker y suba la imagen a un Azure Container Registry. Concretamente estoy utilizando la task «Docker@2» de Azure DevOps. El problema está en que no me hace la build ya que el log lanza un mensaje de error indicando que no encuentra un archivo en el build context. He probado a agregar la ruta del buildcontext en el yml de esta forma en la task correspondiente pero sigue lanzando el mismo error:
buildContext: 'Services/SiPark.Core.Service.PassValidator/'
DOCKERFILE:
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["Services/SiPark.Core.Service.PassValidator/SiPark.Core.Service.PassValidator.csproj", "Services/SiPark.Core.Service.PassValidator/"]
COPY ["Commons/SiPark.Core.Commons/SiPark.Core.Commons.csproj", "Commons/SiPark.Core.Commons/"]
COPY ["Business/SiPark.Core.Business/SiPark.Core.Business.csproj", "Business/SiPark.Core.Business/"]
COPY ["Infrastructure/SiPark.Core.Infrastructure/SiPark.Core.Infrastructure.csproj", "Infrastructure/SiPark.Core.Infrastructure/"]
COPY ["Entities/SiPark.Core.Entities/SiPark.Core.Entities.csproj", "Entities/SiPark.Core.Entities/"]
RUN dotnet restore "Services/SiPark.Core.Service.PassValidator/SiPark.Core.Service.PassValidator.csproj"
COPY . .
WORKDIR "/src/Services/SiPark.Core.Service.PassValidator"
RUN dotnet build "SiPark.Core.Service.PassValidator.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "SiPark.Core.Service.PassValidator.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "SiPark.Core.Service.PassValidator.dll"]
Dockerignore
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
Archivo yml de la Pipeline:
# Stages
# Stage-1:
# Task-1: Build Docker Image and push to Azure Container Registry ACR
# Task-2: Copy kube-manifest files to Build Artifact Directory
# Task-3: Publish build articats to Azure Pipelines
# Pipeline Hierarchial Flow: Stages -> Stage -> Jobs -> Job -> Steps -> Task1, Task2, Task3
trigger:
- NONE
# Variables
variables:
tag: '$(Build.BuildId)'
stages:
# Build Stage
- stage: Build
displayName: Build Stage
jobs:
- job: Build
displayName: Build Job
pool:
vmImage: 'ubuntu-latest'
steps:
# Task-1: Build Docker Image and push to Azure Container Registry ACR
- task: Docker@2
inputs:
containerRegistry: 'DEV_ACR'
repository: 'passvalidator'
command: 'buildAndPush'
Dockerfile: 'Services/SiPark.Core.Service.PassValidator/Dockerfile'
tags: '$(tag)'
# $(Build.SourceVersion)
# Task-2: Copy kube-manifest files to Build Artifact Directory
# Task-3: Publish build articats to Azure Pipelines
Mensaje de error del Log:
Status: Downloaded newer image for mcr.microsoft.com/dotnet/sdk:3.1
---> e192c0c19af6
Step 6/32 : WORKDIR /src
---> Running in 092be212ebb6
Removing intermediate container 092be212ebb6
---> c58b36916536
Step 7/32 : COPY ["Services/SiPark.Core.Service.PassValidator/SiPark.Core.Service.PassValidator.csproj", "Services/SiPark.Core.Service.PassValidator/"]
COPY failed: file not found in build context or excluded by .dockerignore: stat Services/SiPark.Core.Service.PassValidator/SiPark.Core.Service.PassValidator.csproj: file does not exist
##[error]COPY failed: file not found in build context or excluded by .dockerignore: stat Services/SiPark.Core.Service.PassValidator/SiPark.Core.Service.PassValidator.csproj: file does not exist
##[error]The process '/usr/bin/docker' failed with exit code 1
Finishing: Docker
Directorio de archivos en la repo:
P.D. Si hago la build de esta forma me funciona la build pero me gustaría utilizar la tarea de build and publish anterior:
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- NONE
pool:
vmImage: ubuntu-latest
# Variables
variables:
tag: '$(Build.BuildId)'
steps:
- task: AzureCLI@2
inputs:
azureSubscription: 'DEV_SP'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: 'docker build -f Services/SiPark.Core.Service.PassValidator/Dockerfile .'
addSpnToEnvironment: true
useGlobalConfig: true
#- task: Docker@2
# inputs:
# containerRegistry: 'DEV_ACR'
# repository: 'passvalidator'
# command: 'buildAndPush'
# Dockerfile: 'Services/SiPark.Core.Service.PassValidator/Dockerfile'