11

我想在我的管道中构建一个 docker 映像,然后在其中运行一个作业,而不是推送或拉取映像。

这可能吗?

4

2 回答 2

3

按照设计,如果不使用某种外部资源来存储它,您就不能在管道中的作业之间传递工件。但是,您可以在单个作业中的任务之间传递。此外,您可以在每个任务级别而不是每个作业级别上指定图像。Ergo,做你想做的最简单的方法可能是有一个单一的工作,它的第一个任务是生成 docker-image,第二个任务将它作为容器镜像使用。

在您的情况下,您将在构建任务中构建 docker 映像,并用于docker export将映像的文件系统导出到 rootfs,您可以将其放入输出 ( my-task-image)。请记住它需要匹配的 rootfs 输出的特定模式。您将需要 rootfs/...(提取的 'docker export')和 metadata.json,它可以只包含一个空的 json 对象。您可以查看 docker-image-resource 中的 in 脚本,以获取有关如何使其与架构匹配的更多信息:https ://github.com/concourse/docker-image-resource/blob/master/assets/in 。然后在后续任务中,您可以在管道 yml 中添加 image 参数,如下所示:

- task: use-task-image
  image: my-task-image
  file: my-project/ci/tasks/my-task.yml

为了在任务中使用构建的图像。

于 2016-12-09T17:49:01.373 回答
0

UDPATE:PR 被拒绝

这个答案目前不起作用,因为“dry_run”PR 被拒绝了。见https://github.com/concourse/docker-image-resource/pull/185

如果我找到一种可行的方法,我会在这里更新。


2017 年 10 月添加到 docker 资源的“dry_run”参数现在允许这样做(github pr

您需要添加一个虚拟 docker 资源,例如:

resources:
  - name: dummy-docker-image
    type: docker-image
    icon: docker
    source:
      repository: example.com
      tag: latest
  - name: my-source
    type: git
    source:
      uri: git@github.com:me/my-source.git

然后添加一个构建步骤,该步骤推送到该 docker 资源,但设置了“dry_run”,这样实际上没有任何内容被推送:

jobs:
  - name: My Job
    plan:
      - get: my-source
        trigger: true
      - put: dummy-docker-image
        params:
          dry_run: true
          build: path/to/build/scope
          dockerfile: path/to/build/scope/path/to/Dockerfile
于 2020-10-27T15:31:09.473 回答