From 7c01114b313cb9e8306fac71ebcb8e8318b90ad9 Mon Sep 17 00:00:00 2001 From: m2 <69128853+m2Giles@users.noreply.github.com> Date: Sun, 21 Jul 2024 14:20:16 -0400 Subject: [PATCH] chore(ci): Reduce copy layers (#269) * feat: Use cached kerneel feat: Used cached-kernel * fix: include repos * fix: typo, have sbverify test * fix: work on surface install * fix: surface is annoying * fix: surface package name * fix: get surface installing * fix: get surface installing * fix: another surface try * fix: surface, install from repo, replace vmlinuz * fix: more surface changes * chore(ci): Another iteration * chore: annother attempt * chore: another attempt * chore: again * fix: maybe closer? * closer * another attempt * more changes * missing variable * try combining into one block * spelling * consolidate * spelling * remove debug * chore(ci): Reduce copy layers by using mounts Signed-off-by: m2Giles <69128853+m2Giles@users.noreply.github.com> * fix cache mount * copy missing files * fix paths * fix paths, order * correct paths Signed-off-by: m2Giles <69128853+m2Giles@users.noreply.github.com> * don't destroy the cache * don't destroy the cache * don't destroy the cache --------- Signed-off-by: m2Giles <69128853+m2Giles@users.noreply.github.com> --- .github/workflows/reusable-build.yml | 2 +- Containerfile | 44 +++++++++++++++------------- cleanup.sh | 8 +++++ install.sh | 19 ++++++------ 4 files changed, 42 insertions(+), 31 deletions(-) create mode 100755 cleanup.sh diff --git a/.github/workflows/reusable-build.yml b/.github/workflows/reusable-build.yml index dd144b8..30d2c5b 100644 --- a/.github/workflows/reusable-build.yml +++ b/.github/workflows/reusable-build.yml @@ -16,7 +16,7 @@ concurrency: jobs: build_ublue: name: hwe - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 permissions: contents: read packages: write diff --git a/Containerfile b/Containerfile index 8e47010..bd6d072 100644 --- a/Containerfile +++ b/Containerfile @@ -7,6 +7,8 @@ ARG KERNEL_FLAVOR="${KERNEL_FLAVOR:-main}" ARG KERNEL_VERSION="${KERNEL_VERSION:-6.9.7-200.fc40.x86_64}" FROM ghcr.io/${SOURCE_ORG}/${KERNEL_FLAVOR}-kernel:${KERNEL_VERSION} AS kernel +FROM scratch AS ctx +COPY / / FROM ${BASE_IMAGE}:${FEDORA_MAJOR_VERSION} AS main @@ -17,19 +19,20 @@ ARG IMAGE_VENDOR="${IMAGE_VENDOR:-ublue-os}" ARG RPMFUSION_MIRROR="" ARG KERNEL_VERSION="${KERNEL_VERSION:-6.9.7-200.fc40.x86_64}" -COPY *.sh /tmp/ -COPY ${KERNEL_FLAVOR}/ /tmp/ -COPY --from=kernel /tmp/rpms /tmp/kernel-rpms/ - -RUN mkdir -p /var/lib/alternatives && \ - IMAGE_FLAVOR=main /tmp/image-info.sh && \ - /tmp/install.sh && \ +RUN --mount=type=cache,dst=/var/cache/rpm-ostree \ + --mount=type=bind,from=ctx,src=/,dst=/ctx \ + --mount=type=bind,from=kernel,src=/tmp/rpms,dst=/tmp/kernel-rpms \ + mkdir -p /var/lib/alternatives && \ + IMAGE_FLAVOR=main /ctx/image-info.sh && \ + /ctx/install.sh && \ mv /var/lib/alternatives /staged-alternatives && \ - rm -rf /tmp/* /var/* && \ + /ctx/cleanup.sh && \ ostree container commit && \ mkdir -p /var/lib && mv /staged-alternatives /var/lib/alternatives && \ - mkdir -p /tmp /var/tmp && \ - chmod -R 1777 /tmp /var/tmp + mkdir -p /var/tmp && \ + chmod -R 1777 /var/tmp + +FROM ghcr.io/${SOURCE_ORG}/akmods-nvidia:${KERNEL_FLAVOR}-${FEDORA_MAJOR_VERSION} AS akmods_nvidia FROM main AS nvidia @@ -40,17 +43,16 @@ ARG IMAGE_NAME="${IMAGE_NAME:-silverblue}" ARG IMAGE_VENDOR="${IMAGE_VENDOR:-ublue-os}" ARG RPMFUSION_MIRROR="" -COPY --from=ghcr.io/${SOURCE_ORG}/akmods-nvidia:${KERNEL_FLAVOR}-${FEDORA_MAJOR_VERSION} /rpms /tmp/akmods-rpms - -COPY *.sh /tmp/ - -RUN mkdir -p /var/lib/alternatives && \ - IMAGE_FLAVOR=nvidia /tmp/image-info.sh && \ - /tmp/nvidia-install.sh && \ - /tmp/build-initramfs.sh && \ +RUN --mount=type=cache,dst=/var/cache/rpm-ostree \ + --mount=type=bind,from=ctx,src=/,dst=/ctx \ + --mount=type=bind,from=akmods_nvidia,src=/rpms,dst=/tmp/akmods-rpms \ + mkdir -p /var/lib/alternatives && \ + IMAGE_FLAVOR=nvidia /ctx/image-info.sh && \ + /ctx/nvidia-install.sh && \ + /ctx/build-initramfs.sh && \ mv /var/lib/alternatives /staged-alternatives && \ - rm -rf /tmp/* /var/* && \ + /ctx/cleanup.sh && \ ostree container commit && \ mkdir -p /var/lib && mv /staged-alternatives /var/lib/alternatives && \ - mkdir -p /tmp /var/tmp && \ - chmod -R 1777 /tmp /var/tmp + mkdir -p /var/tmp && \ + chmod -R 1777 /var/tmp diff --git a/cleanup.sh b/cleanup.sh new file mode 100755 index 0000000..064dd0b --- /dev/null +++ b/cleanup.sh @@ -0,0 +1,8 @@ +#!/usr/bin/bash + +set -eoux pipefail +shopt -s extglob + +rm -rf /tmp/* || true +rm -rf /var/!(cache) +rm -rf /var/cache/!(rpm-ostree) diff --git a/install.sh b/install.sh index 04542b3..b66706d 100755 --- a/install.sh +++ b/install.sh @@ -44,8 +44,8 @@ elif [ "${KERNEL_FLAVOR}" = "surface" ]; then echo "install.sh: steps for KERNEL_FLAVOR: ${KERNEL_FLAVOR}" curl -Lo /etc/yum.repos.d/linux-surface.repo \ https://pkg.surfacelinux.com/fedora/linux-surface.repo - curl -Lo /tmp/surface-kernel.rpm \ - https://github.com/linux-surface/linux-surface/releases/download/silverblue-20201215-1/kernel-20201215-1.x86_64.rpm + # curl -Lo /tmp/surface-kernel.rpm \ + # https://github.com/linux-surface/linux-surface/releases/download/silverblue-20201215-1/kernel-20201215-1.x86_64.rpm # Install Surface kernel rpm-ostree cliwrap install-to-root / rpm-ostree override replace \ @@ -70,18 +70,19 @@ else fi # copy any shared sys files -if [ -d "/tmp/system_files/shared" ]; then - rsync -rvK /tmp/system_files/shared/ / +if [[ -d /ctx/"${KERNEL_FLAVOR}"/system_files/shared ]]; then + rsync -rvK /ctx/"${KERNEL_FLAVOR}"/system_files/shared/ / fi # copy any flavor specific files, eg silverblue -if [ -d "/tmp/system_files/${IMAGE_NAME}" ]; then - rsync -rvK /tmp/system_files/"${IMAGE_NAME}"/ / +if [[ -d "/ctx/${KERNEL_FLAVOR}/system_files/${IMAGE_NAME}" ]]; then + rsync -rvK "/ctx/${KERNEL_FLAVOR}/system_files/${IMAGE_NAME}"/ / fi # install any packages from packages.json -if [ -f "/tmp/packages.json" ]; then - /tmp/packages.sh /tmp/packages.json +if [ -f "/ctx/${KERNEL_FLAVOR}/packages.json" ]; then + cp /ctx/"${KERNEL_FLAVOR}"/packages.json /tmp/packages.json + /ctx/packages.sh /tmp/packages.json fi # do HWE specific post-install things @@ -104,4 +105,4 @@ if [ -n "${RPMFUSION_MIRROR}" ]; then rename -v .repo.bak .repo /etc/yum.repos.d/rpmfusion-*repo.bak fi -/tmp/build-initramfs.sh +/ctx/build-initramfs.sh