gitlab-ci: Only push Docker 'latest' image when building default branch
PATCH 1/1 gitlab-ci: Only push Docker 'latest' image when building default branch
While we are interested in building docker images in different branches, it only makes sense to push 'latest' to the registry when this is the project default branch (usually 'master').
Else when pushing different branches concurrently we might have inconsistent image state between branches.
--- .gitlab-ci.d/containers.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
.gitlab-ci.d/containers.yml +1 -1
@@ -17,7 +17,7 @@ -t "qemu/$NAME" -f "tests/docker/dockerfiles/$NAME.docker" -r $CI_REGISTRY_IMAGE - docker tag "qemu/$NAME" "$TAG" - - docker push "$TAG" + - test "$CI_COMMIT_BRANCH" = "$CI_DEFAULT_BRANCH" && docker push "$TAG" after_script: - docker logout rules:
Signature · 1 line
2.26.2
Quoted 17 lines · Philippe Mathieu-Daudé
While we are interested in building docker images in different branches, it only makes sense to push 'latest' to the registry when this is the project default branch (usually 'master').
Else when pushing different branches concurrently we might have inconsistent image state between branches.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- .gitlab-ci.d/containers.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-).gitlab-ci.d/containers.yml +0
-0
.gitlab-ci.d/containers.yml line 20
Quoted 5 lines
.gitlab-ci.d/containers.yml +1
-1@@ -17,7 +17,7 @@ -t "qemu/$NAME" -f "tests/docker/dockerfiles/$NAME.docker" -r $CI_REGISTRY_IMAGE - docker tag "qemu/$NAME" "$TAG" - - docker push "$TAG" + - test "$CI_COMMIT_BRANCH" = "$CI_DEFAULT_BRANCH" && docker push "$TAG"
So does that mean that the following stages in the CI (i.e. build, test) are only always (i.e. also for the non-master branches) going to use containers that have been build on the master branch?
Thomas
Quoted 13 lines · Thomas Huth
Quoted 12 lines · Philippe Mathieu-Daudé
While we are interested in building docker images in different branches, it only makes sense to push 'latest' to the registry when this is the project default branch (usually 'master').
Else when pushing different branches concurrently we might have inconsistent image state between branches.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
.gitlab-ci.d/containers.yml| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines
Quoted 11 lines
.gitlab-ci.d/containers.yml +0
-0@@ -17,7 +17,7 @@-t "qemu/$NAME" -f "tests/docker/dockerfiles/$NAME.docker" -r $CI_REGISTRY_IMAGE
- docker tag "qemu/$NAME" "$TAG"
- - docker push "$TAG"
+ - test "$CI_COMMIT_BRANCH" = "$CI_DEFAULT_BRANCH" && docker push "$TAG"So does that mean that the following stages in the CI (i.e. build, test) are only always (i.e. also for the non-master branches) going to use containers that have been build on the master branch?
Hmm good point. Should we use "$CI_COMMIT_BRANCH" instead of "latest"?
Quoted 30 lines · Philippe Mathieu-Daudé
Quoted 13 lines · Thomas Huth
Quoted 12 lines · Philippe Mathieu-Daudé
While we are interested in building docker images in different branches, it only makes sense to push 'latest' to the registry when this is the project default branch (usually 'master').
Else when pushing different branches concurrently we might have inconsistent image state between branches.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
.gitlab-ci.d/containers.yml| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)Quoted 15 lines
Quoted 11 lines
.gitlab-ci.d/containers.yml +0
-0@@ -17,7 +17,7 @@-t "qemu/$NAME" -f "tests/docker/dockerfiles/$NAME.docker" -r $CI_REGISTRY_IMAGE
- docker tag "qemu/$NAME" "$TAG"
- - docker push "$TAG"
+ - test "$CI_COMMIT_BRANCH" = "$CI_DEFAULT_BRANCH" && docker push "$TAG"So does that mean that the following stages in the CI (i.e. build, test) are only always (i.e. also for the non-master branches) going to use containers that have been build on the master branch?
Quoted 1 line
Hmm good point. Should we use "$CI_COMMIT_BRANCH" instead of "latest"?
This doesn't work because git branch names are not guaranteed to be valid docker tag names. Please see my thread here:
https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg03535.html
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 31 lines · Daniel P. Berrangé
Quoted 30 lines · Philippe Mathieu-Daudé
Quoted 28 lines · Thomas Huth
Quoted 17 lines · Philippe Mathieu-Daudé
While we are interested in building docker images in different branches, it only makes sense to push 'latest' to the registry when this is the project default branch (usually 'master').
Else when pushing different branches concurrently we might have inconsistent image state between branches.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
.gitlab-ci.d/containers.yml| 2 +-1 file changed, 1 insertion(+), 1 deletion(-).gitlab-ci.d/containers.yml +0
-0@@ -17,7 +17,7 @@Quoted 6 lines
-t "qemu/$NAME" -f "tests/docker/dockerfiles/$NAME.docker" -r $CI_REGISTRY_IMAGE
- docker tag "qemu/$NAME" "$TAG"
- - docker push "$TAG"
+ - test "$CI_COMMIT_BRANCH" = "$CI_DEFAULT_BRANCH" && docker push "$TAG"So does that mean that the following stages in the CI (i.e. build, test) are only always (i.e. also for the non-master branches) going to use containers that have been build on the master branch?
Quoted 6 lines
Quoted 1 line
Hmm good point. Should we use "$CI_COMMIT_BRANCH" instead of "latest"?
This doesn't work because git branch names are not guaranteed to be valid docker tag names. Please see my thread here:
https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg03535.html
Indeed this thread describes the problem I am having. I'll see if there are follow up on your thread.
Another way of fixing this is to find a way to only allow 1 pipeline at a time. I haven't tried it yet because I don't like the idea of making CI slower, but this is still better than debugging inconsistent pipelines when Docker images are rebuilt.
Regards,
Phil.