Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): Reduce copy layers #612

Merged
merged 10 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: main
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
Expand Down
31 changes: 15 additions & 16 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,30 @@ FROM ghcr.io/ublue-os/config:latest AS config
FROM ghcr.io/ublue-os/akmods:main-${FEDORA_MAJOR_VERSION} AS akmods
FROM ghcr.io/ublue-os/main-kernel:${KERNEL_VERSION} AS kernel

FROM scratch AS ctx
COPY / /

FROM ${BASE_IMAGE}:${FEDORA_MAJOR_VERSION}

ARG IMAGE_NAME="${IMAGE_NAME:-silverblue}"
ARG FEDORA_MAJOR_VERSION="${FEDORA_MAJOR_VERSION:-40}"
ARG RPMFUSION_MIRROR="${:-}"
ARG KERNEL_VERSION="${KERNEL_VERSION:-6.9.7-200.fc40.x86_64}"

COPY github-release-install.sh \
install.sh \
post-install.sh \
packages.sh \
packages.json \
/tmp/

COPY --from=config /rpms /tmp/rpms
COPY --from=akmods /rpms/ublue-os /tmp/rpms
COPY --from=kernel /tmp/rpms /tmp/kernel-rpms
COPY sys_files/usr /usr

RUN mkdir -p /var/lib/alternatives && \
/tmp/install.sh && \
/tmp/post-install.sh && \
RUN --mount=type=cache,dst=/var/cache/rpm-ostree \
--mount=type=bind,from=ctx,src=/,dst=/ctx \
--mount=type=bind,from=config,src=/rpms,dst=/tmp/rpms \
--mount=type=bind,from=akmods,src=/rpms/ublue-os,dst=/tmp/akmods-rpms \
--mount=type=bind,from=kernel,src=/tmp/rpms,dst=/tmp/kernel-rpms \
mkdir -p /var/lib/alternatives && \
/ctx/install.sh && \
/ctx/post-install.sh && \
mv /var/lib/alternatives /staged-alternatives && \
rm -rf /tmp/* /var/* && \
rm -rf /tmp/* || true && \
rm -rf /var/* || true && \
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
7 changes: 7 additions & 0 deletions initramfs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/bash

set -eoux pipefail

QUALIFIED_KERNEL="$(rpm -qa | grep -P 'kernel-(\d+\.\d+\.\d+)' | sed -E 's/kernel-//')"
/usr/libexec/rpm-ostree/wrapped/dracut --no-hostonly --kver "$QUALIFIED_KERNEL" --reproducible -v --add ostree -f "/lib/modules/$QUALIFIED_KERNEL/initramfs.img"
chmod 0600 "/lib/modules/$QUALIFIED_KERNEL/initramfs.img"
18 changes: 13 additions & 5 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,32 @@ if [ -n "${RPMFUSION_MIRROR}" ]; then
RPMFUSION_MIRROR_RPMS=${RPMFUSION_MIRROR}
fi

curl -Lo /tmp/rpms/rpmfusion-free-release-"${RELEASE}".noarch.rpm "${RPMFUSION_MIRROR_RPMS}"/free/fedora/rpmfusion-free-release-"${RELEASE}".noarch.rpm
curl -Lo /tmp/rpms/rpmfusion-nonfree-release-"${RELEASE}".noarch.rpm "${RPMFUSION_MIRROR_RPMS}"/nonfree/fedora/rpmfusion-nonfree-release-"${RELEASE}".noarch.rpm
mkdir -p /tmp/rpm-repos
curl -Lo /tmp/rpm-repos/rpmfusion-free-release-"${RELEASE}".noarch.rpm "${RPMFUSION_MIRROR_RPMS}"/free/fedora/rpmfusion-free-release-"${RELEASE}".noarch.rpm
curl -Lo /tmp/rpm-repos/rpmfusion-nonfree-release-"${RELEASE}".noarch.rpm "${RPMFUSION_MIRROR_RPMS}"/nonfree/fedora/rpmfusion-nonfree-release-"${RELEASE}".noarch.rpm

curl -Lo /etc/yum.repos.d/_copr_ublue-os_staging.repo https://copr.fedorainfracloud.org/coprs/ublue-os/staging/repo/fedora-"${RELEASE}"/ublue-os-staging-fedora-"${RELEASE}".repo
curl -Lo /etc/yum.repos.d/_copr_kylegospo_oversteer.repo https://copr.fedorainfracloud.org/coprs/kylegospo/oversteer/repo/fedora-"${RELEASE}"/kylegospo-oversteer-fedora-"${RELEASE}".repo

rpm-ostree install \
/tmp/rpms/*.rpm \
/tmp/rpm-repos/*.rpm \
/tmp/akmods-rpms/*.rpm \
fedora-repos-archive

# Handle Kernel Skew with override replace
rpm-ostree cliwrap install-to-root /
if [[ "${KERNEL_VERSION}" == "${QUALIFIED_KERNEL}" ]]; then
echo "Installing signed kernel from kernel-cache."
cd /tmp/kernel-rpms
cd /tmp
rpm2cpio /tmp/kernel-rpms/kernel-core-*.rpm | cpio -idmv
cp ./lib/modules/*/vmlinuz /usr/lib/modules/*/vmlinuz
cd /
else
echo "Install kernel version ${KERNEL_VERSION} from kernel-cache."
rpm-ostree override replace \
--experimental \
--install=zstd \
/tmp/kernel-rpms/kernel-[0-9]*.rpm \
/tmp/kernel-rpms/kernel-core-*.rpm \
/tmp/kernel-rpms/kernel-modules-*.rpm
Expand All @@ -59,10 +63,14 @@ if [ -n "${RPMFUSION_MIRROR}" ]; then
fi

# run common packages script
/tmp/packages.sh
/ctx/packages.sh

## install packages direct from github
/tmp/github-release-install.sh sigstore/cosign x86_64
/ctx/github-release-install.sh sigstore/cosign x86_64

if [[ "${KERNEL_VERSION}" == "${QUALIFIED_KERNEL}" ]]; then
/ctx/initramfs.sh
fi

if [ -n "${RPMFUSION_MIRROR}" ]; then
# reset forced use of single rpmfusion mirror
Expand Down
6 changes: 3 additions & 3 deletions packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ RELEASE="$(rpm -E %fedora)"
# build list of all packages requested for inclusion
INCLUDED_PACKAGES=($(jq -r "[(.all.include | (.all, select(.\"$IMAGE_NAME\" != null).\"$IMAGE_NAME\")[]), \
(select(.\"$FEDORA_MAJOR_VERSION\" != null).\"$FEDORA_MAJOR_VERSION\".include | (.all, select(.\"$IMAGE_NAME\" != null).\"$IMAGE_NAME\")[])] \
| sort | unique[]" /tmp/packages.json))
| sort | unique[]" /ctx/packages.json))

# build list of all packages requested for exclusion
EXCLUDED_PACKAGES=($(jq -r "[(.all.exclude | (.all, select(.\"$IMAGE_NAME\" != null).\"$IMAGE_NAME\")[]), \
(select(.\"$FEDORA_MAJOR_VERSION\" != null).\"$FEDORA_MAJOR_VERSION\".exclude | (.all, select(.\"$IMAGE_NAME\" != null).\"$IMAGE_NAME\")[])] \
| sort | unique[]" /tmp/packages.json))
| sort | unique[]" /ctx/packages.json))


# ensure exclusion list only contains packages already present on image
Expand Down Expand Up @@ -40,7 +40,7 @@ fi
# (this can happen if an included package pulls in a dependency)
EXCLUDED_PACKAGES=($(jq -r "[(.all.exclude | (.all, select(.\"$IMAGE_NAME\" != null).\"$IMAGE_NAME\")[]), \
(select(.\"$FEDORA_MAJOR_VERSION\" != null).\"$FEDORA_MAJOR_VERSION\".exclude | (.all, select(.\"$IMAGE_NAME\" != null).\"$IMAGE_NAME\")[])] \
| sort | unique[]" /tmp/packages.json))
| sort | unique[]" /ctx/packages.json))

if [[ "${#EXCLUDED_PACKAGES[@]}" -gt 0 ]]; then
EXCLUDED_PACKAGES=($(rpm -qa --queryformat='%{NAME} ' ${EXCLUDED_PACKAGES[@]}))
Expand Down
2 changes: 1 addition & 1 deletion post-install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

set -ouex pipefail

Expand Down