【问题标题】:Planning CI pipeline to build and push docker containers规划 CI 管道以构建和推送 docker 容器
【发布时间】:2021-05-28 18:38:40
【问题描述】:

我正在创建一个管道,该管道可用于构建 docker 映像并将该映像推送到 azure 容器注册表。以下是我的存储库的树结构:

───repo
    ├── app1
    │   ├── dir1
    │   ├── dockerfile
    │   ├── file1 
    │   └── file2
    ├── app2
    │   ├── dir1
    │   ├── dockerfile
    │   ├── file1 
    │   └── file2
    ├── app3
    │   ├── dir1
    │   ├── dockerfile
    │   ├── file1 
    │   └── file2

我如何规划我的 ci,当管道运行时,如果开发人员更改 app1 目录中的 file1,则管道知道它需要使用 app1 目录中的 dockerfile 构建映像?

注意:我正在 Azure DevOps 中构建管道。

【问题讨论】:

标签: docker kubernetes azure-devops azure-pipelines


【解决方案1】:

您可以使用一个简单的 PS 脚本,该脚本使用 git 来确定更改了哪个文件夹,并使用项目名称和 true 设置构建变量:

$files=$(git diff HEAD HEAD~ --name-only)
$temp=$files -split ' '
$count=$temp.Length
Write-Host "Total changed $count files"
For ($i=0; $i -lt $temp.Length; $i++)
{
  $name=$temp[$i]
  Write-Host "this is $name file"
  $project = $name.Split('/')[0]
  Write-Host "##vso[task.setvariable variable=$project]true"
}

现在,对于每个更改的项目,您都有一个带有项目名称和值 true 的变量。

因此,在 docker build 任务中,您可以使用custom conditions。例如 - 对于app1 步骤:

and(succeeded(), eq(variables['app1'], 'true'))

【讨论】:

    猜你喜欢
    • 2018-02-13
    • 2023-03-16
    • 1970-01-01
    • 2018-03-27
    • 2018-10-23
    • 2020-01-25
    • 1970-01-01
    • 1970-01-01
    • 2017-05-15
    相关资源
    最近更新 更多