From 9fb2d181918cb354c9e7d5ecf0b91eb8bdeddfa5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Dalleau?=
 <frederic.dalleau@collabora.com>
Date: Mon, 18 Mar 2019 10:18:08 +0000
Subject: [PATCH] Generate ostree static delta for rollback test
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The test ostree commit is generated after the successful commit.
Removing updatectl, it makes it impossible to mark an update successful.
Hence the bootcount will be increased at each boot, eventually causing
rollback to the previous deployment.

Ostree provides --skip-list that allows to create a commit with a list
of files to skip. That is useful to generate the rollback commit.
This way there is not need to modify existing recipes or provide
additional one. The execution time is also very short.

Signed-off-by: Frédéric Dalleau <frederic.dalleau@collabora.com>
---
 Jenkinsfile | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/Jenkinsfile b/Jenkinsfile
index 75df3264..91c02a5d 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -268,6 +268,26 @@ def buildOStree(architecture, type, board, debosarguments = "", repo = "repo") {
         --filename ${image_name}.delta""")
 }
 
+def buildOStreeRollbackDelta(architecture, type, board, debosarguments = "", repo = "repo") {
+  def image_name = imageName(architecture, type, board, true)
+  def branch = "${osname}/${release}/${architecture}-${board}/${type}"
+  def rollback_branch = "${osname}/${release}/${architecture}-${board}/${type}-rollback"
+
+  sh(script: """
+      cd ${PIPELINE_VERSION}/${architecture}/${type}
+      echo "/usr/bin/updatectl" > skip_list
+      ostree --repo=${repo} commit \
+        --tree=ref=${branch} \
+        --branch=${rollback_branch} \
+        --skip-list="skip_list"
+      ostree --repo=${repo} static-delta generate \
+        --from=${branch} \
+        --to=${rollback_branch} \
+        --inline \
+        --min-fallback-size=1024 \
+        --filename ${image_name}_rollback.delta""")
+}
+
 /** Generate the image name
  *
  * To have a single place for image name generation.
@@ -323,6 +343,7 @@ def buildOStreeImage(architecture, type, board, debosarguments = "") {
 
     stage("${architecture} ${type} ${board} OStree image build") {
       buildOStree(architecture, type, board, debosarguments, repo)
+      buildOStreeRollbackDelta(architecture, type, board, debosarguments, repo)
 
       sh(script: """
           cd ${PIPELINE_VERSION}/${architecture}/${type}
-- 
GitLab