forgejo-ci-runners/.taskfiles/_scripts/build_import_and_push.sh

33 lines
1.1 KiB
Bash

#!/usr/bin/env bash
# Function to check if a command was successful
check_command() {
if [ $? -ne 0 ]; then
echo "Error: $1 failed"
exit 1
fi
}
# Build the qemu image and get the path
qemuImageBuildPath=$(nix build .#nixosConfigurations.fj-lxc-vm-x86_64.config.system.build.qemuImage --print-out-paths)
check_command "Building qemu image"
# Build the metadata and get the path
metadataBuildPath=$(nix build .#nixosConfigurations.fj-lxc-vm-x86_64.config.system.build.metadata --print-out-paths)
check_command "Building metadata"
# Set the paths for the metadata and qemu image
MBP="${metadataBuildPath}/tarball/nixos-system-x86_64-linux.tar.xz"
QBP="${qemuImageBuildPath}/nixos.qcow2"
# Import the image to Incus and capture the instance name
instance_name=$(incus image import --alias nixos-gen/custom/fj-lxc-vm-x86_64 "$MBP" "$QBP" | grep -oP '(?<=Instance ).*(?= created)')
check_command "Importing image to Incus"
echo "Instance created: $instance_name"
# Call the push_token.sh script with the new instance name
./push_token.sh "$instance_name"
check_command "Pushing token to instance"
echo "Process completed successfully"