首页 > 解决方案 > 组合 docker-tag 和 shell-local 时打包器后处理器“未知工件类型”错误

问题描述

我有以下打包程序配置文件:

{
  "builders":[
    {
      "type": "docker",
      "image": "ubuntu:18.04",
      "commit": true
    }

  ],
  "post-processors": [
    [
      {
        "type": "shell-local",
        "inline": ["$(aws ecr get-login --no-include-email --region us-east-2)"]
      },
      {
        "type": "docker-tag",
        "repository": "localhost/my_image",
        "tag": "latest"
      },
      {
        "type": "docker-tag",
        "repository": "123456789.dkr.ecr.us-east-2.amazonaws.com/my_image",
        "tag": "latest"
      },
      "docker-push"
    ]
  ]
}

这给了我以下错误

==> docker: Running post-processor: shell-local
==> docker (shell-local): Running local shell script: /var/folders/zh/wsr6wlx11v9703__rn7f3b080000gn/T/packer-shell756682313
==> docker (shell-local): WARNING! Using --password via the CLI is insecure. Use --password-stdin.
    docker (shell-local): Login Succeeded
==> docker: Running post-processor: docker-tag
Build 'docker' errored: 1 error(s) occurred:

* Post-processor failed: Unknown artifact type: 
Can only tag from Docker builder artifacts.

如果我删除 shell-local 后处理器,它会起作用。

我在 shell-local 后处理器中执行什么样的命令也没有关系。

我试图添加"keep_input_artifact": true到 shell-local 后处理器,但这并没有改变任何东西。

如何在 docker-tag / docker-push 后处理器之前执行 shell-local 后处理器?

标签: dockerpacker

解决方案


我想到了。我必须将 shell-local 后处理器放在一个单独的列表中,即我必须将另一个列表添加到后处理器列表中,如下所示:

"post-processors": [
    [
      {
        "type": "shell-local",
        "inline": ["$(aws ecr get-login --no-include-email --region us-east-2)"]
      }
     ],
     [
      {
        "type": "docker-tag",
        "repository": "localhost/my_image",
        "tag": "latest"
      },
      {
        "type": "docker-tag",
        "repository": "123456789.dkr.ecr.us-east-2.amazonaws.com/my_image",
        "tag": "latest"
      },
      "docker-push"
    ]
  ]
}

推荐阅读