Skip to content

Include git in docker-image-builder ?

Hello,

we want to be able to use multi-project pipelines with 2 projects Upstream and Downstream, where the former is included in the latter as a submodule. We want a change in Upstream to trigger the Downstream pipeline.

This can be easily achieved with a pipeline like this:

monoHbb:
  stage: trigger_downstream
  variables:
    UPSTREAM_BRANCH: $CI_COMMIT_REF_NAME
  trigger:
    project: path/to/Downstream 
    strategy: depend

In the Downstream project we have a pipeline that uses docker-image-builder to build an docker image:

build_image:
  stage: build
  variables:
    GIT_SUBMODULE_STRATEGY: recursive
    IMAGE_DESTINATION: "${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_SLUG}"
  image:
    name: gitlab-registry.cern.ch/ci-tools/docker-image-builder
    entrypoint: [""]
  script:
    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
    - if [[ "$CI_PIPELINE_SOURCE" == "pipeline" ]] ; then echo "Triggered from pipeline, will check out $UPSTREAM_BRANCH" ; cd Upstream ; git checkout $UPSTREAM_BRANCH ; cd .. ; fi
    - /kaniko/executor --context "${CI_PROJECT_DIR}"
                       --dockerfile "${CI_PROJECT_DIR}/Dockerfile"
                       --destination "${IMAGE_DESTINATION}"
    - echo "Image pushed successfully to ${IMAGE_DESTINATION}"

Now in order to be able to get the correct commit of the Upstream submodule we need the following if [[ "$CI_PIPELINE_SOURCE" == "pipeline" ]] ; then cd Upstream ; git checkout $UPSTREAM_BRANCH ; fi however since git is not available in the image the CI jobs fail with Screenshot_2021-04-06_at_11.10.50

Would it be possible to include git in docker-image-builder?

Thanks!