简体   繁体   English

让Concourse仅在文件diff上构建新的docker容器而不是在提交时构建

[英]Have Concourse only build new docker containers on file diff not on commit

So I have a pipeline that builds multiple docker containers from a single git repo. 所以我有一个从单个git repo构建多个docker容器的管道。 It looks something like this: 看起来像这样:

---
resources:
- name: resource-docker
  type: git
  source:
    uri: https://github.com/$MYUSER/$MYREPO.git
    branch: master

# docker-image resources
- name: first-container
  type: docker-image
  source:
    repository: $MYUSER/first-container

- name: second-container
  type: docker-image
  source:
    repository: $MYUSER/second-container

jobs:
# image-update jobs
- name: first-container-image-update
  public: true
  serial_groups:
    - serial_lock
  plan:
  - get: resource-docker
    serial: true
  - put: first-container
    params:
      build: resource-docker/first-container-path

- name: second-container-image-update
  public: true
  serial_groups:
    - serial_lock
  plan:
  - get: resource-docker
    serial: true
  - put: second-container
    params:
      build: resource-docker/second-container-path

The problem is that running a resource-docker task is taking up a significant portion of system resources and rebuilding the containers from scratch on each commit to the master (which contains more code than just the docker containers). 问题在于,运行resource-docker任务会占用系统资源的很大一部分,并且在每次提交到主服务器时都会从头开始重建容器(其中包含的代码比docker容器还多)。

I would like to make these tasks instead compare the old and new files used to build the containers, and only rebuild a container if there is a diff in the files. 我想执行这些任务,而不是比较用于构建容器的旧文件和新文件,并且仅当文件中存在差异时才重新构建容器。

Note: that separating the files out into different repos is an option I want to avoid. 注意:我想避免将文件分成不同的存储库。

your resource can be configured to trigger new builds only with changes to specific files in the repo: 您的资源可以配置为仅通过对仓库中的特定文件进行更改来触发新的构建:

- name: resource-docker
  type: git
  source:
    uri: https://github.com/$MYUSER/$MYREPO.git
    branch: master
    paths:
      - <path/to/Dockerfile/or/whatever>
      - <path/to/other/triggering/diffs>

In case Quintana's answer isn't totally clear, the idea is you can define multiple Git resources which point at the same Git repository. 万一Quintana的答案还不是很清楚,您可以定义多个指向同一Git存储库的Git资源。 Each resource can use paths / ignore_paths to specify which filed to look at. 每个资源都可以使用paths / ignore_paths指定要查看的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM