diff --git a/.github/actions/quick-rpm-clean/action.yaml b/.github/actions/quick-rpm-clean/action.yaml new file mode 100644 index 00000000..2e0ca6b9 --- /dev/null +++ b/.github/actions/quick-rpm-clean/action.yaml @@ -0,0 +1,104 @@ +name: quick-rpm-clean +description: Reusable action to run the quick RPM installation and clean procedures + +inputs: + bootc-image-url: + description: Base Bootc image URL used for the test environment + required: true + bootc-image-tag: + description: Base Bootc image tag used for the test environment + required: true + install-tag: + description: Tag to use for the MicroShift RPM packages + required: false + default: "latest" + run-clean: + description: Run the clean script + required: false + default: "true" + +runs: + using: "composite" + steps: + - name: Prepare the test environment + shell: bash + run: | + set -euo pipefail + set -x + + # Mask the systemd-resolved and its related services to prevent them from + # interfering with the host DNS resolver. + # See: https://gitlab.com/fedora/bootc/tracker/-/issues/80 + mask_opts="" + for service in systemd-resolved.service systemd-resolved-varlink.socket systemd-resolved-monitor.socket ; do + mask_opts="${mask_opts} --security-opt mask=/usr/lib/systemd/system/${service}" + done + + sudo podman run --privileged -d \ + -v /dev:/dev \ + --tmpfs /var/lib/containers \ + --name microshift-okd \ + ${mask_opts} \ + "${{ inputs.bootc-image-url }}:${{ inputs.bootc-image-tag }}" + + # Wait up to 60 seconds for the container to initialize the system services + is_running=false + for _ in {1..60}; do + running=$(sudo podman exec -i microshift-okd systemctl is-system-running || true) + if [ "${running}" = "running" ] || [ "${running}" = "degraded" ] ; then + is_running=true + break; + fi + sleep 1; + done + if [ "${is_running}" = "false" ]; then + echo "ERROR: The container did not initialize the system services within 60 seconds" + exit 1 + fi + + - name: Run the quick RPM installation script + shell: bash + run: | + set -euo pipefail + set -x + + sudo podman exec -i microshift-okd \ + env TAG="${{ inputs.install-tag }}" \ + bash -xeuo pipefail < ./src/quickrpm.sh + + # Restart the greenboot service synchronously to check the health of the system. + # The command exits with the status of the service. + sudo podman exec -i microshift-okd systemctl restart greenboot-healthcheck.service + + - name: Run the quick clean script + if: ${{ inputs.run-clean == 'true' }} + shell: bash + run: | + set -euo pipefail + set -x + + sudo podman exec -i microshift-okd \ + bash -xeuo pipefail < ./src/quickclean.sh + + - name: Clean up test container + if: always() + shell: bash + run: | + set -euo pipefail + set -x + + # Remove the container used for the test + sudo podman rm -f microshift-okd --time 0 || true + + # Uncomment this to enable tmate-debug on failure + # - name: Pause and open tmate debug session + # if: failure() + # uses: ./.github/actions/tmate-debug + + - name: Collect debug information on failure + if: failure() + uses: ./.github/actions/debug-info + + - name: Collect MicroShift container sosreport on failure + if: failure() + uses: ./.github/actions/sos-report diff --git a/.github/workflows/installers.yaml b/.github/workflows/installers.yaml index ae5de793..8bb4ab47 100644 --- a/.github/workflows/installers.yaml +++ b/.github/workflows/installers.yaml @@ -15,7 +15,38 @@ jobs: - name: Check out MicroShift upstream repository uses: actions/checkout@v4 - # Test the quick start and clean procedures with the latest published build - # of the MicroShift container image. - - name: Run the quick start script and clean scripts + # Test the quick Bootc image installation and clean procedures with the latest + # published build of the MicroShift container image. + - name: Run the quick Bootc image installation and clean scripts uses: ./.github/actions/quick-start-clean + + quick-rpm-and-clean: + if: ${{ !github.event.pull_request.draft }} + strategy: + matrix: + runners: [ubuntu-24.04, ubuntu-24.04-arm] + runs-on: ${{ matrix.runners }} + steps: + - name: Check out MicroShift upstream repository + uses: actions/checkout@v4 + + # Test the quick RPM installation and clean procedures with the latest + # published build of the MicroShift RPM packages. + # The test is run on Fedora and CentOS images (newest to oldest order). + - name: Run the quick RPM installation and clean scripts (Fedora) + uses: ./.github/actions/quick-rpm-clean + with: + bootc-image-url: registry.fedoraproject.org/fedora-bootc + bootc-image-tag: 42 + + - name: Run the quick RPM installation and clean scripts (CentOS 10) + uses: ./.github/actions/quick-rpm-clean + with: + bootc-image-url: quay.io/centos-bootc/centos-bootc + bootc-image-tag: stream10 + + - name: Run the quick RPM installation and clean scripts (CentOS 9) + uses: ./.github/actions/quick-rpm-clean + with: + bootc-image-url: quay.io/centos-bootc/centos-bootc + bootc-image-tag: stream9 diff --git a/README.md b/README.md index 392cea32..8059123d 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ The goal is to enable contributors and testers to work with an upstream build of set up using OKD components, making it easier to develop, verify, and iterate on features outside the downstream Red Hat payloads. -# Operating System Support +## Operating System Support MicroShift and its main components are available for the `x86_64` and `aarch64` architectures. RPM and DEB packages built in a container can be installed and @@ -39,33 +39,24 @@ Notes: Prebuilt MicroShift artifacts are published at the [Releases](https://github.com/microshift-io/microshift/releases) page. +MicroShift can be run on the host or inside a Bootc container. -Run the following command to quickly run the latest build of MicroShift inside a -Bootc container on your host. +* Install the [latest](https://github.com/microshift-io/microshift/releases/latest) + MicroShift RPM packages on your host and start the MicroShift service. -```bash -curl -s https://microshift-io.github.io/microshift/quickstart.sh | sudo bash -``` + ```bash + curl -s https://microshift-io.github.io/microshift/quickrpm.sh | sudo bash + ``` -When completed successfully, the command displays information about the system -setup, next steps for accessing MicroShift and uninstall instructions. - -```text -MicroShift is running in a bootc container -Hostname: 127.0.0.1.nip.io -Container: microshift-okd -LVM disk: /var/lib/microshift-okd/lvmdisk.image -VG name: myvg1 +* Bootstrap the [latest](https://github.com/microshift-io/microshift/releases/latest) + MicroShift build inside a Bootc container on your host. -To access the container, run the following command: - - sudo podman exec -it microshift-okd /bin/bash + ```bash + curl -s https://microshift-io.github.io/microshift/quickstart.sh | sudo bash + ``` -To verify that MicroShift pods are up and running, run the following command: - - sudo podman exec -it microshift-okd oc get pods -A - -To uninstall MicroShift, run the following command: - - curl -s https://microshift-io.github.io/microshift/quickclean.sh | sudo bash -``` +When completed successfully, the commands displays information about the system +setup, next steps for accessing MicroShift and uninstall instructions. ## Documentation diff --git a/docs/quickrpm.sh b/docs/quickrpm.sh new file mode 120000 index 00000000..2dc12f76 --- /dev/null +++ b/docs/quickrpm.sh @@ -0,0 +1 @@ +../src/quickrpm.sh \ No newline at end of file diff --git a/docs/run.md b/docs/run.md index 3a9a3ae3..bbe597a5 100644 --- a/docs/run.md +++ b/docs/run.md @@ -10,9 +10,9 @@ inside a Bootc container. ### Install RPM -Run the following command to install MicroShift RPM packages from the local -repository copied from the build container image. -See [Create RPM Packages](../docs/build.md#create-rpm-packages) for more information. +Run the following commands to install MicroShift RPM packages from a local repository. +This repository should be either [built locally](../docs/build.md#create-rpm-packages) +or downloaded from [Releases](https://github.com/microshift-io/microshift/releases). ```bash RPM_REPO_DIR=/tmp/microshift-rpms @@ -56,9 +56,9 @@ oc get pods -A ### Install DEB -Run the following command to install MicroShift DEB packages from the local -repository copied from the build container image. -See [Create DEB Packages](../docs/build.md#create-deb-packages) for more information. +Run the following commands to install MicroShift DEB packages from the RPM repository. +This repository should be either [built locally](../docs/build.md#create-deb-packages) +or downloaded from [Releases](https://github.com/microshift-io/microshift/releases). ```bash DEB_REPO_DIR=/tmp/microshift-rpms/deb diff --git a/docs/workflows.md b/docs/workflows.md index 85abc285..a1011ecc 100644 --- a/docs/workflows.md +++ b/docs/workflows.md @@ -34,8 +34,13 @@ The following configurations are tested: #### Installers -Run the [Quick Start](../README.md#quick-start) procedure followed by the -[quick clean](./quickclean.sh) script invocation. +Run the [Quick Start](../README.md#quick-start) procedures to verify: +* The latest published RPM packages on the supported operating systems and + architectures +* The latest published Bootc images on the supported architectures + +The [quick clean](./quickclean.sh) script is called in the end to verify the +uninstall procedure. #### Linters diff --git a/src/quickclean.sh b/src/quickclean.sh index 1798348c..66faecd9 100755 --- a/src/quickclean.sh +++ b/src/quickclean.sh @@ -10,13 +10,21 @@ if [ "$(id -u)" -ne 0 ]; then exit 1 fi -image_ref="$(podman inspect --format '{{.Image}}' microshift-okd)" - -# Stop and remove the container -podman rm -f --time 0 microshift-okd || true +# Clean up the MicroShift container and image +image_ref="$(podman inspect --format '{{.Image}}' microshift-okd 2>/dev/null || true)" +if [ -n "${image_ref:-}" ]; then + podman rm -f --time 0 microshift-okd || true + podman rmi -f "${image_ref}" || true +fi -# Remove the image -podman rmi -f "${image_ref}" || true +# Clean up the MicroShift data and uninstall RPMs +if rpm -q microshift &>/dev/null ; then + echo y | microshift-cleanup-data --all + dnf remove -y 'microshift*' + # Undo post-installation configuration + rm -f /etc/sysctl.d/99-microshift.conf + rm -f /root/.kube/config +fi # Remove the LVM disk if [ -f "${LVM_DISK}" ]; then diff --git a/src/quickrpm.sh b/src/quickrpm.sh new file mode 100755 index 00000000..3128b612 --- /dev/null +++ b/src/quickrpm.sh @@ -0,0 +1,139 @@ +#!/bin/bash +set -euo pipefail + +OWNER=${OWNER:-microshift-io} +REPO=${REPO:-microshift} +BRANCH=${BRANCH:-main} +TAG=${TAG:-latest} + +LVM_DISK="/var/lib/microshift-okd/lvmdisk.image" +VG_NAME="myvg1" + +WORKDIR=$(mktemp -d /tmp/microshift-quickrpm-XXXXXX) +trap 'rm -rf "${WORKDIR}"' EXIT + +function check_prerequisites() { + # Supported platforms + case "$(uname -m)" in + x86_64|aarch64) + ;; + *) + echo "ERROR: Unsupported platform: $(uname -m)" + exit 1 + esac + + # Supported operating systems + # shellcheck disable=SC1091 + source /etc/os-release + case "${ID}" in + centos|fedora|rhel) + ;; + *) + echo "ERROR: Unsupported operating system: ${ID}" + exit 1 + esac +} + +# The CentOS 10 Stream does not include the containernetworking-plugins package +# in the AppStream repository. Download the package from CentOS 9 Stream because +# it is required by MicroShift 4.20 and older due to cri-o dependencies. +function centos10_cni_plugins() { + # Check if the operating system is CentOS 10 Stream + # shellcheck disable=SC1091 + source /etc/os-release + if [ "${ID}" != "centos" ] || [ "${VERSION_ID}" != "10" ] ; then + return 0 + fi + + # If containernetworking-plugins is already installed, exit + if rpm -q containernetworking-plugins &>/dev/null; then + return 0 + fi + + dnf install -y \ + --repofrompath=c9appstream,"https://mirror.stream.centos.org/9-stream/AppStream/$(uname -m)/os/" \ + --repo=c9appstream \ + --nogpgcheck \ + containernetworking-plugins +} + +function install_rpms() { + # Download the RPMs from the release + mkdir -p "${WORKDIR}/rpms" + curl -L -s --retry 5 \ + "https://github.com/${OWNER}/${REPO}/releases/download/${TAG}/microshift-rpms-$(uname -m).tgz" | \ + tar zxf - -C "${WORKDIR}/rpms" + + # Download the installation scripts + for script in create_repos.sh postinstall.sh ; do + curl -fSsL --retry 5 --max-time 60 \ + "https://github.com/${OWNER}/${REPO}/raw/${BRANCH}/src/rpm/${script}" \ + -o "${WORKDIR}/${script}" + chmod +x "${WORKDIR}/${script}" + done + + # Create the RPM repository and install the RPMs + "${WORKDIR}/create_repos.sh" -create "${WORKDIR}/rpms" + # Disable weak dependencies to avoid the deployment of the microshift-networking + # RPM, which is not necessary when microshift-kindnet RPM is installed. + dnf install -y --setopt=install_weak_deps=False \ + microshift microshift-kindnet microshift-topolvm + "${WORKDIR}/create_repos.sh" -delete +} + +function prepare_lvm_disk() { + local -r lvm_disk="$1" + local -r vg_name="$2" + + if [ -f "${lvm_disk}" ]; then + echo "INFO: '${lvm_disk}' already exists. Clearing and reusing it." + dd if=/dev/zero of="${lvm_disk}" bs=1M count=100 >/dev/null + return 0 + fi + + mkdir -p "$(dirname "${lvm_disk}")" + truncate --size=1G "${lvm_disk}" + + local -r device_name="$(losetup --find --show --nooverlap "${lvm_disk}")" + vgcreate -f -y "${vg_name}" "${device_name}" +} + +function start_microshift() { + "${WORKDIR}/postinstall.sh" + systemctl start microshift.service +} + +# Check if the script is running as root +if [ "$(id -u)" -ne 0 ]; then + echo "ERROR: This script must be run as root (use sudo)" + exit 1 +fi + +# Update the 'latest' tag to the latest released version +if [ "${TAG}" == "latest" ] ; then + dnf install -y jq + TAG="$(curl -s --max-time 60 "https://api.github.com/repos/${OWNER}/${REPO}/releases/latest" | jq -r .tag_name)" + if [ -z "${TAG}" ] || [ "${TAG}" == "null" ] ; then + echo "ERROR: Could not determine the latest release tag from GitHub" + exit 1 + fi +fi + +# Run the procedures +check_prerequisites +centos10_cni_plugins +install_rpms +prepare_lvm_disk "${LVM_DISK}" "${VG_NAME}" +start_microshift + +# Follow-up instructions +echo +echo "MicroShift is running on the host" +echo "LVM disk: ${LVM_DISK}" +echo "VG name: ${VG_NAME}" +echo +echo "To verify that MicroShift pods are up and running, run the following command:" +echo " - sudo oc get pods -A --kubeconfig /var/lib/microshift/resources/kubeadmin/kubeconfig" +echo +echo "To uninstall MicroShift, run the following command:" +echo " - curl -s https://${OWNER}.github.io/${REPO}/quickclean.sh | sudo bash" diff --git a/src/quickstart.sh b/src/quickstart.sh index 3299cc50..f9e93bad 100755 --- a/src/quickstart.sh +++ b/src/quickstart.sh @@ -104,7 +104,7 @@ echo "LVM disk: ${LVM_DISK}" echo "VG name: ${VG_NAME}" echo echo "To access the container, run the following command:" -echo " - sudo podman exec -it microshift-okd /bin/bash" +echo " - sudo podman exec -it microshift-okd /bin/bash -l" echo echo "To verify that MicroShift pods are up and running, run the following command:" echo " - sudo podman exec -it microshift-okd oc get pods -A" diff --git a/src/rpm/create_repos.sh b/src/rpm/create_repos.sh index bac5f175..ac5f183c 100755 --- a/src/rpm/create_repos.sh +++ b/src/rpm/create_repos.sh @@ -50,12 +50,25 @@ fi case $1 in -create) repo_path="$2" - repo_version="$(dnf --quiet --disablerepo="*" --repofrompath=ushift,file://"${repo_path}" --enablerepo=ushift repoquery --qf "%{VERSION}" microshift | cut -d. -f1,2)" + if [ ! -d "${repo_path}" ] ; then + echo "ERROR: The RPM repository path '${repo_path}' does not exist" + exit 1 + fi + + repo_version="$(dnf --quiet --disablerepo="*" \ + --repofrompath=ushift,file://"${repo_path}" \ + --enablerepo=ushift repoquery --qf "%{VERSION}" microshift | cut -d. -f1,2)" + if [ -z "${repo_version:-}" ] ; then + echo "ERROR: Could not determine the MicroShift version from the RPM repository at '${repo_path}'" + exit 1 + fi create_repos "${repo_path}" "${repo_version}" ;; + -delete) delete_repos ;; + *) usage esac diff --git a/src/rpm/postinstall.sh b/src/rpm/postinstall.sh index 0687c5e9..a21e5e02 100755 --- a/src/rpm/postinstall.sh +++ b/src/rpm/postinstall.sh @@ -69,7 +69,7 @@ fi # directory may not exist, depending on the operating system. if [ ! -f /root/.kube/config ] ; then mkdir -p "$(readlink -f /root)/.kube" - ln -s /var/lib/microshift/resources/kubeadmin/kubeconfig /root/.kube/config + ln -sf /var/lib/microshift/resources/kubeadmin/kubeconfig /root/.kube/config fi # Enable the MicroShift service