jjb: Test newly published images before changing aliases
authorKienan Stewart <kstewart@efficios.com>
Thu, 1 Feb 2024 18:46:37 +0000 (13:46 -0500)
committerKienan Stewart <kstewart@efficios.com>
Fri, 2 Feb 2024 14:07:03 +0000 (09:07 -0500)
Change-Id: I20d8eaf171508ff43cf31b7d89b271741fdf323b
Signed-off-by: Kienan Stewart <kstewart@efficios.com>
pipelines/images/distrobuild.sh
pipelines/images/imagebuild.sh

index f02fd54935074c0ec117c97f2f601c94f1a11d9a..5dceb73b9012df34572a219434aa4ec62a360026 100644 (file)
@@ -195,18 +195,23 @@ fi
 # only the last image imported will keep the alias. Therefore, the
 # image type is appended as part of the alias.
 IMAGE_NAME="${IMAGE_NAME}/${IMAGE_TYPE}"
-lxc image import "${BUILD_DIR}/incus.tar.xz" "${ROOTFS}" --alias="${IMAGE_NAME}" ci:
+
+if FINGERPRINT=$(lxc image import "${BUILD_DIR}/incus.tar.xz" "${ROOTFS}" 2>&1 | grep -E -o '[A-Fa-f0-9]{64}') ; then
+    echo "Image imported with fingerprint '${FINGERPRINT}'"
+else
+    fail 1 "No fingerprint for imported image"
+fi
 
 if [[ "${TEST}" == "true" ]] ; then
     set +e
     INSTANCE_NAME=''
-    if INSTANCE_NAME="$(lxc -q launch -e ${VM_ARG[@]} -p default -p "${LXD_INSTANCE_PROFILE}" "${IMAGE_NAME}")" ; then
+    if INSTANCE_NAME="$(lxc -q launch -e ${VM_ARG[@]} -p default -p "${LXD_INSTANCE_PROFILE}" "${FINGERPRINT}")" ; then
         INSTANCE_NAME="$(echo "${INSTANCE_NAME}" | cut -d':' -f2 | tr -d ' ')"
         CLEANUP+=(
-            "lxc stop ${INSTANCE_NAME}"
+            "lxc stop -f ${INSTANCE_NAME}"
         )
     else
-        fail 1 "Failed to launch instance using image '${IMAGE_NAME}'"
+        fail 1 "Failed to launch instance using image '${FINGERPRINT}'"
     fi
     TIME_REMAINING="${INSTANCE_START_TIMEOUT}"
     INSTANCE_STATUS=''
@@ -223,3 +228,6 @@ if [[ "${TEST}" == "true" ]] ; then
     done
     set -e
 fi
+
+lxc image alias delete "${IMAGE_NAME}" || true
+lxc image alias create "${IMAGE_NAME}" "${FINGERPRINT}"
index 1b36a0331f5d6290493742957d4089c1fe0f6c2d..8731e1517c6669ecd4d04712a988029fd7c3d8f8 100644 (file)
@@ -111,7 +111,7 @@ INSTANCE_NAME="$(echo "${INSTANCE_NAME}" | cut -d ':' -f 2 | tr -d ' ')"
 set -e
 
 CLEANUP+=(
-    "lxc stop ${INSTANCE_NAME}"
+    "lxc stop -f ${INSTANCE_NAME}"
 )
 
 # VMs may take more time to start, wait until instance is running
@@ -197,21 +197,25 @@ LANG=C ANSIBLE_STRATEGY=linear ansible-playbook \
        -l "${INSTANCE_IP}" -i fake-inventory
 
 # Publish
-lxc publish "${INSTANCE_NAME}" --alias "${TARGET_IMAGE_NAME}" -f
+if FINGERPRINT=$(lxc publish "${INSTANCE_NAME}" -f 2>&1 | grep -E -o '[A-Fa-f0-9]{64}') ; then
+    echo "Published instance with fingerprint '${FINGERPRINT}'"
+else
+    fail 1 "No fingerprint for published instance"
+fi
 
 TRIES=0
 
 if [[ "${TEST}" == "true" ]] ; then
     set +e
     while [[ "${TRIES}" -lt "${TRIES_MAX}" ]] ; do
-        if ! INSTANCE_NAME=$(lxc -q launch -e "${VM_ARG[@]}" -p default -p "${LXD_INSTANCE_PROFILE}" "${TARGET_IMAGE_NAME}")  ; then
+        if ! INSTANCE_NAME=$(lxc -q launch -e "${VM_ARG[@]}" -p default -p "${LXD_INSTANCE_PROFILE}" "${FINGERPRINT}")  ; then
             TRIES=$((TRIES + 1))
             echo "Failed to launch instance try ${TRIES}/${TRIES_MAX}"
             if [[ "${TRIES}" -lt "${TRIES_MAX}" ]] ; then
                 sleep $((1 + RANDOM % 10))
                 continue
             fi
-            fail 1 "Failed to launch an instance using newly published image '${TARGET_IMAGE_NAME}'"
+            fail 1 "Failed to launch an instance using newly published image '${FINGERPRINT}'"
         else
             INSTANCE_NAME="$(echo "${INSTANCE_NAME}" | cut -d':' -f2 | tr -d ' ')"
             CLEANUP+=(
@@ -222,3 +226,6 @@ if [[ "${TEST}" == "true" ]] ; then
     done
     set -e
 fi
+
+lxc image alias delete "${TARGET_IMAGE_NAME}" || true
+lxc image alias create "${TARGET_IMAGE_NAME}" "${FINGERPRINT}"
This page took 0.027228 seconds and 4 git commands to generate.