Skip to contentSkip to conversation

fix build failures from incorrectly skipped container build jobs

PATCH In review Daniel P. Berrangé 3 participants 8 messages Feb 16, 2021 – Feb 24, 2021

lore
Share & tools
lore
#0 lore raw

v2 cover fix build failures from incorrectly skipped container build jobs

This series fixes a problem with our gitlab CI rules that cause container builds to be skipped. See the commit description in the first patch for the details on this problem.

The overall result of this series though is a small increase in overall pipeline time.

Previously

- When container jobs are skipped: approx 1hr 5 mins
- When container jobs are run, cached by docker: approx 1hr 15 mins
- When container jobs are run, not cached by docker: approx 1hr 30 mins

With this series applied the first scenario no longer exists, so all piplines are either 1hr 15 or 1hr 30 depending on whether the container phase is skipped.

On the plus side the builds are more reliable as we're actually building container images at correct times.

There is still a race condition though where build jobs can run with the wrong containers. This happens if you push two different branches to gitlab with different docker file content. If the container jobs for the 2nd branch finish before the 1st branch runs its build jobs, the 1st branch can end up using containers fro the second branch. The only fix to truely fix that would be to stop using "latest" docker tag and always use a tag based on the branch name. This would mean we build up a growing set of docker images in the gitlab registry.

At least this series is much more correct that what exists in git currently. I'm intending to continue to investigate a solution for the remaining race condition, but don't want to block this series from merging, since this already solves the problem for the majority of contributors' usage.

Changed in v2:

- Set needs rules for cross jobs too

Daniel P. Berrangé (3):
gitlab: always build container images
gitlab: add fine grained job deps for all build jobs
gitlab: fix inconsistent indentation

 .gitlab-ci.d/containers.yml  |  7 ----
 .gitlab-ci.d/crossbuilds.yml | 46 ++++++++++++++++++++++
 .gitlab-ci.yml               | 74 ++++++++++++++++++++++++++++++++----
 3 files changed, 112 insertions(+), 15 deletions(-)
Signature · 1 line
2.29.2
#2 lore raw

PATCH v2 2/3 gitlab: add fine grained job deps for all build jobs

This allows the build jobs to start running as soon as their respective container image is ready, instead of waiting for all container builds to finish.

---
 .gitlab-ci.d/crossbuilds.yml | 46 ++++++++++++++++++++++++++++
 .gitlab-ci.yml               | 58 ++++++++++++++++++++++++++++++++++++
 2 files changed, 104 insertions(+)
.gitlab-ci.d/crossbuilds.yml +46 -0
index 66547b6683..d5098c986b 100644
@@ -41,114 +41,158 @@
 
 cross-armel-system:
   extends: .cross_system_build_job
+  needs:
+    job: armel-debian-cross-container
   variables:
     IMAGE: debian-armel-cross
 
 cross-armel-user:
   extends: .cross_user_build_job
+  needs:
+    job: armel-debian-cross-container
   variables:
     IMAGE: debian-armel-cross
 
 cross-armhf-system:
   extends: .cross_system_build_job
+  needs:
+    job: armhf-debian-cross-container
   variables:
     IMAGE: debian-armhf-cross
 
 cross-armhf-user:
   extends: .cross_user_build_job
+  needs:
+    job: armhf-debian-cross-container
   variables:
     IMAGE: debian-armhf-cross
 
 cross-arm64-system:
   extends: .cross_system_build_job
+  needs:
+    job: arm64-debian-cross-container
   variables:
     IMAGE: debian-arm64-cross
 
 cross-arm64-user:
   extends: .cross_user_build_job
+  needs:
+    job: arm64-debian-cross-container
   variables:
     IMAGE: debian-arm64-cross
 
 cross-i386-system:
   extends: .cross_system_build_job
+  needs:
+    job: i386-fedora-cross-container
   variables:
     IMAGE: fedora-i386-cross
     MAKE_CHECK_ARGS: check-qtest
 
 cross-i386-user:
   extends: .cross_user_build_job
+  needs:
+    job: i386-fedora-cross-container
   variables:
     IMAGE: fedora-i386-cross
     MAKE_CHECK_ARGS: check
 
 cross-mips-system:
   extends: .cross_system_build_job
+  needs:
+    job: mips-debian-cross-container
   variables:
     IMAGE: debian-mips-cross
 
 cross-mips-user:
   extends: .cross_user_build_job
+  needs:
+    job: mips-debian-cross-container
   variables:
     IMAGE: debian-mips-cross
 
 cross-mipsel-system:
   extends: .cross_system_build_job
+  needs:
+    job: mipsel-debian-cross-container
   variables:
     IMAGE: debian-mipsel-cross
 
 cross-mipsel-user:
   extends: .cross_user_build_job
+  needs:
+    job: mipsel-debian-cross-container
   variables:
     IMAGE: debian-mipsel-cross
 
 cross-mips64el-system:
   extends: .cross_system_build_job
+  needs:
+    job: mips64el-debian-cross-container
   variables:
     IMAGE: debian-mips64el-cross
 
 cross-mips64el-user:
   extends: .cross_user_build_job
+  needs:
+    job: mips64el-debian-cross-container
   variables:
     IMAGE: debian-mips64el-cross
 
 cross-ppc64el-system:
   extends: .cross_system_build_job
+  needs:
+    job: ppc64el-debian-cross-container
   variables:
     IMAGE: debian-ppc64el-cross
 
 cross-ppc64el-user:
   extends: .cross_user_build_job
+  needs:
+    job: ppc64el-debian-cross-container
   variables:
     IMAGE: debian-ppc64el-cross
 
 cross-s390x-system:
   extends: .cross_system_build_job
+  needs:
+    job: s390x-debian-cross-container
   variables:
     IMAGE: debian-s390x-cross
 
 cross-s390x-user:
   extends: .cross_user_build_job
+  needs:
+    job: s390x-debian-cross-container
   variables:
     IMAGE: debian-s390x-cross
 
 cross-s390x-kvm-only:
   extends: .cross_accel_build_job
+  needs:
+    job: s390x-debian-cross-container
   variables:
     IMAGE: debian-s390x-cross
     ACCEL_CONFIGURE_OPTS: --disable-tcg
 
 cross-win32-system:
   extends: .cross_system_build_job
+  needs:
+    job: win32-fedora-cross-container
   variables:
     IMAGE: fedora-win32-cross
 
 cross-win64-system:
   extends: .cross_system_build_job
+  needs:
+    job: win64-fedora-cross-container
   variables:
     IMAGE: fedora-win64-cross
 
 cross-amd64-xen-only:
   extends: .cross_accel_build_job
+  needs:
+    job: amd64-debian-cross-container
   variables:
     IMAGE: debian-amd64-cross
     ACCEL: xen
@@ -156,6 +200,8 @@ cross-amd64-xen-only:
 
 cross-arm64-xen-only:
   extends: .cross_accel_build_job
+  needs:
+    job: arm64-debian-cross-container
   variables:
     IMAGE: debian-arm64-cross
     ACCEL: xen
.gitlab-ci.yml +58 -0

232 lines not on this page · raw message

Signature · 1 line
2.29.2
#1 lore raw

PATCH v2 1/3 gitlab: always build container images

In reply to Daniel P. Berrangé

Currently we attempt to skip building container images if the commits do not involve changes to the dockerfiles or gitlab CI definitions.

Conceptually this makes sense, but there is a challenge in the real world implementation of this in gitlab.

In the case of a CI pipeline triggered from a merge request, GitLab knows the common ancestor of the merge request and the main git repo, so it can trivially determine if any of the commits associated with the MR change the dockerfiles.

In the case of a CI pipeline triggered from a push to a branch, it is much more difficult. There is no concept of a common ancestor in this case. Instead GitLab looks at the set of commits in the git push event.

On the surface this may sound reasonable, but it doesn't take into account that a push event does not always contain the full set of patches from a branch.

For example, consider pushing 5 commits, one of which contains a dockerfile change. This will trigger a CI pipeline for the containers. Now consider you do some more work on the branch and push 3 further commits, so you now have a branch of 8 commits. For the second push GitLab will only look at the 3 most recent commits, the other 5 were already present. Thus GitLab will not realize that the branch has dockerfile changes that need to trigger the container build.

This can cause real world problems:

- Push 5 commits to branch "foo", including a dockerfile change

=> rebuilds the container images with content from "foo" => build jobs runs against containers from "foo"

- Refresh your master branch with latest upstream master

=> rebuilds the container images with content from "master" => build jobs runs against containers from "master"

- Push 3 more commits to branch "foo", with no dockerfile change

=> no container rebuild triggers
=> build jobs runs against containers from "master"

The "changes" conditional in gitlab is OK, *provided* your build jobs are not relying on any external state from previous builds.

This is NOT the case in QEMU, because we are building container images and these are cached. This is a scenario in which the "changes" conditional is not usuable.

The only other way to avoid this problem would be to use the git branch name as the container image tag, instead of always using "latest". The downside of this approach is that the user's gitlab registry will grow significantly until it starts to trigger GitLab's automatic deletion policy. Every time the user starts a new branch they will have to trigger a rebuild of the container images. Given this, we might as well just drop the conditional and always build the container images. Most of the time docker will be able to use the layer cache to avoid the most expensive part of the rebuild process (installing all the RPMs/debs/etc)

---
 .gitlab-ci.d/containers.yml | 7 -------
 1 file changed, 7 deletions(-)
.gitlab-ci.d/containers.yml +0 -7
index 90fac85ce4..33e4046e23 100644
@@ -20,13 +20,6 @@
     - docker push "$TAG"
   after_script:
     - docker logout
-  rules:
-    - changes:
-      - .gitlab-ci.d/containers.yml
-      - tests/docker/*
-      - tests/docker/dockerfiles/*
-    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
-    - if: '$CI_COMMIT_REF_NAME == "testing/next"'
 
 amd64-alpine-container:
   <<: *container_job_definition
Signature · 1 line
2.29.2
Reviewed-by on v2 2/3
#3 lore raw

Re: [PATCH v2 2/3] gitlab: add fine grained job deps for all build jobs

In reply to Daniel P. Berrangé
Quoted 9 lines · Daniel P. Berrangé

This allows the build jobs to start running as soon as their respective container image is ready, instead of waiting for all container builds to finish.

---
 .gitlab-ci.d/crossbuilds.yml | 46 ++++++++++++++++++++++++++++
 .gitlab-ci.yml               | 58 ++++++++++++++++++++++++++++++++++++
 2 files changed, 104 insertions(+)
#4 lore raw

PATCH v2 3/3 gitlab: fix inconsistent indentation

In reply to Daniel P. Berrangé

The standard is to use 2 space indent, not 3.

---
 .gitlab-ci.yml | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
.gitlab-ci.yml +8 -8
index 32cc6bd4a2..870d5f83f5 100644
@@ -282,14 +282,14 @@ check-system-opensuse:
     MAKE_CHECK_ARGS: check
 
 acceptance-system-opensuse:
-   <<: *native_test_job_definition
-   needs:
-     - job: build-system-opensuse
-       artifacts: true
-   variables:
-     IMAGE: opensuse-leap
-     MAKE_CHECK_ARGS: check-acceptance
-   <<: *acceptance_definition
+  <<: *native_test_job_definition
+  needs:
+    - job: build-system-opensuse
+      artifacts: true
+  variables:
+    IMAGE: opensuse-leap
+    MAKE_CHECK_ARGS: check-acceptance
+  <<: *acceptance_definition
 
 
 build-disabled:
Signature · 1 line
2.29.2
#5 lore raw
In reply to Daniel P. Berrangé

ping - can we get this series merged so we reduce the chances of stale container images for people working across multiple branches

Quoted 45 lines · Daniel P. Berrangé

This series fixes a problem with our gitlab CI rules that cause container builds to be skipped. See the commit description in the first patch for the details on this problem.

The overall result of this series though is a small increase in overall pipeline time.

Previously

- When container jobs are skipped: approx 1hr 5 mins
- When container jobs are run, cached by docker: approx 1hr 15 mins
- When container jobs are run, not cached by docker: approx 1hr 30 mins

With this series applied the first scenario no longer exists, so all piplines are either 1hr 15 or 1hr 30 depending on whether the container phase is skipped.

On the plus side the builds are more reliable as we're actually building container images at correct times.

There is still a race condition though where build jobs can run with the wrong containers. This happens if you push two different branches to gitlab with different docker file content. If the container jobs for the 2nd branch finish before the 1st branch runs its build jobs, the 1st branch can end up using containers fro the second branch. The only fix to truely fix that would be to stop using "latest" docker tag and always use a tag based on the branch name. This would mean we build up a growing set of docker images in the gitlab registry.

At least this series is much more correct that what exists in git currently. I'm intending to continue to investigate a solution for the remaining race condition, but don't want to block this series from merging, since this already solves the problem for the majority of contributors' usage.

Changed in v2:

- Set needs rules for cross jobs too

Daniel P. Berrangé (3):
gitlab: always build container images
gitlab: add fine grained job deps for all build jobs
gitlab: fix inconsistent indentation

Quoted 8 lines
 .gitlab-ci.d/containers.yml  |  7 ----
 .gitlab-ci.d/crossbuilds.yml | 46 ++++++++++++++++++++++
 .gitlab-ci.yml               | 74 ++++++++++++++++++++++++++++++++----
 3 files changed, 112 insertions(+), 15 deletions(-)
Signature · 1 line
2.29.2

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 :|
#7 lore raw
Quoted 9 lines · Thomas Huth
Quoted 2 lines · Daniel P. Berrangé

ping - can we get this series merged so we reduce the chances of stale container images for people working across multiple branches

It's in already:

https://gitlab.com/qemu-project/qemu/-/commit/c31fa24e9690ef62b

You should also have gotten the PULL mail on CC: ? Did it get lost?

Doh, sorry for the noise. I am indeed behind on my branch.

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 :|