Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
feat: first attempt to build zfs kmods into scratch image
Browse files Browse the repository at this point in the history
  • Loading branch information
bsherman committed Aug 8, 2023
1 parent 10d1f49 commit 590d845
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 10 deletions.
26 changes: 26 additions & 0 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#Build from base, simpley because it's the smallest image
ARG SOURCE_IMAGE="${SOURCE_IMAGE:-fedora-coreos}"
ARG BASE_IMAGE="quay.io/fedora/${SOURCE_IMAGE}"
ARG COREOS_VERSION="${COREOS_VERSION:-stable}"

FROM ${BASE_IMAGE}:${COREOS_VERSION} AS builder
ARG COREOS_VERSION="${COREOS_VERSION:-stable}"

#RUN ln -s /usr/bin/rpm-ostree /usr/bin/dnf
COPY build*.sh /tmp
COPY certs /tmp/certs


RUN /tmp/build-prep.sh

RUN /tmp/build-kmod-zfs.sh

RUN for RPM in $(find /var/cache/akmods/ -type f -name \*.rpm); do \
cp "${RPM}" /var/cache/rpms/kmods/; \
done

RUN find /var/cache/rpms

FROM scratch

COPY --from=builder /var/cache/rpms /rpms
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@

A layer for adding extra kernel modules to your Fedora CoreOS image.

# Usage
# Features

Add this to your Containerfile to install all the RPM packages, replacing `RELEASE` with either `stable` or `testing`:
Feel free to PR more kmod build scripts into this repo!

COPY --from=ghcr.io/ublue-os/ucore-kmods:RELEASE /rpms/ /tmp/rpms
RUN rpm-ostree install /tmp/rpms/kmods/*.rpm
- [zfs](https://github.com/openzfs/zfs) - OpenZFS advanced file system and volume manager

This example shows:
1. copying all the rpms from the `ucore-kmods` image
2. installing the kmods RPMs, providing the actual kmods built in this repo

# Usage

# Features
Add this to your Containerfile to install ZFS RPM packages, replacing `RELEASE` with either `stable` or `testing`:

Feel free to PR more kmod build scripts into this repo!
COPY --from=ghcr.io/ublue-os/ucore-kmods:RELEASE /rpms/ /tmp/rpms
RUN rpm-ostree install /tmp/rpms/kmods/zfs/*.rpm

- [zfs](https://github.com/openzfs/zfs) - OpenZFS advanced file system and volume manager
This example shows:
1. copying all the rpms from the `ucore-kmods` image into an image temp directory
2. installing the normal (not debug/src/devel/other) zfs RPMs which were built in this repo

Note: inspect the build logs or image filesystem to see the extra ZFS RPMS provided.


# Adding kmods
Expand Down
41 changes: 41 additions & 0 deletions build-kmod-zfs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/sh

set -oeux pipefail


ARCH="$(rpm -E '%_arch')"
KERNEL="$(rpm -q kernel --queryformat '%{VERSION}-%{RELEASE}.%{ARCH}')"
RELEASE="$(rpm -E '%fedora')"

cd /tmp

# Use cURL to fetch the given URL, saving the response to `data.json`
curl "https://api.github.com/repos/openzfs/zfs/releases" -o data.json
ZFS_VERSION=$(jq -r '[ .[] | select(.prerelease==false and .draft==false) ][0].name' data.json|cut -f2- -d-)
ZFS_PREVIOUS=$(jq -r '[ .[] | select(.prerelease==false and .draft==false) ][1].name' data.json|cut -f2- -d-)

### zfs specific build deps
rpm-ostree install libtirpc-devel libblkid-devel libuuid-devel libudev-devel openssl-devel zlib-devel libaio-devel libattr-devel elfutils-libelf-devel python3-devel libffi-devel libcurl-devel


### BUILD zfs
echo "getting zfs-${ZFS_VERSION}.tar.gz"
curl -L -O https://github.com/openzfs/zfs/releases/download/zfs-${ZFS_VERSION}/zfs-${ZFS_VERSION}.tar.gz
tar xzf zfs-${ZFS_VERSION}.tar.gz

cd /tmp/zfs-${ZFS_VERSION}
./configure \
-with-linux=/usr/src/kernels/${KERNEL}/ \
-with-linux-obj=/usr/src/kernels/${KERNEL}/ \
&& make -j 1 rpm-utils rpm-kmod \
|| (cat config.log && exit 1)


# create a directory for later copying of resulting zfs specific artifacts
mkdir -p /var/cache/rpms/kmods/zfs/{debug,devel,other,src} \
&& mv *src.rpm /var/cache/rpms/kmods/zfs/src/ \
&& mv *devel*.rpm /var/cache/rpms/kmods/zfs/devel/ \
&& mv *debug*.rpm /var/cache/rpms/kmods/zfs/debug/ \
&& mv zfs-dracut*.rpm /var/cache/rpms/kmods/zfs/other/ \
&& mv zfs-test*.rpm /var/cache/rpms/kmods/zfs/other/ \
&& mv *.rpm /var/cache/rpms/kmods/zfs/
66 changes: 66 additions & 0 deletions build-prep.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/sh

set -oeux pipefail


### PREPARE REPOS
ARCH="$(rpm -E '%_arch')"
RELEASE="$(rpm -E '%fedora')"

sed -i 's@enabled=1@enabled=0@g' /etc/yum.repos.d/fedora-cisco-openh264.repo

mkdir /tmp/rpms
curl -sL --output-dir /tmp/rpms --remote-name \
https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-${RELEASE}.noarch.rpm
curl -sL --output-dir /tmp/rpms --remote-name \
https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-${RELEASE}.noarch.rpm

# enable testing repos if not enabled on testing stream
if [[ "testing" == "${COREOS_VERSION}" ]]; then
for REPO in $(ls /etc/yum.repos.d/fedora-updates-testing{,-modular}.repo); do
if [[ "$(grep enabled=1 ${REPO} > /dev/null; echo $?)" == "1" ]]; then
echo "enabling $REPO" && \
sed -i '0,/enabled=0/{s/enabled=0/enabled=1/}' ${REPO};
fi;
done;
fi


# enable RPMs with alternatives to create them in this image build
mkdir -p /var/lib/alternatives

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


### PREPARE BUILD ENV
# stuff for akmods
rpm-ostree install \
akmods \
mock

# stuff for dkms
rpm-ostree install \
autoconf \
automake \
dkms \
git \
libtool \
ncompress

if [[ ! -s "/tmp/certs/private_key.priv" ]]; then
echo "WARNING: Using test signing key. Run './generate-akmods-key' for production builds."
cp /tmp/certs/private_key.priv{.test,}
cp /tmp/certs/public_key.der{.test,}
fi

install -Dm644 /tmp/certs/public_key.der /etc/pki/akmods/certs/public_key.der
install -Dm644 /tmp/certs/private_key.priv /etc/pki/akmods/private/private_key.priv

# protect against incorrect permissions in tmp dirs which can break akmods builds
chmod 1777 /tmp /var/tmp

# create a directory for later copying of resulting artifacts
mkdir -p /var/cache/rpms/kmods

0 comments on commit 590d845

Please sign in to comment.