From eedbfe3d49ade2c2415528bfc1fdc9d8533774f2 Mon Sep 17 00:00:00 2001 From: Mohammad Durrani <46766905+mdurrani808@users.noreply.github.com> Date: Sat, 31 Dec 2022 19:24:37 -0500 Subject: [PATCH] Generate limelight + Photon images (#669) * change to 64 bit image generation * Generate LL and Pi images in workflow * Update main.yml * Update main.yml * Update main.yml * REVERTME yeet publish * Update main.yml * Add archive suffix to generator * Bump base images to beta 3 * Add more error prints to image gen * Fix image base URL * Bump pi/LL base images * Update main.yml Co-authored-by: Matt Co-authored-by: Chris Gerth --- .github/workflows/main.yml | 49 +++++++++++++++++++++++++++++--------- scripts/generatePiImage.sh | 44 +++++++++++++++++++++++++++------- 2 files changed, 74 insertions(+), 19 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2af036bb8..6ae350df7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -375,30 +375,57 @@ jobs: ./gradlew photon-server:shadowJar --max-workers 2 if: ${{ (matrix.arch-override == 'none') }} - # The image will only pull the Pi32 JAR in - - name: Generate image - if: ${{ github.event_name != 'pull_request' && (matrix.artifact-name) == 'LinuxArm32' }} - run: | - chmod +x scripts/generatePiImage.sh - ./scripts/generatePiImage.sh - # Upload final fat jar as artifact. - uses: actions/upload-artifact@v3 with: name: jar-${{ matrix.artifact-name }} path: photon-server/build/libs - # Upload image as well + + photon-image-generator: + needs: [photon-build-package] + if: ${{ github.event_name != 'pull_request' }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + artifact-name: LinuxArm64 + image_suffix: raspi + image_url: https://api.github.com/repos/photonvision/photon-pi-gen/releases/tags/v2023.1.0-beta-4_arm64 + - os: ubuntu-latest + artifact-name: LinuxArm64 + image_suffix: limelight + image_url: https://api.github.com/repos/photonvision/photon-pi-gen/releases/tags/v2023.1.0-beta-5_limelight-arm64 + + runs-on: ${{ matrix.os }} + name: "Build image - ${{ matrix.image_url }}" + + steps: + # Checkout code. + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: actions/download-artifact@v2 + with: + name: jar-${{ matrix.artifact-name }} + + - name: Generate image + run: | + chmod +x scripts/generatePiImage.sh + ./scripts/generatePiImage.sh ${{ matrix.image_url }} ${{ matrix.image_suffix }} - uses: actions/upload-artifact@v3 - if: ${{ github.event_name != 'pull_request' && (matrix.artifact-name) == 'LinuxArm32' }} + name: Upload image with: - name: image-${{ matrix.artifact-name }} + name: image-${{ matrix.image_suffix }} path: photonvision*.xz photon-release: - needs: [photon-build-package] + needs: [photon-build-package, photon-image-generator] runs-on: ubuntu-22.04 steps: # Download literally every single artifact. This also downloads client and docs, diff --git a/scripts/generatePiImage.sh b/scripts/generatePiImage.sh index 02590cc7c..813b4bbd4 100755 --- a/scripts/generatePiImage.sh +++ b/scripts/generatePiImage.sh @@ -1,23 +1,47 @@ -# We need to look for a JAR with the "-raspi" suffix so we don't accidentally bundle the big jar -# Not that it really matters, but it'll save us 50 megs or so -NEW_JAR=$(realpath $(find . -name photonvision\*-linuxarm32.jar)) +if [ "$#" -ne 2 ]; then + echo "Illegal number of parameters -- expected (Image release URL) (image suffix)" + exit 1 +fi + +# 1st arg should be the release to download the image template from. The release ought to only have one +# artifact for a "xz" image. + +NEW_JAR=$(realpath $(find . -name photonvision\*-linuxarm64.jar)) echo "Using jar: " $NEW_JAR +echo "Downloading image from" $1 sudo apt-get install -y xz-utils -curl -sk https://api.github.com/repos/photonvision/photon-pi-gen/releases/tags/v2023.1.0-beta-1 | grep "browser_download_url.*xz" | cut -d : -f 2,3 | tr -d '"' | wget -qi - +curl -sk $1 | grep "browser_download_url.*xz" | cut -d : -f 2,3 | tr -d '"' | wget -qi - ls FILE_NAME=$(ls | grep image_*.xz) -echo "Downloaded " $FILE_NAME + +if [ -z "$FILE_NAME" ] +then + echo "Could not locate image archive!" + exit 1 +fi + +echo "Downloaded " $FILE_NAME " -- decompressing now..." xz -T0 -v --decompress $FILE_NAME IMAGE_FILE=$(ls | grep *.img) ls -echo "Unziped image: " $IMAGE_FILE + +if [ -z "$FILE_NAME" ] +then + echo "Could not locate unzipped image!" + exit 1 +fi + +echo "Unziped image: " $IMAGE_FILE " -- mounting" TMP=$(mktemp -d) LOOP=$(sudo losetup --show -fP "${IMAGE_FILE}") +echo "Image mounted! Copying jar..." sudo mount ${LOOP}p2 $TMP pushd . cd $TMP/opt/photonvision sudo cp $NEW_JAR photonvision.jar +echo "Jar updated! Creating service..." + cd $TMP/etc/systemd/system/multi-user.target.wants sudo bash -c "printf \ \"[Unit] @@ -35,9 +59,13 @@ RestartSec=1 WantedBy=multi-user.target\" > photonvision.service" popd + +echo "Service created!" + sudo umount ${TMP} sudo rmdir ${TMP} -NEW_IMAGE=$(basename "${NEW_JAR/jar/img}") +NEW_IMAGE=$(basename "${NEW_JAR/.jar/_$2.img}") +echo "Renaming image " $IMAGE_FILE " -> " $NEW_IMAGE mv $IMAGE_FILE $NEW_IMAGE xz -T0 -v -z $NEW_IMAGE -mv $NEW_IMAGE.xz $(basename "${NEW_JAR/.jar/-image.xz}") +mv $NEW_IMAGE.xz $(basename "${NEW_JAR/.jar/-image_$2.xz}")