Building several docker images depending on each other

Hi!
I am currently on the way to build a CI/CD chain for several docker images depending on each other.

We have a base image (Level A) that gets used in another level of docker files (Level B). Level B Dockerfiles are get used in other Dockerfiles (Level C) and so on. Last level may be Z.
When a Dockerfile changes in git i want that the image is rebuilt and all referencing images.
Example 1: If B is changed i want B to be rebuilt, then C then D and so on.
Example 2: If the last Level Z is being changed i only want that Layer to be rebuild.

In order to track versioning of images i want my images to be tagged with a timestamp YYYYmmdd-HHMM

What i’ve got so far is:
I managed to build Level A which gets tagged with the correct timestamp format. I did this that way:

jobs:
- name: build-amd64-ubuntu-bionic-base
  public: true
  serial: true
  plan:
  - get: source
    trigger: true
  - task: build-cached-image-workspace
    config:
      platform: linux
      image_resource:
        type: docker-image
        source:
          repository: ubuntu
      outputs:
      - name: workspace
      run:
        path: /bin/bash
        args:
        - -c
        - |
          output_dir=workspace
          echo $(date +"%Y%m%d%H%M") > "$output_dir/timestamp"
          echo bionic-$(cat "$output_dir/timestamp") > "$output_dir/tag"
    
  - put: amd64-ubuntu-bionic-base
    params:
      build: source/amd64/ubuntu/bionic/base/
      dockerfile: source/amd64/ubuntu/bionic/base/Dockerfile
      tag_file: workspace/tag

My problems right now ware:

  1. How do i trigger Level B when Level A changed? I thought of using some gating resource (meshcloud/gate-resource) to trigger following Levels. This could be possible, but i wasn’t able to test it because of issue 2
  2. How do i pass the timestamp from Level A into Level B as a string that can get used as build_args to reference the correct version in the Dockerfile? The Dockerfile contains an ARG for the Version to use.
ARG DOCKER_REGISTRY
ARG ARCH
ARG OS
ARG OS_RELEASE
ARG TIMESTAMP

FROM ${DOCKER_REGISTRY:-none}/{ARCH:-amd64}/{OS:-ubuntu}/${RELEASE:-bionic}:${TIMESTAMP:-latest} 

I thougt of using some keyvalue resource to pass on variables. But nevertheless i don’t find a way to get the information from "$output_dir/timestamp" into a string.

Can anybody help me out?

You can use the semver resource to grab a version number, input to a task to check if the version needs bumping, and put that version number back into a semver resource that should only trigger if a new version is available.

See Semver Resource