【问题标题】:Building multiple images from a monorepo where each service has its own Dockerfile从每个服务都有自己的 Dockerfile 的 monorepo 构建多个图像
【发布时间】:2019-12-09 18:25:54
【问题描述】:

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

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

有些我很好奇:

  • 是否可以从单个azure-pipelines.yml 创建多个图像?
  • 每个Dockerfile 是否需要多个.yml
  • 我是否需要单独编写一个 .sh 来分别构建和推送这些 (example)?
  • 或者这对于单一存储库根本不可能?

【问题讨论】:

    标签: azure docker azure-devops azure-container-service


    【解决方案1】:
    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)
    

    或者可以在 repo 中有多个 something.yml 并为每个组件单独构建(更有意义,tbh)

    或者,使用您的文件结构,您可以重复使用相同的 yaml 文件作为模板并为其提供参数。这将减少代码重复并允许更轻松地管理您的构建

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-16
      • 2012-12-19
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 2015-08-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多