jjb: Add job for building Ubuntu images
[lttng-ci.git] / pipelines / images / distrobuild.sh
index 7c2e161d841b5d7eb02bcf46a4ed9f4619c3f13f..fea1d13655e2057a54f533c2eb984315e03d0032 100644 (file)
@@ -52,7 +52,7 @@ if [[ ! "${MISSING_VARS}" == "0" ]] ; then
 fi
 
 # Optional variables
-INSTANCE_START_TIMEOUT="${INSTANCE_START_TIMEOUT:-30}"
+INSTANCE_START_TIMEOUT="${INSTANCE_START_TIMEOUT:-120}"
 VM_ARG=()
 
 # Install lxd-client
@@ -81,7 +81,7 @@ fi
 
 # Get go
 apt-get install -y wget
-wget "https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz" -O - | tar -C /usr/local -xzf -
+wget -q "https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz" -O - | tar -C /usr/local -xzf -
 export PATH="${PATH}:/usr/local/go/bin"
 
 # Install distrobuilder
@@ -129,6 +129,16 @@ if [[ "${IMAGE_FILE}" == "" ]] ; then
     fail 1 "Unable to find image file for '${OS}' in ${IMAGE_DIRS[@]}"
 fi
 
+if grep -q -E 'XX[A-Za-z0-9_]+XX' "${IMAGE_FILE}" ; then
+    while read -r VAR ; do
+        echo "${VAR}"
+        SHELLVAR=$(echo "${VAR}" | sed 's/^XX//g' | sed 's/XX$//g')
+        set +x
+        sed -i "s/${VAR}/${!SHELLVAR:-VARIABLENOTFOUND}/g" "${IMAGE_FILE}"
+        set -x
+    done < <(grep -E -o 'XX[A-Za-z0-9_]+XX' "${IMAGE_FILE}")
+fi
+
 DISTROBUILDER_ARGS=(
     distrobuilder
     build-incus
@@ -181,18 +191,27 @@ if [[ "${ARCH}" == "i386" ]] ; then
     rm -rf "${TMP_DIR}"
 fi
 
-lxc image import "${BUILD_DIR}/incus.tar.xz" "${ROOTFS}" --alias="${IMAGE_NAME}" ci:
+# When using `lxc image import` two images cannot have the same alias -
+# 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}"
+
+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=''
@@ -209,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}"
This page took 0.023719 seconds and 4 git commands to generate.