Skip to content

Commit

Permalink
Switch to Incus
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <[email protected]>
  • Loading branch information
stgraber committed Oct 10, 2023
1 parent 7418f84 commit 0468230
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
18 changes: 9 additions & 9 deletions bin/build-distro
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ TARGET=${1}
shift

cleanup() {
lxc delete --force "${CNAME}"
incus delete --force "${CNAME}"
}

trap cleanup EXIT HUP INT TERM

# Create the container
lxc copy "cache-distrobuilder-${ARCH}" "${CNAME}"
incus copy "cache-distrobuilder-${ARCH}" "${CNAME}"

# Start the container
lxc start "${CNAME}"
incus start "${CNAME}"

set -x

lxc file push "${YAML}" "${CNAME}/root/image.yaml"
incus file push "${YAML}" "${CNAME}/root/image.yaml"

(
cat << EOF
Expand Down Expand Up @@ -61,21 +61,21 @@ SERIAL=\$(date -u +%Y%m%d_%H:%M)
distrobuilder --cache-dir /root/build/cache/ --timeout "${TIMEOUT}" build-dir image.yaml rootfs -o image.serial="\${SERIAL}" "\$@"
if echo ${TYPE} | grep -q vm; then
distrobuilder --cache-dir /root/build/cache/ pack-lxd image.yaml rootfs --vm -o image.serial="\${SERIAL}" "\$@"
distrobuilder --cache-dir /root/build/cache/ pack-incus image.yaml rootfs --vm -o image.serial="\${SERIAL}" "\$@"
fi
if echo ${TYPE} | grep -q container; then
distrobuilder --cache-dir /root/build/cache/ pack-lxc image.yaml rootfs -o image.serial="\${SERIAL}" "\$@"
distrobuilder --cache-dir /root/build/cache/ pack-lxd image.yaml rootfs -o image.serial="\${SERIAL}" "\$@"
distrobuilder --cache-dir /root/build/cache/ pack-incus image.yaml rootfs -o image.serial="\${SERIAL}" "\$@"
fi
btrfs subvolume delete rootfs/var/lib/machines >/dev/null 2>&1 || true
rm -Rf rootfs
echo "\${SERIAL}" > serial
exit 0
EOF
) | lxc file push - "${CNAME}/root/build.sh" --mode=755
lxc exec "${CNAME}" -- /root/build.sh "$@"
lxc exec "${CNAME}" -- tar -cf - -C /root/build/ . | tar -xvf - -C "${TARGET}"
) | incus file push - "${CNAME}/root/build.sh" --mode=755
incus exec "${CNAME}" -- /root/build.sh "$@"
incus exec "${CNAME}" -- tar -cf - -C /root/build/ . | tar -xvf - -C "${TARGET}"

[ -n "${SUDO_UID:-}" ] && chown "${SUDO_UID}" -R "${TARGET}"
[ -n "${SUDO_GID:-}" ] && chgrp "${SUDO_GID}" -R "${TARGET}"
20 changes: 10 additions & 10 deletions bin/build-image-distrobuilder
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export PATH="/snap/bin/:${PATH}"

cleanup() {
set +e
lxc delete build-distrobuilder-cache -f >/dev/null 2>&1
incus delete build-distrobuilder-cache -f >/dev/null 2>&1

exit 0
}
Expand All @@ -14,13 +14,13 @@ TARGET="$2"
DISTRO="jammy"

# Create the container
lxc init "images:ubuntu/${DISTRO}/${ARCH}" build-distrobuilder-cache \
incus init "images:ubuntu/${DISTRO}/${ARCH}" build-distrobuilder-cache \
-c security.privileged=true -c security.nesting=true
printf "lxc.cgroup2.devices.allow = b 259:* rw\nlxc.cgroup.devices.allow = b 259:* rw" | lxc config set build-distrobuilder-cache raw.lxc -
printf "lxc.cgroup2.devices.allow = b 259:* rw\nlxc.cgroup.devices.allow = b 259:* rw" | incus config set build-distrobuilder-cache raw.incus -

# Setup loop devices
(
lxc config show build-distrobuilder-cache | sed "/devices:/d"
incus config show build-distrobuilder-cache | sed "/devices:/d"
cat << EOF
devices:
loop-control:
Expand All @@ -39,10 +39,10 @@ EOF
type: unix-block
EOF
done
) | lxc config edit build-distrobuilder-cache
) | incus config edit build-distrobuilder-cache

# Start the container
lxc start build-distrobuilder-cache
incus start build-distrobuilder-cache

# Install distrobuilder
(
Expand Down Expand Up @@ -118,8 +118,8 @@ rm -Rf /root/distrobuilder /root/go /root/.cache
# All done
exit 0
EOF
) | lxc exec build-distrobuilder-cache -- sh
) | incus exec build-distrobuilder-cache -- sh

lxc stop build-distrobuilder-cache
lxc export build-distrobuilder-cache "${TARGET}/build-distrobuilder-cache.tar.xz" --optimized-storage
lxc delete -f build-distrobuilder-cache
incus stop build-distrobuilder-cache
incus export build-distrobuilder-cache "${TARGET}/build-distrobuilder-cache.tar.xz" --optimized-storage
incus delete -f build-distrobuilder-cache
18 changes: 9 additions & 9 deletions bin/build-image-lxc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export PATH="/snap/bin/:${PATH}"

cleanup() {
set +e
lxc delete build-lxc-cache -f >/dev/null 2>&1
incus delete build-lxc-cache -f >/dev/null 2>&1

exit 0
}
Expand All @@ -13,11 +13,11 @@ ARCH="$1"
TARGET="$2"

# Create the container
lxc init "images:ubuntu/jammy/${ARCH}" build-lxc-cache \
incus init "images:ubuntu/jammy/${ARCH}" build-lxc-cache \
-c security.nesting=true

# Start the container
lxc start build-lxc-cache
incus start build-lxc-cache

# Install build dependencies
(
Expand Down Expand Up @@ -63,11 +63,11 @@ apt-get clean
# Create build directory
mkdir -p /build
EOF
) | lxc exec build-lxc-cache -- sh
) | incus exec build-lxc-cache -- sh

# Install Android dependencies
if [ "${ARCH}" = "amd64" ]; then
lxc file push deps/android-ndk-linux-x86_64.zip build-lxc-cache/root/ndk.zip
incus file push deps/android-ndk-linux-x86_64.zip build-lxc-cache/root/ndk.zip
(
cat << EOF
#!/bin/sh
Expand Down Expand Up @@ -103,11 +103,11 @@ cp -P /build/libcap/libcap/libcap.a /build/ndk/sysroot/usr/lib/
cp -P /build/libcap/libcap/include/sys/capability.h /build/ndk/sysroot/usr/include/sys/
cp -P /build/libcap/libcap/include/uapi/linux/capability.h /build/ndk/sysroot/usr/include/linux/
EOF
) | lxc exec build-lxc-cache -- sh
) | incus exec build-lxc-cache -- sh
fi

lxc stop build-lxc-cache
lxc export build-lxc-cache "${TARGET}/build-lxc-cache.tar.xz" --optimized-storage
lxc delete -f build-lxc-cache
incus stop build-lxc-cache
incus export build-lxc-cache "${TARGET}/build-lxc-cache.tar.xz" --optimized-storage
incus delete -f build-lxc-cache

exit 0
26 changes: 13 additions & 13 deletions bin/update-images
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export PATH="/snap/bin/:${PATH}"

cleanup() {
set +e
lxc delete build-distrobuilder-cache -f >/dev/null 2>&1
lxc delete build-lxc-cache -f >/dev/null 2>&1
incus delete build-distrobuilder-cache -f >/dev/null 2>&1
incus delete build-lxc-cache -f >/dev/null 2>&1

exit 0
}
Expand All @@ -20,9 +20,9 @@ while :; do
done

# Make sure LXD is functional
lxc delete update-images -f >/dev/null 2>&1 || true
lxc init update-images --empty --quiet
lxc delete -f update-images
incus delete update-images -f >/dev/null 2>&1 || true
incus init update-images --empty --quiet
incus delete -f update-images

# Avoid conflicting with an in progress build.
while :; do
Expand All @@ -38,13 +38,13 @@ build_distrobuilder() {
fi

for arch in ${DISTROBUILDER_ARCHES}; do
lxc delete -f build-distrobuilder-cache >/dev/null 2>&1 || true
incus delete -f build-distrobuilder-cache >/dev/null 2>&1 || true
rm -f /tmp/build-distrobuilder-cache
curl -s "${HOST}/job/lxc-ci-artifacts/architecture=${arch},artifact=distrobuilder-image,restrict=vm,variant=default/lastSuccessfulBuild/artifact/build-distrobuilder-cache.tar.xz" -o /tmp/build-distrobuilder-cache
lxc import --quiet /tmp/build-distrobuilder-cache
incus import --quiet /tmp/build-distrobuilder-cache
rm -f /tmp/build-distrobuilder-cache
lxc delete -f "cache-distrobuilder-${arch}" >/dev/null 2>&1 || true
lxc move build-distrobuilder-cache "cache-distrobuilder-${arch}"
incus delete -f "cache-distrobuilder-${arch}" >/dev/null 2>&1 || true
incus move build-distrobuilder-cache "cache-distrobuilder-${arch}"
done
}

Expand All @@ -54,13 +54,13 @@ build_lxc() {
fi

for arch in ${LXC_ARCHES}; do
lxc delete -f build-lxc-cache >/dev/null 2>&1 || true
incus delete -f build-lxc-cache >/dev/null 2>&1 || true
rm -f /tmp/build-lxc-cache
curl -s "${HOST}/job/lxc-ci-artifacts/architecture=${arch},artifact=lxc-image,restrict=vm,variant=default/lastSuccessfulBuild/artifact/build-lxc-cache.tar.xz" -o /tmp/build-lxc-cache
lxc import --quiet /tmp/build-lxc-cache
incus import --quiet /tmp/build-lxc-cache
rm -f /tmp/build-lxc-cache
lxc delete -f "cache-lxc-${arch}" >/dev/null 2>&1 || true
lxc move build-lxc-cache "cache-lxc-${arch}"
incus delete -f "cache-lxc-${arch}" >/dev/null 2>&1 || true
incus move build-lxc-cache "cache-lxc-${arch}"
done
}

Expand Down

0 comments on commit 0468230

Please sign in to comment.