Skip to content

Build Image

Build Image #714

Workflow file for this run

name: Build Image
on:
workflow_dispatch:
inputs:
build_alpha:
description: 'Alpha build true/false default: false'
required: false
default: false
push:
branches:
- mrbeam2-stable
paths-ignore:
- '*.rst'
- '*.md'
pull_request:
branches: [develop, mrbeam2-stable]
env:
VARIANT: beamos
jobs:
set_matrix:
name: Configure the matrix of image flavors to build.
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- id: set-matrix
if:
run: |
if [ "${{ github.event.inputs.build_alpha }}" = "true" ]
then
flavors='{"flavor":"alpha 2Q"}'
else
flavors='{"flavor":"migrationOS"}'
fi
echo "matrix={\"include\":[$flavors]}" >> $GITHUB_OUTPUT
build:
needs: set_matrix
runs-on: ubuntu-latest
strategy:
matrix: ${{fromJson(needs.set_matrix.outputs.matrix)}}
# flavors: ["2S", "2R", "develop 2R"]
# flavors: ["develop 2S"]
steps:
- name: Install Dependencies
run: |
sudo apt update
sudo apt install coreutils p7zip-full qemu-user-static
- name: Configure SSH-Keys inside image
env:
SSH_KEY_MOUNTMANAGER: ${{ secrets.DEPLOY_KEY_MOUNTMANAGER }}
SSH_KEY_MRBCHECK: ${{ secrets.DEPLOY_KEY_MRBCHECK }}
SSH_KEY_BITBUCKET: ${{ secrets.BITBUCKET_ACCESS_KEY }}
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY_BITBUCKET" > ~/.ssh/bitbucket.key
echo "$SSH_KEY_MOUNTMANAGER" > ~/.ssh/mountmanager.key
echo "$SSH_KEY_MRBCHECK" > ~/.ssh/mrbcheck.key
chmod 600 ~/.ssh/bitbucket.key
chmod 600 ~/.ssh/mountmanager.key
chmod 600 ~/.ssh/mrbcheck.key
touch ~/.ssh/known_hosts
ssh-keygen -R bitbucket.org
ssh-keygen -R github.com
ssh-keyscan -H bitbucket.org >> ~/.ssh/known_hosts
ssh-keyscan -H github.com >> ~/.ssh/known_hosts
cat >>~/.ssh/config <<END
Host bitbucket.org
HostName bitbucket.org
IdentityFile ~/.ssh/bitbucket.key
Host github.com-mountmanager
HostName github.com
IdentityFile ~/.ssh/mountmanager.key
Host github.com-mrb_check
HostName github.com
IdentityFile ~/.ssh/mrbcheck.key
END
- name: Checkout CustomPiOS
uses: actions/checkout@v4
with:
repository: 'mrbeam/CustomPiOS'
path: CustomPiOS
ref: 'test_devpi_josef'
- name: Checkout Project Repository
uses: actions/checkout@v4
with:
submodules: recursive
path: repository
- name: Write submodule info to separate files outside chroot
run: |
cd repository
git --no-pager submodule foreach 'git branch | tail -n 1 | tee current_branch'
git --no-pager submodule foreach 'git rev-parse HEAD | tee current_commit_hash'
- name: Download Raspbian Image
run: |
cd repository/src/image
wget -c --trust-server-names 'https://downloads.raspberrypi.org/raspios_lite_armhf/images/raspios_lite_armhf-2021-05-28/2021-05-07-raspios-buster-armhf-lite.zip'
- name: Update CustomPiOS Paths
run: |
cd repository/src
../../CustomPiOS/src/update-custompios-paths
- name: Force apt mirror to work around intermittent mirror hiccups
run: |
echo "OCTOPI_APTMIRROR=http://mirror.us.leaseweb.net/raspbian/raspbian" > repository/src/config.local
- name: Download the Beam OS 2 Image
uses: actions-hub/gcloud@master
env:
PROJECT_ID: devpi-310008
APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_DOWNLOAD }}
with:
args: cp "${{ vars.BEAMOS2_IMAGE }}" repository/src/image/
cli: gsutil
- name: Extract the Beam OS 2 Image
id: extract_the_image
run: |
# Set the image file
the_image=$(basename "${{ vars.BEAMOS2_IMAGE }}")
source_dir="repository/src/image"
echo "The Beam OS 2 Image: ${the_image}"
target_dir="repository/src/modules/beamos/filesystem/migration/home/pi/image"
target_name="beamos2.wic"
# Extract bz2 file into target_dir
tar -xjf ${source_dir}/${the_image} -C $target_dir
# Rename the extracted image to beamos2.wic[bz2, bmap] and remove other files
mv ${target_dir}/mrbeam-image-*.wic.bz2 ${target_dir}/${target_name}.bz2
mv ${target_dir}/mrbeam-image-*.wic.bmap ${target_dir}/${target_name}.bmap
rm ${target_dir}/mrbeam-*
echo "Placed the image in ${target_dir}/${target_name}.bz2 with bmap file"
- name: Build Image (MrBeam Variant)
env:
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
run: |
sudo modprobe loop
cd repository/src
echo "export EXTRA_SSH_KEY='${{ secrets.SSH_BEAMOS01_RSA }}'" >> config
echo "export PERSONAL_ACCESS_TOKEN='${{ secrets.PERSONAL_ACCESS_TOKEN }}'" >> config
sudo bash -x ./build_dist $VARIANT ${{ matrix.flavor }}
- name: Copy output
id: copy
run: |
source repository/src/config
source repository/src/variants/beamos/config
NOW=$(date +"%Y-%m-%d-%H%M")
# When building a variant, it is built in workspace-$VARIANT
if [ -n $VARIANT ]; then
[ -n "${{ matrix.flavor }}" ] && FL="$(echo ${{ matrix.flavor }} | sed 's/ /-/g')-"
IMAGE=$NOW-$VARIANT-$FL$DIST_VERSION
BRANCH_NAME=${GITHUB_REF##*/}
if [[ "$BRANCH_NAME" != "mrbeam" ]]; then
IMAGE=$IMAGE-$BRANCH_NAME
fi
cp repository/src/workspace-$VARIANT/*.img $IMAGE.img
else
IMAGE=$NOW-octopi-$DIST_VERSION
cp repository/src/workspace/*.img $IMAGE.img
fi
echo "image=$IMAGE" >> $GITHUB_OUTPUT
# # artifact upload will take care of zipping for us
# - uses: actions/upload-artifact@v1
# # if: github.event_name == 'schedule'
# with:
# name: ${{ steps.copy.outputs.image }}
# path: ${{ steps.copy.outputs.image }}.img
- name: Compress output
run: |
zip -r ${{ steps.copy.outputs.image }}.zip ${{ steps.copy.outputs.image }}.img
- name: Create env variable for upload folder in gcloud bucket
run: |
# Use the last letter of the flavor for the directory name
echo "DIR=$(echo ${{ matrix.flavor }})" >> $GITHUB_ENV
- uses: actions-hub/gcloud@master
env:
PROJECT_ID: devpi-310008
APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
with:
args: cp ${{ steps.copy.outputs.image }}.zip gs://beamos_images/${{ env.DIR }}/
cli: gsutil