From c4c1b5800f4f74fb809f885d373b4f27e84099a8 Mon Sep 17 00:00:00 2001 From: Kyle Harding Date: Fri, 1 Nov 2024 15:56:01 -0400 Subject: [PATCH] Use NFS cache as a mirror only Change-type: minor Signed-off-by: Kyle Harding --- .github/workflows/yocto-build-deploy.yml | 46 ++++++++++++++++-------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/.github/workflows/yocto-build-deploy.yml b/.github/workflows/yocto-build-deploy.yml index f87fe6cb1..79b4f3a78 100644 --- a/.github/workflows/yocto-build-deploy.yml +++ b/.github/workflows/yocto-build-deploy.yml @@ -186,10 +186,6 @@ jobs: automation_dir: "${{ github.workspace }}/balena-yocto-scripts/automation" BALENARC_BALENA_URL: ${{ vars.BALENA_HOST || inputs.deploy-environment || 'balena-cloud.com' }} API_ENV: ${{ vars.BALENA_HOST || inputs.deploy-environment || 'balena-cloud.com' }} - - # Yocto NFS sstate cache host - YOCTO_CACHE_HOST: ${{ vars.YOCTO_CACHE_HOST || 'nfs.product-os.io' }} - YOCTO_CACHE_DIR: ${{ github.workspace }}/shared/yocto-cache BARYS_ARGUMENTS_VAR: "" outputs: @@ -446,17 +442,34 @@ jobs: BARYS_ARGUMENTS_VAR="${BARYS_ARGUMENTS_VAR} --bitbake-args --no-setscene" echo "BARYS_ARGUMENTS_VAR=${BARYS_ARGUMENTS_VAR}" >>"${GITHUB_ENV}" - # the directory is required even if we don't mount the NFS share - - name: Create shared cache mount point - run: | - sudo mkdir -p "${YOCTO_CACHE_DIR}/$(whoami)" - sudo chown -R "$(id -u):$(id -g)" "${YOCTO_CACHE_DIR}" - + # https://wiki.yoctoproject.org/wiki/Enable_sstate_cache + # https://docs.yoctoproject.org/4.0.10/ref-manual/variables.html#term-MIRRORS + # https://docs.yoctoproject.org/4.0.10/ref-manual/variables.html#term-PREMIRRORS + # https://docs.yoctoproject.org/4.0.10/ref-manual/variables.html#term-SSTATE_MIRRORS - name: Mount shared NFS cache - if: env.YOCTO_CACHE_HOST != '' && contains(fromJSON(inputs.build-runs-on), 'self-hosted') + if: vars.YOCTO_CACHE_HOST && contains(fromJSON(inputs.build-runs-on), 'self-hosted') + # continue-on-error: true + env: + YOCTO_CACHE_HOST: ${{ vars.YOCTO_CACHE_HOST }} + MOUNTPOINT: /nfs/yocto run: | - sudo mount -t nfs "${YOCTO_CACHE_HOST}:/" "${YOCTO_CACHE_DIR}" -o fsc,nolock - ls -al "${YOCTO_CACHE_DIR}/$(whoami)" + sudo mkdir -p "${MOUNTPOINT}" + sudo chown -R "$(id -u):$(id -g)" "${MOUNTPOINT}" + sudo mount -t nfs "${YOCTO_CACHE_HOST}:/" "${MOUNTPOINT}" -o fsc,nolock + + mkdir -p conf + cat <> conf/auto.conf + SSTATE_MIRRORS:prepend = " + file://.* file://${MOUNTPOINT}/$(whoami)/${MACHINE}/sstate/PATH" + + PREMIRRORS:prepend = " + git://.*/.* file://${MOUNTPOINT}/$(whoami)/shared-downloads/ + ftp://.*/.* file://${MOUNTPOINT}/$(whoami)/shared-downloads/ + http://.*/.* file://${MOUNTPOINT}/$(whoami)/shared-downloads/ + https://.*/.* file://${MOUNTPOINT}/$(whoami)/shared-downloads/" + + BB_NO_NETWORK=1 + EOF # All preperation complete before this step # Start building balenaOS @@ -466,6 +479,7 @@ jobs: id: build env: HELPER_IMAGE_REPO: ghcr.io/balena-os/balena-yocto-scripts + SHARED_BUILD_DIR: ${{ github.workspace }}/shared run: | # When building for non-x86 device types, meson, after building binaries must try to run them via qemu if possible , maybe as some sanity check or test? # Therefore qemu must be used - and our runner mmap_min_addr is set to 4096 (default, set here: https://github.com/product-os/github-runner-kernel/blob/ef5a66951599dc64bf2920d896c36c6d9eda8df6/config/5.10/microvm-kernel-x86_64-5.10.config#L858 @@ -475,10 +489,14 @@ jobs: sudo sysctl -w vm.mmap_min_addr=65536 sysctl vm.mmap_min_addr + mkdir -p "${SHARED_BUILD_DIR}" + + cat conf/auto.conf + ./balena-yocto-scripts/build/balena-build.sh \ -d "${MACHINE}" \ -t "${{ secrets.BALENA_API_DEPLOY_KEY }}" \ - -s "${YOCTO_CACHE_DIR}/$(whoami)" \ + -s "${SHARED_BUILD_DIR}" \ -g "${BARYS_ARGUMENTS_VAR}" if grep -R "ERROR: " build/tmp/log/*; then