我正在尝试学习Azure DevOps管道和AKS。最终目标是Build and deploy to Azure Kubernetes Service,但我将其分解为较小的部分,因此请了解每个阶段的情况。
因此,我目前的目标是Build and push to Azure Container Registry。
我正在使用一个非常基本的monorepo,它具有简化的结构:
acr-test/
client/
Dockerfile
db/
Dockerfile
server/
Dockerfile
我想为应用程序的每个部分生成图像,以便生成arc-test-client
和arc-test-server
。
[当我在Azure DevOps中“创建管道”并让其构建azure-pipelines.yml
时,正在发生什么,因为它只是找到第一个Dockerfile
并以所有参数为基础,而忽略了其他参数。
有些我很好奇:
azure-pipelines.yml
创建多个图像?.yml
是否需要多个Dockerfile
?.sh
来分别构建和推送这些example吗?azure-pipelines.yml
。.sh
脚本,但仅在azure-pipelines.yml
中放置docker任务可能更容易您将需要执行以下操作:
steps:
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository1)
dockerfile: $(dockerfilePath1)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag1)
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository2)
dockerfile: $(dockerfilePath2)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag2)
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository3)
dockerfile: $(dockerfilePath3)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag3)
或在回购中可以有多个something.yml
,并且每个组件都有单独的版本(更有意义,tbh)
或者,使用您的文件结构,您可以将相同的yaml文件用作模板,并仅提供其参数。这将减少代码重复并简化构建管理]