Skip to content

Commit 55f6e4d

Browse files
authored
Accept-tar-files-for-images (#2)
* update capacity after truncation * add processing for tar files * don't call any partition modifiers when offset specified * fix extra directory in tar file
1 parent 4c90a9d commit 55f6e4d

File tree

5 files changed

+79
-17
lines changed

5 files changed

+79
-17
lines changed

.github/workflows/test-rubikpi.yml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- uses: actions/checkout@v4
1515
- uses: ./
1616
with:
17-
image_url: https://people.canonical.com/~platform/images/qualcomm-iot/rubikpi3/ubuntu-server-24.04/x00/ubuntu-24.04-preinstalled-server-arm64+rubikpi3-20250912-127.yaml
17+
image_url: https://people.canonical.com/~platform/images/qualcomm-iot/rubikpi3/ubuntu-server-24.04/x01/ubuntu-24.04-preinstalled-server-arm64+rubikpi3-20250926-145.yaml
1818
minimum_free_mb: 2000
1919
root_location: "offset=569376768"
2020
shrink_image: "no"
@@ -27,21 +27,27 @@ jobs:
2727
- name: Compress image
2828
run: |
2929
imagedir=$(dirname ${{ steps.build_image.outputs.image }})
30-
tardir=${RUNNER_TEMP}/photonvision_rubikpi3
30+
tardir=photonvision_rubikpi3_fromYAML
3131
mkdir --parents ${tardir}
32-
if ls ${imagedir}*.tar.gz 1>/dev/null 2>&1; then
33-
sudo tar -xzf ${imagedir}*.tar.gz -C ${tardir}
32+
echo "Contents of imagedir: ${imagedir}"
33+
ls -la ${imagedir}
34+
if ls ${imagedir}/*.tar.gz 1>/dev/null 2>&1; then
35+
sudo tar -xzf ${imagedir}/*.tar.gz -C ${tardir}
3436
fi
3537
sudo mv ${imagedir}/rawprogram*.xml ${tardir}/ 2>/dev/null || true
3638
sudo mv ${imagedir}/dtb.bin ${tardir}/ 2>/dev/null || true
3739
sudo mv ${imagedir}/*.img ${tardir}/ 2>/dev/null || true
40+
echo "Before cleanup contents of tardir: ${tardir}"
41+
ls -la ${tardir}
3842
sudo find ${tardir} -mindepth 2 -type f -exec mv {} ${tardir}/ \;
3943
sudo find ${tardir} -mindepth 1 -type d -empty -delete
40-
sudo tar -I 'xz -T0' -cf ./photonvision_rubikpi3.tar.xz ${tardir} --checkpoint=10000 --checkpoint-action=echo='%T'
44+
echo "After cleanup contents of tardir: ${tardir}"
45+
ls -la ${tardir}
46+
sudo tar -I 'xz -T0' -cf ./photonvision_rubikpi3_fromYAML.tar.xz ${tardir} --checkpoint=10000 --checkpoint-action=echo='%T'
4147
- uses: actions/upload-artifact@v4
4248
with:
43-
name: photonvision_rubikpi3.tar.xz
44-
path: ./photonvision_rubikpi3.tar.xz
49+
name: photonvision_rubikpi3_fromYAML.tar.xz
50+
path: ./photonvision_rubikpi3_fromYAML.tar.xz
4551
compression-level: 0
4652
if-no-files-found: error
4753
retention-days: 1

.github/workflows/test-tar.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: 'Test modifying a Rubik Pi tar image'
2+
on:
3+
push:
4+
branches:
5+
- 'main'
6+
- 'releases/**'
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-24.04-arm
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: ./
16+
with:
17+
image_url: https://github.com/PhotonVision/photon-image-modifier/releases/download/v2026.0.4/photonvision_rubikpi3.tar.xz
18+
minimum_free_mb: 2000
19+
root_location: "offset=569376768"
20+
shrink_image: "no"
21+
commands: |
22+
echo "Testing Rubik Pi tar image"
23+
uname -a
24+
lsblk
25+
echo "${loopdev}"
26+
id: build_image
27+
- name: Compress image
28+
run: |
29+
imagedir=$(dirname ${{ steps.build_image.outputs.image }})
30+
echo "Imagedir: ${imagedir}"
31+
ls -la ${imagedir}
32+
tardir=photonvision_rubikpi3_fromTAR
33+
mkdir --parents ${tardir}
34+
echo "Tardir: ${tardir}"
35+
ls -la ${tardir}
36+
sudo mv ${imagedir}/* ${tardir}/
37+
echo "After move"
38+
ls -la ${tardir}
39+
sudo tar -I 'xz -T0' -cf ./photonvision_rubikpi3_fromTAR.tar.xz ${tardir} --checkpoint=10000 --checkpoint-action=echo='%T'
40+
- uses: actions/upload-artifact@v4
41+
with:
42+
name: photonvision_rubikpi3_fromTAR.tar.xz
43+
path: ./photonvision_rubikpi3_fromTAR.tar.xz
44+
compression-level: 0
45+
if-no-files-found: error
46+
retention-days: 1
47+
48+

get_image.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
set -euo pipefail
2+
set -euxo pipefail
33

44
url=$1
55
download_path="${RUNNER_TEMP}/image"
@@ -30,16 +30,23 @@ else
3030
fi
3131

3232
echo "Image: ${image}"
33-
34-
ls -l ${download_path}
33+
ls -la ${download_path}
3534

3635
if [[ ${image} = *.xz ]]; then
3736
echo "Unzipping ${image}"
3837
unxz ${image}
3938
image=${image%.xz}
4039
fi
4140

42-
ls -l ${download_path}
41+
if [[ ${image} = *.tar ]]; then
42+
echo "Untarring ${image}"
43+
tar -xf ${image}
44+
rm ${image}
45+
image=$(find . -type f \( -name '*.img' \) -exec ls -s {} + 2>/dev/null | sort -rn | head -n1 | awk '{print $2}')
46+
fi
47+
48+
echo "Image: ${image}"
49+
ls -la $(dirname ${image})
4350

4451
if [[ ${image} != *.img ]]; then
4552
echo "${image} isn't a valid image file"

mount_image.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
set -euo pipefail
2+
set -euxo pipefail
33

44
image="$1"
55
additional_mb=$2
@@ -17,7 +17,7 @@ case ${root_location,,} in
1717
rootdev="${loopdev}p${rootpartition}"
1818
;;
1919
offset* )
20-
rootpartition=1
20+
rootpartition=0
2121
rootoffset=${root_location#*=}
2222
loopdev=$(losetup --find --show --offset=${rootoffset} ${image})
2323
rootdev="${loopdev}"
@@ -65,9 +65,9 @@ if [[ ${additional_mb} -gt 0 ]]; then
6565
fi
6666
if [[ ${rootpartition} -gt 0 ]]; then
6767
parted --script "${loopdev}" resizepart ${rootpartition} 100%
68+
e2fsck -p -f "${rootdev}"
69+
resize2fs "${rootdev}"
6870
fi
69-
e2fsck -p -f "${rootdev}"
70-
resize2fs "${rootdev}"
7171
echo "Finished resizing disk image."
7272
fi
7373

pack_image.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
set -euo pipefail
2+
set -euxo pipefail
33

44
####
55
# Clean up and shrink image
@@ -16,7 +16,7 @@ echo "Zero filling empty space"
1616

1717
umount --recursive "${rootdir}"
1818

19-
if [[ ${shrink,,} = y* ]]; then
19+
if [[ ${shrink,,} = y* && ${rootpartition} -gt 0 ]]; then
2020
echo "Resizing root filesystem to minimal size."
2121
e2fsck -v -f -p -E discard "${rootdev}"
2222
resize2fs -M "${rootdev}"
@@ -45,6 +45,7 @@ if [[ ${shrink,,} = y* ]]; then
4545
fi
4646
echo "Shrinking image from ${initial_image_size} to ${image_size} bytes."
4747
truncate -s "${image_size}" "${image}"
48+
losetup --set-capacity "${loopdev}"
4849
if [[ "${part_type}" == "gpt" ]]; then
4950
# use sgdisk to fix the secondary GPT after truncation
5051
sgdisk -e "${image}"

0 commit comments

Comments
 (0)