从 monorepo 构建多个镜像,其中每个服务都有自己的 Dockerfile
Building multiple images from a monorepo where each service has its own Dockerfile
我正在尝试学习 Azure DevOps Pipelines 和 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 中 "Create Pipeline" 并让它构建 azure-pipelines.yml
时,当前发生的事情是它只是找到第一个 Dockerfile
并基于它的所有参数,忽略其他的。
有些我很好奇:
- 是否可以从单个图像创建多个图像
azure-pipelines.yml
?
- 每个
Dockerfile
我需要多个 .yml
吗?
- 我是否需要编写单独的
.sh
来单独构建和推送它们 (example)?
- 或者这对于 mono-repo 来说根本不可能吗?
- 是的,您需要为此修改
azure-pipelines.yml
。
- 没有。全部一个或每个 docker文件一个都可以
- 没有必要,您可以使用
.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)
或者在 repo 中可以有多个 something.yml
并且每个组件都有单独的构建(更有意义,tbh)
或者,使用您的文件结构,您可以重复使用相同的 yaml 文件作为模板并为其提供参数。这将减少代码重复并允许更轻松地管理您的构建
我正在尝试学习 Azure DevOps Pipelines 和 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 中 "Create Pipeline" 并让它构建 azure-pipelines.yml
时,当前发生的事情是它只是找到第一个 Dockerfile
并基于它的所有参数,忽略其他的。
有些我很好奇:
- 是否可以从单个图像创建多个图像
azure-pipelines.yml
? - 每个
Dockerfile
我需要多个.yml
吗? - 我是否需要编写单独的
.sh
来单独构建和推送它们 (example)? - 或者这对于 mono-repo 来说根本不可能吗?
- 是的,您需要为此修改
azure-pipelines.yml
。 - 没有。全部一个或每个 docker文件一个都可以
- 没有必要,您可以使用
.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)
或者在 repo 中可以有多个 something.yml
并且每个组件都有单独的构建(更有意义,tbh)
或者,使用您的文件结构,您可以重复使用相同的 yaml 文件作为模板并为其提供参数。这将减少代码重复并允许更轻松地管理您的构建