DRY jobs when building docker images

Hi all, I have a pipeline to build docker images. The job is triggered by a change to the TAG file:

resources:
  - name: my-git
    type: git
    source:
      uri: …
      branch: "master"
      paths:
        - "dockerfiles/image1/TAG"

  - name: my-docker-image
    type: docker-image
    source:
    …

jobs:
  - name: test
    plan:
      - get: my-repo
        resource: my-git
        trigger: true

      - put: my-docker-image
        params:
          build: my-repo/dockerfiles/image1
          tag_file: my-repo/dockerfiles/image1/TAG

now, I’d want to add more images like the image1/ directory, and my question is: what’s the best approach to not repeat the resource and job for each image, and only build the image which TAG file has changed.

AFAIK there aren’t any features built into Concourse that can help you DRY out your pipeline code. However you can use YAML anchors (a feature of YAML itself) to clean up the resources a little bit.

Something like:

resources:
  - name: image1-git
    type: git
    source: &git-config
      uri: some-url
      branch: "master"
      paths:
        - "dockerfiles/image1/TAG"

  - name: image2-git
    type: git
    source: *git-config
      paths:
      - "dockerfiles/image2/TAG"

  - name: my-docker-image-1
    type: docker-image
    source:
      <<: &docker-creds
        username: user
        password: pass
      repository: foo/bar

  - name: my-docker-image-2
    type: docker-image
    source:
      <<: *docker-creds
      repository: foo/buz