Build Rootfs #13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Rootfs | |
on: | |
workflow_dispatch: | |
inputs: | |
host-os: | |
required: false | |
type: string | |
default: ubuntu-22.04 | |
arch: | |
required: true | |
type: choice | |
options: | |
- x86_64 | |
- arm64 | |
use-cached: | |
required: false | |
type: boolean | |
default: false | |
workflow_call: | |
inputs: | |
host-os: | |
required: false | |
type: string | |
default: ubuntu-22.04 | |
arch: | |
required: true | |
type: string | |
use-cached: | |
required: false | |
type: boolean | |
default: true | |
jobs: | |
check-cache: | |
name: Check cache (${{ inputs.arch }}) | |
if: ${{ github.events.inputs.use-cached == 'true' }} | |
runs-on: ${{ inputs.host-os }} | |
outputs: | |
cache-hit: ${{ steps.cache-check.outputs.cache-hit }} | |
env: | |
ALPINE_ROOTFS: alpine-${{ inputs.arch }}.img | |
ALPINE_CPIO: alpine-${{ inputs.arch }}.cpio.gz | |
UBUNTU_ROOTFS: ubuntu-jammy-${{ inputs.arch }}.img | |
UBUNTU_CPIO: ubuntu-jammy-${{ inputs.arch }}.cpio.gz | |
steps: | |
- name: Restore cache for rootfs | |
id: cache-check | |
uses: actions/cache/restore@v4 | |
with: | |
key: rootfs-${{ inputs.arch }} | |
path: | | |
rootfs/${{ env.ALPINE_ROOTFS }} | |
rootfs/${{ env.UBUNTU_ROOTFS }} | |
rootfs/${{ env.ALPINE_CPIO }} | |
rootfs/${{ env.UBUNTU_CPIO }} | |
- name: Upload rootfs artifact | |
if: steps.cache-check.outputs.cache-hit == 'true' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: rootfs-${{ inputs.arch }} | |
path: | | |
rootfs/${{ env.ALPINE_ROOTFS }} | |
rootfs/${{ env.UBUNTU_ROOTFS }} | |
rootfs/${{ env.ALPINE_CPIO }} | |
rootfs/${{ env.UBUNTU_CPIO }} | |
rootfs: | |
name: rootfs (${{ inputs.arch }}) | |
needs: check-cache | |
if: inputs.use-cached == 'false' || needs.check-cache.outputs.cache-hit != 'true' | |
runs-on: ${{ inputs.host-os }} | |
env: | |
# ARCH isn't directly used by the workflow, but it is used by the `make` commands | |
ARCH: ${{ inputs.arch }} | |
ALPINE_ROOTFS: alpine-${{ inputs.arch }}.img | |
ALPINE_CPIO: alpine-${{ inputs.arch }}.cpio.gz | |
UBUNTU_ROOTFS: ubuntu-jammy-${{ inputs.arch }}.img | |
UBUNTU_CPIO: ubuntu-jammy-${{ inputs.arch }}.cpio.gz | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install common dependencies | |
run: sudo apt update && sudo apt install -y debootstrap qemu-utils | |
- name: Install arm64 dependencies | |
if: ${{ inputs.arch == 'arm64' }} | |
run: sudo apt install -y qemu-user-static binfmt-support | |
- name: Initialize rootfs and initramfs | |
shell: bash | |
run: | | |
set -x | |
make rootfs-init | |
# Test generating rootfs in non-standard location | |
ROOTFS=${ALPINE_ROOTFS} make rootfs-init | |
# Verify it matches previously generated rootfs | |
cmp ./${ALPINE_ROOTFS} ./rootfs/${ALPINE_ROOTFS} | |
# Generate ubuntu rootfs and cpio (with CPIO at a non-standard location) | |
scripts/ubuntu_debootstrap.sh jammy ${{ inputs.arch }} | |
SUDO=1 ROOTFS_DIR=./rootfs/ubuntu-jammy-${{ inputs.arch }} CPIO_FILE=${UBUNTU_CPIO} make rootfs-overlay | |
mv ./${UBUNTU_CPIO} rootfs/${UBUNTU_CPIO} | |
- name: Cache rootfs artifacts | |
uses: actions/cache/save@v4 | |
with: | |
key: rootfs-${{ inputs.arch }} | |
path: | | |
rootfs/${{ env.ALPINE_ROOTFS }} | |
rootfs/${{ env.UBUNTU_ROOTFS }} | |
rootfs/${{ env.ALPINE_CPIO }} | |
rootfs/${{ env.UBUNTU_CPIO }} | |
- name: Upload rootfs artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: rootfs-${{ inputs.arch }} | |
path: | | |
rootfs/${{ env.ALPINE_ROOTFS }} | |
rootfs/${{ env.UBUNTU_ROOTFS }} | |
rootfs/${{ env.ALPINE_CPIO }} | |
rootfs/${{ env.UBUNTU_CPIO }} |