Support multiple module project with several JIB artifacts

Description

The jib pipeline works for the case that you have a single main artifact / container in the root of the folder. Many projects that i work on contain several deliverables (e.g. micro services) in the same repository.

The global jib works already by setting properties in all modules:

  1. in modules that are pom, shared libraries or artifacts that are not delivered as jib you set the property jib.skip to false
    <properties>
      <jib.skip>true</jib.skip>
    </properties>
  2. in modules that are delivered you set the property image to the target image name.
    <properties>
      <image>yourRegistry/${CI_PROJECT_PATH_SLUG}/${project.artifactId}</>
    </properties>

With this the jib build target will create the images as wanted and creates one jib-image.digest in each module with an image created.

Starting from this point the following assumptions of the pipeline no longer work:

  • the dotenv file assumes an image name different from the one set in the pom.xml used by jib
  • multiple images and jib-image.digest files exists now meaning all follow up build steps (sbom, trivy, release) are now no longer working as intended, as all of them assume a single jib digest
  • image url used for skopeo is not the one set in the pom.xml

Implementation ideas

Switch to using jib-image.json

Jib already creates a json file containing image url, image id, image digest, and tags. Most of the existing stage script should work when looping over those files and extracting the values needed from the files created by jib.

for i in `find -name jib-image.json`; do 
  imageDigest=$(cat $i | jq .imageDigest | cut -d\" -f2 | cut -d':' -f 2)
  imageUrl=$(cat $i | jq .image| cut -d\" -f2 | cut -d':' -f 2)
done

For me this is more a quick fix than good solution as the test and analysis results from the different artifacts would always share the reporting from a single stage.

Use Declare Modules In Pipeline Component Input

As much as I love auto-detection and hands-off configuration I think pipeline users can declare which components create delivery artifacts. This can be as simple as listing the module paths creating images via jib.

  - component: "$CI_SERVER_FQDN/to-be-continuous/maven/gitlab-ci-maven-jib@3.11.2"
    inputs:
      jib-modules: [ serviceA, path/to/serviceB ]

With these module paths it is then possible to create the build steps from the existing templates and add a parallel matrix build and give the paths as build parameter to each step.

This has the advantage that you end with having one trivy, sbom, etc. check status per image.