Skip to content

Commit

Permalink
chore(ci): Reduce copy layers (#269)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* fix cache mount

* copy missing files

* fix paths

* fix paths, order

* correct paths

Signed-off-by: m2Giles <[email protected]>

* don't destroy the cache

* don't destroy the cache

* don't destroy the cache

---------

Signed-off-by: m2Giles <[email protected]>
  • Loading branch information
m2Giles authored Jul 21, 2024
1 parent 904ba27 commit 7c01114
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/reusable-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 23 additions & 21 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
8 changes: 8 additions & 0 deletions cleanup.sh
Original file line number Diff line number Diff line change
@@ -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)
19 changes: 10 additions & 9 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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
Expand All @@ -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

0 comments on commit 7c01114

Please sign in to comment.