jjb: Gently stop instances before publication
authorKienan Stewart <kstewart@efficios.com>
Tue, 20 Feb 2024 19:31:48 +0000 (14:31 -0500)
committerKienan Stewart <kstewart@efficios.com>
Wed, 21 Feb 2024 12:50:53 +0000 (07:50 -0500)
Avoids potential issues with changes not being fully written to disk
in teh result image.

Change-Id: I0dab01038870cbc798560863de1971a3a124983a
Signed-off-by: Kienan Stewart <kstewart@efficios.com>
automation/ansible/playbooks/post-imagebuild-clean.yml
pipelines/images/imagebuild.sh

index 4a352fc24db60c1c18a83cf2f268fe261e25fb3e..d26490a3392ec6d92fef11892d06f4953732773f 100644 (file)
@@ -16,6 +16,8 @@
     - ansible.builtin.command:
         argv: ['cloud-init', 'clean']
       ignore_errors: true
+    - ansible.built.command:
+        argv: ['sync']
     - ansible.builtin.shell:
         cmd: 'history -cw'
       # Some default shells don't have the `history` built-in,
index 5a2693027d09f27c6aab02b8d3bae87d90a729ce..45632c0514c365dd0811a5eac196c5c5158825c8 100644 (file)
@@ -91,9 +91,9 @@ set +e
 TRIES_MAX=3
 TRIES=0
 while [[ "${TRIES}" -lt "${TRIES_MAX}" ]] ; do
-    if ! INSTANCE_NAME=$(lxc -q launch -e "${VM_ARG[@]}" -p default -p "${LXD_INSTANCE_PROFILE}" "${SOURCE_IMAGE_NAME}/${IMAGE_TYPE}") ; then
+    if ! INSTANCE_NAME=$(lxc -q launch "${VM_ARG[@]}" -p default -p "${LXD_INSTANCE_PROFILE}" "${SOURCE_IMAGE_NAME}/${IMAGE_TYPE}") ; then
         # Try from images
-        if ! INSTANCE_NAME=$(lxc -q launch -e "${VM_ARG[@]}" -p default -p "${LXD_INSTANCE_PROFILE}" images:"${SOURCE_IMAGE_NAME}") ; then
+        if ! INSTANCE_NAME=$(lxc -q launch "${VM_ARG[@]}" -p default -p "${LXD_INSTANCE_PROFILE}" images:"${SOURCE_IMAGE_NAME}") ; then
             TRIES=$((TRIES + 1))
             echo "Failed to deployed ephemereal instance attempt ${TRIES}/${TRIES_MAX}"
             if [[ "${TRIES}" -lt  "${TRIES_MAX}" ]] ; then
@@ -111,7 +111,8 @@ INSTANCE_NAME="$(echo "${INSTANCE_NAME}" | cut -d ':' -f 2 | tr -d ' ')"
 set -e
 
 CLEANUP+=(
-    "lxc stop -f ${INSTANCE_NAME}"
+    "lxc delete -f ${INSTANCE_NAME}"
+    "lxc stop ${INSTANCE_NAME}"
 )
 
 # VMs may take more time to start, wait until instance is running
@@ -196,8 +197,11 @@ LANG=C ANSIBLE_STRATEGY=linear ansible-playbook \
        playbooks/post-imagebuild-clean.yml \
        -l "${INSTANCE_IP}" -i fake-inventory
 
+# Graceful shutdown
+lxc stop "${INSTANCE_NAME}"
+
 # Publish
-if FINGERPRINT=$(lxc publish "${INSTANCE_NAME}" -f 2>&1 | grep -E -o '[A-Fa-f0-9]{64}') ; then
+if FINGERPRINT=$(lxc publish "${INSTANCE_NAME}" 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"
This page took 0.026359 seconds and 4 git commands to generate.