Skip to content

Commit

Permalink
Merge pull request #410 from sallyom/growfs
Browse files Browse the repository at this point in the history
Add growfs service to chatbot/bootc Containerfiles
  • Loading branch information
rhatdan authored May 1, 2024
2 parents 4419054 + eadfd76 commit 16d27a6
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 1 deletion.
7 changes: 6 additions & 1 deletion recipes/common/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ build:
podman build --squash-all $(ARCH:%=--platform linux/%) $(FROM:%=--from %) -t ${APP_IMAGE} app/

.PHONY: bootc
bootc: quadlet
bootc: quadlet growfs
podman build \
$(ARCH:%=--arch %) \
$(FROM:%=--from %) \
Expand Down Expand Up @@ -156,6 +156,11 @@ install-chrome:
rm $(CHROME_DOWNLOAD_PATH); \
fi;

.PHONY: growfs
growfs: quadlet
# Add growfs service
mkdir -p build/usr; cp -R ../../common/usr/ build/usr/

.PHONY: quadlet
quadlet:
# Modify quadlet files to match the server, model and app image
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[Unit]
Description=Bootc Fallback Root Filesystem Grow
Documentation=https://gitlab.com/fedora/bootc/docs
# For now we skip bare metal cases, and we also have nothing to do
# for containers.
ConditionVirtualization=vm
# This helps verify that we're running in a bootc/ostree based target.
ConditionPathIsMountPoint=/sysroot
# We want to run before any e.g. large container images might be pulled.
DefaultDependencies=no
Requires=sysinit.target
After=sysinit.target
Before=basic.target

[Service]
ExecStart=/usr/libexec/bootc-generic-growpart
# So we can temporarily remount the sysroot writable
MountFlags=slave
# Just to auto-cleanup our temporary files
PrivateTmp=yes
41 changes: 41 additions & 0 deletions recipes/common/usr/libexec/bootc-generic-growpart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
set -eu

backing_device=$(findmnt -vno SOURCE /sysroot)
echo "Backing device: ${backing_device}"
syspath=/sys/class/block/$(basename "${backing_device}")
if ! test -d "${syspath}"; then
echo "failed to find backing device ${syspath}"; exit 1
fi

# Handling devicemapper targets is a whole other thing
case $backing_device in
/dev/mapper/*) "Not growing $backing_device"; exit 0 ;;
esac

# Note that we expect that the rootfs is on a partition
partition=$(cat "${syspath}"/partition)

# Walk up to find the parent blockdev
parentpath=$(dirname "$(realpath "${syspath}")")
devmajmin=$(cat "${parentpath}"/dev)
parent="/dev/block/${devmajmin}"

# Grow the partition
tmpf=$(mktemp)
# Ignore errors because growpart exits 1 if nothing changed;
# we need to check the output for NOCHANGE:
if ! /usr/bin/growpart "${parent}" "${partition}" > "${tmpf}"; then
cat "${tmpf}"
if grep -qEe '^NOCHANGE: ' "${tmpf}"; then
exit 0
fi
echo "growpart failed"
exit 1
fi
cat "${tmpf}"
# Now, temporarily remount the sysroot writable in our mount namespace
mount -o remount,rw /sysroot
# And defer to systemd's growfs wrapper which handles dispatching on
# the target filesystem type.
/usr/lib/systemd/systemd-growfs /sysroot
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ ARG APP_IMAGE=quay.io/ai-lab/${RECIPE}:latest
ARG SERVER_IMAGE=quay.io/ai-lab/llamacpp_python:latest
ARG TARGETARCH

# Include growfs service
COPY build/usr/lib /usr/lib
COPY --chmod=0755 build/usr/libexec/bootc-generic-growpart /usr/libexec/bootc-generic-growpart

# Add quadlet files to setup system to automatically run AI application on boot
COPY build/${RECIPE}.kube build/${RECIPE}.yaml /usr/share/containers/systemd

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ RUN set -eu; mkdir -p /usr/ssh && \

ARG RECIPE=chatbot

# Include growfs service
COPY build/usr/lib /usr/lib
COPY --chmod=0755 build/usr/libexec/bootc-generic-growpart /usr/libexec/bootc-generic-growpart

# Add quadlet files to setup system to automatically run AI application on boot
COPY build/${RECIPE}.image build/${RECIPE}.kube build/${RECIPE}.yaml /usr/share/containers/systemd

Expand Down

0 comments on commit 16d27a6

Please sign in to comment.