Nicolas Massé 3 months ago
parent
commit
69b9536fb4
  1. 8
      bootc/scenario3a/Containerfile
  2. 0
      bootc/scenario3a/config.toml
  3. 26
      bootc/scenario3a/custom.sh
  4. 5
      bootc/scenario3a/root/etc/default/bootstrap-vm-nextcloud.env
  5. 20
      bootc/scenario3a/root/etc/greenboot/check/required.d/30_nextcloud_check.sh
  6. 1
      bootc/scenario3a/root/etc/libvirt/qemu/networks/autostart/default.xml
  7. 19
      bootc/scenario3a/root/etc/libvirt/qemu/networks/default.xml
  8. 17
      bootc/scenario3a/root/etc/systemd/system/bootstrap-vm@.service
  9. 25
      bootc/scenario3a/root/usr/local/bin/bootstrap-vm.sh
  10. 2
      bootc/scenario3a/root/usr/local/libvirt/images/nextcloud/.gitignore
  11. 5
      bootc/scripts/build.sh

8
bootc/scenario3a/Containerfile

@ -0,0 +1,8 @@
FROM edge-registry.itix.fr/demo-edge-retail/base:latest
ADD --chown=root:root root /
RUN <<EOF
set -Eeuo pipefail
systemctl enable bootstrap-vm@nextcloud.service
EOF

0
bootc/scenario3a/config.toml

26
bootc/scenario3a/custom.sh

@ -0,0 +1,26 @@
#!/bin/bash
set -Eeuo pipefail
if [[ "$UID" -ne 0 ]]; then
echo "This command must be run as root!"
exit 1
fi
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
. "$PROJECT_DIR/config.env"
function bootc_image_builder () {
local config="$1"
shift
podman run --rm -it --privileged --pull=newer --security-opt label=type:unconfined_t -v "$config:/$(basename $config):ro" \
-v $PWD/root/usr/local/libvirt/images/nextcloud:/output -v /var/lib/containers/storage:/var/lib/containers/storage \
registry.redhat.io/rhel10/bootc-image-builder:latest --config "/$(basename $config)" "$@"
}
BOOTC_IMAGE="$(echo -n "$TARGET_IMAGE_TEMPLATE" | SCENARIO=scenario1 envsubst)"
echo "Building qcow2 from $BOOTC_IMAGE..."
bootc_image_builder "$PWD/config.toml" --type qcow2 "$BOOTC_IMAGE"

5
bootc/scenario3a/root/etc/default/bootstrap-vm-nextcloud.env

@ -0,0 +1,5 @@
DOMAIN_VCPUS=4
DOMAIN_RAM=8192
DOMAIN_DISK_SIZE=100
DOMAIN_OS_VARIANT=rhel9.6
DOMAIN_MAC_ADDRESS=04:00:00:00:00:01

20
bootc/scenario3a/root/etc/greenboot/check/required.d/30_nextcloud_check.sh

@ -0,0 +1,20 @@
#!/bin/bash
exit 0 # Temporary disable the check
set -Eeuo pipefail
MAX_ATTEMPTS=60
for (( attempt=1; attempt<=MAX_ATTEMPTS; attempt++ )); do
echo "Checking VM ($attempt/$MAX_ATTEMPTS)..."
if virsh domstate nextcloud | grep -q 'running'; then
echo "Nextcloud VM is running."
exit 0
fi
sleep 5
done
echo "Nextcloud VM is not running correctly after $MAX_ATTEMPTS attempts!"
exit 1

1
bootc/scenario3a/root/etc/libvirt/qemu/networks/autostart/default.xml

@ -0,0 +1 @@
../default.xml

19
bootc/scenario3a/root/etc/libvirt/qemu/networks/default.xml

@ -0,0 +1,19 @@
<network>
<name>default</name>
<bridge name="virbr0" stp="on" delay="5" />
<forward mode='nat' />
<domain name="libvirt.test" />
<dns>
<host ip='192.168.122.1'>
<hostname>host</hostname>
</host>
</dns>
<ip address="192.168.122.1" netmask="255.255.255.0" localPtr="yes">
<dhcp>
<range start="192.168.122.100" end="192.168.122.200">
<lease expiry='1' unit='days'/>
</range>
<host mac="04:00:00:00:00:01" name="vm.libvirt.test" ip="192.168.122.2" />
</dhcp>
</ip>
</network>

17
bootc/scenario3a/root/etc/systemd/system/bootstrap-vm@.service

@ -0,0 +1,17 @@
[Unit]
Description=RHDE VM Bootstrap Service
Documentation=man:systemd.service(5)
# Only start if the VM root disk does not exist
#ConditionPathExists=!/var/lib/libvirt/images/%i/root.qcow2
ConditionPathExists=/dummy
[Service]
Type=oneshot
Persistent=true
#ExecStartPre=/usr/local/bin/configure-network.sh
ExecStart=/usr/local/bin/bootstrap-vm.sh %i
EnvironmentFile=/etc/default/bootstrap-vm-%i.env
[Install]
WantedBy=multi-user.target

25
bootc/scenario3a/root/usr/local/bin/bootstrap-vm.sh

@ -0,0 +1,25 @@
#!/bin/bash
set -Eeuo pipefail
if [[ $# -ne 1 ]]; then
echo "Usage: $0 <vm-name>"
exit 1
fi
VM="${1}"
cp -a "/usr/local/libvirt/images/nextcloud/qcow2/disk.qcow2" "/var/lib/libvirt/images/${VM}/root.qcow2"
virt-install --name "${VM}" \
--autostart \
--cpu=host-passthrough \
--vcpus=${DOMAIN_VCPUS} \
--ram=${DOMAIN_RAM} \
--os-variant=${DOMAIN_OS_VARIANT} \
--disk=path=/var/lib/libvirt/images/${VM}/root.qcow2,bus=virtio,format=qcow2,size=${DOMAIN_DISK_SIZE}G \
--console=pty,target_type=virtio \
--serial=pty \
--graphics=none \
--import \
--network=network=bridged,mac=${DOMAIN_MAC_ADDRESS}

2
bootc/scenario3a/root/usr/local/libvirt/images/nextcloud/.gitignore

@ -0,0 +1,2 @@
qcow2
manifest-qcow2.json

5
bootc/scripts/build.sh

@ -43,5 +43,10 @@ if [ ! -f "$REGISTRY_AUTH_FILE" ]; then
podman login registry.redhat.io
fi
if [ -x "$PWD/custom.sh" ]; then
echo "Running custom.sh..."
"$PWD/custom.sh"
fi
podman build --no-cache -t "${TARGET_IMAGE}" .
podman push --sign-by-sigstore-private-key "$PROJECT_DIR/signing-key.private" --sign-passphrase-file "$PROJECT_DIR/signing-key.pass" "${TARGET_IMAGE}"

Loading…
Cancel
Save