Skip to content

Resolve "Re-use and tag master CI test image for merge requests"

Closes #753 (closed) #764 (closed)

I just figured out how to fix this, assuming that we can write to .cluster.env several times in one CI pipeline or do several reports.dotenvs

  1. do a curl to the container registry API to check if we already have an image for the current branch:

    curl https://open.greenhost.net/api/v4/projects/openappstack%2Fopenappstack/registry/repositories/2/tags/${CI_COMMIT_REF_SLUG}

    If it exists, write to .cluster.env: CI_CONTAINER_TAG=${CI_COMMIT_REF_SLUG} If it does not exist, write to .cluster.env: CI_CONTAINER_TAG=master

  2. If the Dockerfile or requirements.txt has changed, build the container like we do now, and write to .cluster.env: CI_CONTAINER_TAG=${CI_COMMIT_REF_SLUG}

  3. Change default image to image: "${CI_REGISTRY_IMAGE}/${KANIKO_BUILD_IMAGENAME}:${CI_CONTAINER_TAG}"

What I tried before:

  1. I tried the docker pull master; docker tag ; docker push but it requires "docker in docker" to work, which would require us to make some adjustments to the docker runners that compromise some of its security
  2. I checked if we can use the GitLab API to re-tag an image (we can't, we can only GET and DELETE them)
  3. I checked if kaniko can easily re-tag an image
  4. I checked if we can only run the container build job for new branches or merge requests, but I haven't found a way of checking if your commit is for a new branch or merge request or not
Edited by Maarten de Waard

Merge request reports