Skip to content

Commit

Permalink
update more things, add scripting test
Browse files Browse the repository at this point in the history
  • Loading branch information
korewaChino committed Oct 1, 2023
1 parent 16f4e8e commit ee3e5e2
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 9 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Build test

on:
push:
branches: [ refactor ]

jobs:
unit-test:
runs-on: ubuntu-latest
container:
image: ghcr.io/terrapkg/builder:f38
# Pass /dev from host to container
# Very hacky, but it works
# Microsoft/Github, if you're reading this,
# I'm sorry.
options: --privileged -v /dev:/dev

steps:
- uses: actions/checkout@v4
- name: Cache DNF packages
uses: actions/cache@v2
with:
path: /var/cache/dnf
key: dnf-${{ runner.os }}
restore-keys: |
dnf-${{ runner.os }}-
dnf-
- name: Install dependencies
run: |
dnf install -y \
xorriso \
rpm \
limine \
systemd \
btrfs-progs \
e2fsprogs \
xfsprogs \
dosfstools \
grub2 \
parted \
util-linux-core \
systemd-container \
grub2-efi \
uboot-images-armv8 \
uboot-tools \
rustc \
qemu-user-static-aarch64 \
qemu-user-binfmt \
qemu-kvm \
qemu-img \
cargo \
systemd-devel \
mkpasswd \
moby-engine
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- uses: Swatinem/rust-cache@v2

- name: Build and install katsu
run: |
cargo install --path . --debug
- name: Run test
run: |
export PATH=$HOME/.cargo/bin:$PATH
pushd tests/ng
echo "COLORBT_SHOW_HIDDEN=1" >> .env
echo "KATSU_LOG=trace" >> .env
katsu -o disk-image katsu.yaml 2>&1
xz -z9 katsu-work/image/katsu.img -c > katsu-work/image/katsu.raw.xz
popd
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: katsudon-arm
path: tests/ng/katsu-work/image/*.raw.xz
6 changes: 4 additions & 2 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl RootBuilder for DnfRootBuilder {

info!("Running post-install scripts");

run_scripts(manifest.scripts.pre.clone(), &chroot, true)?;
run_scripts(manifest.scripts.post.clone(), &chroot, true)?;

Ok(())
}
Expand Down Expand Up @@ -141,9 +141,11 @@ pub fn run_scripts(scripts: Vec<Script>, chroot: &PathBuf, in_chroot: bool) -> R
Ok(())
})?;
} else {
// export envar
std::env::set_var("CHROOT", chroot);
cmd_lib::run_cmd!(
chmod +x katsu-work/tmp-script;
katsu-work/tmp-script;
/usr/bin/env CHROOT=${chroot} katsu-work/tmp-script;
)?;
}

Expand Down
17 changes: 12 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use color_eyre::Result;
use merge_struct::merge;
use serde_derive::{Deserialize, Serialize};
use tracing::debug;
use tracing::{debug, trace};
use std::path::PathBuf;

#[derive(Deserialize, Debug, Clone, Serialize)]
Expand Down Expand Up @@ -32,10 +32,12 @@ impl Manifest {
pub fn load(path: PathBuf) -> Result<Self> {
let mut manifest: Self = serde_yaml::from_str(&std::fs::read_to_string(path.clone())?)?;

// get dir of path
// get dir of path relative to cwd

let mut path_can = path.canonicalize()?;

let mut path_can = path;
path_can.pop();
trace!(path = ?path_can, "Canonicalizing path");

for import in &mut manifest.import {
debug!("Import: {import:#?}");
Expand All @@ -49,13 +51,18 @@ impl Manifest {

for script in &mut manifest.scripts.pre {
if let Some(f) = script.file.as_mut() {
*f = f.canonicalize()?;
let cn = path_can.join(&f);
trace!(f = ?cn, "Canonicalizing script path");
*f = path_can.join(&f);
}
}

for script in &mut manifest.scripts.post {
if let Some(f) = script.file.as_mut() {
*f = f.canonicalize()?;

let cn = path_can.join(&f);
trace!(f = ?cn, "Canonicalizing script path");
*f = path_can.join(&f);
}
}

Expand Down
17 changes: 17 additions & 0 deletions tests/ng/grub-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash -x

# get /dev/ of /boot
bootdev=$(findmnt -n -o SOURCE /boot)

# get blkid of /boot
bootid=$(blkid -s UUID -o value $bootdev)

# heredoc for /dev/disk

cat << EOF > /boot/efi/EFI/fedora/grub.cfg
search --no-floppy --fs-uuid --set=dev $bootid
set prefix=(\$dev)/grub2
export \$prefix
configfile \$prefix/grub.cfg
EOF
8 changes: 8 additions & 0 deletions tests/ng/image-cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash -x
rm -f /var/lib/systemd/random-seed
rm -f /etc/NetworkManager/system-connections/*.nmconnection

rm -f /etc/machine-id
touch /etc/machine-id

rm -f /var/lib/rpm/__db*
23 changes: 21 additions & 2 deletions tests/ng/katsu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,32 @@ distro: Katsu Ultramarine

scripts:
pre:
- inline: |
- id: pre-test
name: Preinstall test
inline: |
echo "Hello from pre.sh"
- id: pre-test2
name: Preinstall test 2
file: pre-test2.sh

post:
- inline: |
- id: post-test
name: Postinstall test
inline: |
echo "Hello from post.sh"
- id: image-cleanup
name: Clean up root filesystem
file: image-cleanup.sh

- id: grub-install
name: Install GRUB
file: grub-install.sh

- id: selinux-label
name: Relabel SELinux for new filesystem
file: selinux-label.sh

dnf:
releasever: 38
packages:
Expand Down
37 changes: 37 additions & 0 deletions tests/ng/pre-test2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
echo "Hello from pre2.sh"
echo "This is an integration test for Katsu, the Ultramarine image builder."
# check if $CHROOT is set, if not, exit


echo "Testing if CHROOT is set..."
if [ -z "$CHROOT" ]; then
echo "CHROOT is not set, exiting."
exit 1
fi
echo "CHROOT: $CHROOT"

# check if $CHROOT is a directory, if not, exit
echo "Testing if CHROOT is a directory..."
if [ ! -d "$CHROOT" ]; then
echo "CHROOT is not a directory, exiting."
exit 1
fi

# check if $CHROOT is readable, if not, exit
echo "Testing if CHROOT is readable..."
if [ ! -r "$CHROOT" ]; then
echo "CHROOT is not readable, exiting."
exit 1
fi

# check if $CHROOT is writable, if not, exit
echo "Testing if CHROOT is writable..."
if [ ! -w "$CHROOT" ]; then
echo "CHROOT is not writable, exiting."
exit 1
fi



echo "Enjoy!"
4 changes: 4 additions & 0 deletions tests/ng/selinux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash -x

setfiles -v -F -e /proc -e /sys -e /dev -e /bin /etc/selinux/targeted/contexts/files/file_contexts /
setfiles -v -F -e /proc -e /sys -e /dev -e /etc/selinux/targeted/contexts/files/file_contexts.bin /bin

0 comments on commit ee3e5e2

Please sign in to comment.