我在docker / azure DevOps构建管道中是全新的。但是我不得不承认,这是一条痛苦的道路。这似乎很简单,但不是:)
我要实现的是只构建一个项目,该解决方案中有一个引用的项目。但是我不想构建整个解决方案(因为我有Xamarin项目,需要花费更长的时间来构建)至于SLN-我想答案会更容易找到。
当只有一个项目而没有引用其他项目时,我确实使该管道正常工作。但是现在,正如我所提到的,它坏了。
仅作记录,我正在使用构建管道来创建docker映像并将其部署到Azure容器注册表。但这并不重要,因为它在构建上失败。
我的代码结构
解决方案
我的初始文件是通过VS上的Docker支持插件创建的(在此处提出:asp.net core 2.0 - multiple projects solution docker file)
当然,当我第一次使用它时,它没有引用项目。所以我想,好吧,也许我只是删除docker文件并再次使用Add-> Docker support。并且确实更改了dockerfile以包含引用的项目(称为BuildChat
)
因此更改后,我的docker文件如下:
#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/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["SignalRChat/SignalRChat.csproj", "SignalRChat/"]
COPY ["BuildChat/BuildChat.csproj", "BuildChat/"]
RUN dotnet restore "SignalRChat/SignalRChat.csproj"
COPY . .
WORKDIR "/src/SignalRChat"
RUN dotnet build "SignalRChat.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "SignalRChat.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "SignalRChat.dll"]
但是它不起作用。可能是因为docker无法超出上下文。但是话又说回来,码头工人的支持不知道吗?:D
我想一个选择是将其移动到SLN级别,然后使用带有-f的docker build来指定文件(我认为这是一个建议),但是我不知道如何将其包含在azure构建管道中。
也许关于如何实现这一目标还有其他想法(在这个docker“ hello world”程序中,结果非常复杂:D)
我当前的构建管道如下:
# Docker
# Build a Docker image
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- master
resources:
- repo: self
variables:
dockerRegistryServiceConnection: 'MyProductDockerACR'
imageRepository: 'mobile/signalr'
containerRegistry: 'myAcrName.azurecr.io'
dockerfilePath: '**/Dockerfile'
tag: '$(Build.BuildNumber)'
vmImageName: 'ubuntu-latest'
stages:
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: Docker@2
displayName: Build and push image to container registry
inputs:
containerRegistry: $(dockerRegistryServiceConnection)
repository: $(imageRepository)
command: 'buildAndPush'
Dockerfile: $(dockerfilePath)
tags: |
$(tag)
并且构建管道产生的错误是((剪切以显示有趣的部分:)):
Starting: Build and push image to container registry
==============================================================================
Task : Docker
Description : Build or push Docker images, login or logout, or run a Docker command
Version : 2.166.1
Author : Microsoft Corporation
Help : https://aka.ms/azpipes-docker-tsg
==============================================================================
/usr/bin/docker build -f /home/vsts/work/1/s/SignalRChat/Dockerfile --label com.azure.dev.image.system.teamfoundationcollectionuri=https://dev.azure.com/myAzureDevops/ --label com.azure.dev.image.system.teamproject=Mobile --label com.azure.dev.image.build.repository.name=Mobile --label com.azure.dev.image.build.sourceversion=e1fcddf1507478434251b2c12a3f999ef23f7b70 --label com.azure.dev.image.build.repository.uri=https://[email protected]/myAzureDevops/Mobile/_git/Mobile --label com.azure.dev.image.build.sourcebranchname=master --label com.azure.dev.image.build.definitionname=Mobile --label com.azure.dev.image.build.buildnumber=20200423.7 --label com.azure.dev.image.build.builduri=vstfs:///Build/Build/26 -t ***/mobile/signalr:20200423.7 /home/vsts/work/1/s/SignalRChat
Sending build context to Docker daemon 2.509MB
[...]
Status: Downloaded newer image for mcr.microsoft.com/dotnet/core/sdk:3.1-buster
---> 4aa6a74611ff
Step 6/27 : WORKDIR /src
---> Running in abca9a0a7296
Removing intermediate container abca9a0a7296
---> 15699d4bddc2
Step 7/27 : COPY ["SignalRChat/SignalRChat.csproj", "SignalRChat/"]
COPY failed: stat /var/lib/docker/tmp/docker-builder654251088/SignalRChat/SignalRChat.csproj: no such file or directory
##[error]COPY failed: stat /var/lib/docker/tmp/docker-builder654251088/SignalRChat/SignalRChat.csproj: no such file or directory
##[error]The process '/usr/bin/docker' failed with exit code 1
我认为您的订单可能有误