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.dotenv
s
-
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
-
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}
-
Change default image to
image: "${CI_REGISTRY_IMAGE}/${KANIKO_BUILD_IMAGENAME}:${CI_CONTAINER_TAG}"
What I tried before:
- 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
- I checked if we can use the GitLab API to re-tag an image (we can't, we can only GET and DELETE them)
- I checked if kaniko can easily re-tag an image
- 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