From fcc397f16efde0c053c8a96e7500147ab84cb8d3 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Tue, 28 Apr 2020 16:28:14 +0000 Subject: image_types_ostree/ota: use hash from ostree commit Relying on a OSTree branch reference has been problematic in the past and addressed by adding more attributes to it in commit 202a8c70ba8c ("image_types_ostree: Add a unique ref to fix simultaneous bitbaking."). However, depening on what kind of OpenEmbedded builds are running in parallel, even more attributes would need to be taken into account. Instead of relying on a reference, store the exact ostree commit hash in a manifest file and reuse it in the do_image_ota deploy task. This guarantees that the correct reference gets picked even when two builds with the exact same machine/image name run in parallel. Note: This gets rid of the second branch name again. If the branch name with image name is preferred, the variable OSTREE_BRANCHNAME can be used: OSTREE_BRANCHNAME = "${SOTA_HARDWARE_ID}-${IMAGE_BASENAME}" Signed-off-by: Stefan Agner --- classes/image_types_ostree.bbclass | 18 ++++++------------ classes/image_types_ota.bbclass | 2 +- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/classes/image_types_ostree.bbclass b/classes/image_types_ostree.bbclass index a8a6c39..dad625d 100644 --- a/classes/image_types_ostree.bbclass +++ b/classes/image_types_ostree.bbclass @@ -168,25 +168,19 @@ IMAGE_CMD_ostreecommit () { fi # Commit the result - ostree --repo=${OSTREE_REPO} commit \ + ostree_target_hash=$(ostree --repo=${OSTREE_REPO} commit \ --tree=dir=${OSTREE_ROOTFS} \ --skip-if-unchanged \ --branch=${OSTREE_BRANCHNAME} \ --subject="${OSTREE_COMMIT_SUBJECT}" \ --body="${OSTREE_COMMIT_BODY}" \ - --add-metadata-string=version="${OSTREE_COMMIT_VERSION}" \ - --bind-ref="${OSTREE_BRANCHNAME}-${IMAGE_BASENAME}" + --add-metadata-string=version="${OSTREE_COMMIT_VERSION}") + + echo $ostree_target_hash > ${WORKDIR}/ostree_manifest if [ "${OSTREE_UPDATE_SUMMARY}" = "1" ]; then ostree --repo=${OSTREE_REPO} summary -u fi - - # To enable simultaneous bitbaking of two images with the same branch name, - # create a new ref in the repo using the basename of the image. (This first - # requires deleting it if it already exists.) Fixes OTA-2211. - ostree --repo=${OSTREE_REPO} refs --delete ${OSTREE_BRANCHNAME}-${IMAGE_BASENAME} - ostree_target_hash=$(cat ${OSTREE_REPO}/refs/heads/${OSTREE_BRANCHNAME}) - ostree --repo=${OSTREE_REPO} refs --create=${OSTREE_BRANCHNAME}-${IMAGE_BASENAME} ${ostree_target_hash} } IMAGE_TYPEDEP_ostreepush = "ostreecommit" @@ -236,7 +230,7 @@ IMAGE_CMD_garagesign () { --home-dir ${GARAGE_SIGN_REPO} \ --credentials ${SOTA_PACKED_CREDENTIALS} - ostree_target_hash=$(cat ${OSTREE_REPO}/refs/heads/${OSTREE_BRANCHNAME}-${IMAGE_BASENAME}) + ostree_target_hash=$(cat ${WORKDIR}/ostree_manifest) # Use OSTree target hash as version if none was provided by the user target_version=${ostree_target_hash} @@ -312,7 +306,7 @@ IMAGE_CMD_garagecheck () { # if credentials are issued by a server that doesn't support offline signing, exit silently unzip -p ${SOTA_PACKED_CREDENTIALS} root.json targets.pub targets.sec tufrepo.url 2>&1 >/dev/null || exit 0 - ostree_target_hash=$(cat ${OSTREE_REPO}/refs/heads/${OSTREE_BRANCHNAME}-${IMAGE_BASENAME}) + ostree_target_hash=$(cat ${WORKDIR}/ostree_manifest) garage-check --ref=${ostree_target_hash} \ --credentials=${SOTA_PACKED_CREDENTIALS} \ diff --git a/classes/image_types_ota.bbclass b/classes/image_types_ota.bbclass index 374ddc2..56c7794 100644 --- a/classes/image_types_ota.bbclass +++ b/classes/image_types_ota.bbclass @@ -64,7 +64,7 @@ IMAGE_CMD_ota () { bbfatal "Invalid bootloader: ${OSTREE_BOOTLOADER}" fi - ostree_target_hash=$(cat ${OSTREE_REPO}/refs/heads/${OSTREE_BRANCHNAME}-${IMAGE_BASENAME}) + ostree_target_hash=$(cat ${WORKDIR}/ostree_manifest) ostree --repo=${OTA_SYSROOT}/ostree/repo pull-local --remote=${OSTREE_OSNAME} ${OSTREE_REPO} ${ostree_target_hash} kargs_list="" -- cgit v1.2.3-54-g00ecf From 48c0442f926940346e2d4fa693c49cb7419917bf Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Tue, 28 Apr 2020 18:54:39 +0000 Subject: image_types_ota: use named reference Use named reference when deploying the device tree. This makes sure that this reference will end up in the deployments .origin file, which will be visible by the user in ostree admin status. This reference will also be used when running ostree admin upgrade. This is not really required when using aktualizr, but can be useful during test/debugging when using pure OSTree updates. Make sure to make ${OSTREE_REPO} accessible via http and add a remote on the device called ${OSTREE_OSNAME} pointing to the http exposed archive OSTree. With that ostree admin upgrade should work. Note: We could use the name reference in ostree pull-local already, but this is potentially racy if multiple builds are committing to the same branch. Use the OSTree commit hash to get the actual commit and recreate a local reference to this commit. This makes absolutely sure that we use the same OSTree commit this bitbake execution committed during the do_image_ostreecommit task. Signed-off-by: Stefan Agner --- classes/image_types_ota.bbclass | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/classes/image_types_ota.bbclass b/classes/image_types_ota.bbclass index 56c7794..a8a19b5 100644 --- a/classes/image_types_ota.bbclass +++ b/classes/image_types_ota.bbclass @@ -66,13 +66,23 @@ IMAGE_CMD_ota () { ostree_target_hash=$(cat ${WORKDIR}/ostree_manifest) + # Use OSTree hash to avoid any potential race conditions between + # multiple builds accessing the same ${OSTREE_REPO}. ostree --repo=${OTA_SYSROOT}/ostree/repo pull-local --remote=${OSTREE_OSNAME} ${OSTREE_REPO} ${ostree_target_hash} kargs_list="" for arg in ${OSTREE_KERNEL_ARGS}; do kargs_list="${kargs_list} --karg-append=$arg" done - ostree admin --sysroot=${OTA_SYSROOT} deploy ${kargs_list} --os=${OSTREE_OSNAME} ${ostree_target_hash} + # Create the same reference on the device we use in the archive OSTree + # repo in ${OSTREE_REPO}. This reference will show up when showing the + # deployment on the device: + # ostree admin status + # If a remote with the name ${OSTREE_OSNAME} is configured, this also + # will allow to use: + # ostree admin upgrade + ostree --repo=${OTA_SYSROOT}/ostree/repo refs --create=${OSTREE_OSNAME}:${OSTREE_BRANCHNAME} ${ostree_target_hash} + ostree admin --sysroot=${OTA_SYSROOT} deploy ${kargs_list} --os=${OSTREE_OSNAME} ${OSTREE_OSNAME}:${OSTREE_BRANCHNAME} cp -a ${IMAGE_ROOTFS}/var/sota ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true # Create /var/sota if it doesn't exist yet -- cgit v1.2.3-54-g00ecf