从monorepo构建多个映像,其中每个服务都有其自己的Dockerfile

问题描述 投票:2回答:1

我正在尝试学习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-clientarc-test-server

[当我在Azure DevOps中“创建管道”并让其构建azure-pipelines.yml时,正在发生什么,因为它只是找到第一个Dockerfile并以所有参数为基础,而忽略了其他参数。

有些我很好奇:

  • 是否可以通过单个azure-pipelines.yml创建多个图像?
  • 每个.yml是否需要多个Dockerfile
  • 我需要编写单独的.sh来分别构建和推送这些example吗?
  • 或者单存储库根本不可能吗?
azure docker azure-devops azure-container-service
1个回答
3
投票
  1. 是,您需要为此修改azure-pipelines.yml
  2. 不。一个全部或每个dockerfile一个就可以了
  3. [不是必需的,您可以使用.sh脚本,但仅在azure-pipelines.yml中放置docker任务可能更容易
  4. 是。

您将需要执行以下操作:

    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文件用作模板,并仅提供其参数。这将减少代码重复并简化构建管理]

© www.soinside.com 2019 - 2024. All rights reserved.