Skip to content

Commit 9fc77d4

Browse files
committed
feat(ci: build-ami.yaml): Get list of installed packages from RAW or QCOW2 image
1 parent 9492ab1 commit 9fc77d4

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

.github/actions/shared-steps/action.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,56 @@ runs:
380380
# - name: Setup tmate session
381381
# uses: mxschmitt/action-tmate@v3
382382

383+
- name: List installed packages in ${{ env.IMAGE_FILE }} cloud image
384+
if: ${{ ! contains(inputs.type, 'vagrant') }}
385+
shell: bash
386+
run: |
387+
# List installed packages in ${{ env.IMAGE_FILE }} image
388+
case ${{ inputs.arch }} in
389+
x86_64*) partition=4 ;;
390+
aarch64*) partition=3 ;;
391+
*) false ;;
392+
esac
393+
394+
case ${{ inputs.type }} in
395+
oci|gencloud|opennebula) format=qcow2 ;;
396+
azure) format=raw ;;
397+
*) false ;;
398+
esac
399+
rootfs_path=/mnt/rootfs
400+
sudo mkdir -p ${rootfs_path}
401+
402+
# Install qemu-utils
403+
sudo ${{ env.runner_os == 'ubuntu' && 'apt-get' || 'dnf -q' }} \
404+
-y install \
405+
${{ env.runner_os == 'ubuntu' && 'qemu-utils' || 'qemu-img' }}
406+
407+
# Load nbd kernel module
408+
sudo modprobe nbd max_part=8
409+
410+
# Make a copy of the image file
411+
sudo cp ${{ env.IMAGE_FILE }} $(dirname ${rootfs_path})
412+
413+
# Attach the image file to the nbd device
414+
sudo qemu-nbd \
415+
--read-only \
416+
--format=${format} \
417+
--connect=/dev/nbd0 \
418+
$(dirname ${rootfs_path})/$(basename ${{ env.IMAGE_FILE }}) \
419+
&& sleep 10 || false
420+
421+
# Mount need partition
422+
sudo fdisk -l /dev/nbd0
423+
sudo mount /dev/nbd0p${partition} ${rootfs_path} \
424+
&& sleep 10 || false
425+
426+
# Get installed packages list
427+
sudo sh -c "rpm --dbpath=${rootfs_path}/var/lib/rpm -qa --queryformat '%{NAME}\n' | sort > ${{ env.IMAGE_FILE }}.txt"
428+
429+
[ -f ${{ env.IMAGE_FILE }}.txt ] \
430+
&& echo "got_pkgs_list=true" >> $GITHUB_ENV \
431+
|| echo "got_pkgs_list=false" >> $GITHUB_ENV
432+
383433
- name: Test ${{ inputs.type }} ${{ inputs.variant }} image
384434
if: inputs.run_test == 'true'
385435
shell: bash

0 commit comments

Comments
 (0)