diff --git a/.github/workflows/build-rpms.md b/.github/workflows/build-rpms.md new file mode 100644 index 0000000..9b9cdf8 --- /dev/null +++ b/.github/workflows/build-rpms.md @@ -0,0 +1,9 @@ +## MicroShift Bootc Image + +Load the image using the following command: + +```bash +sudo podman load -i microshift-bootc-image-x86_64.tgz +``` + +Review the instructions in [Run MicroShift Upstream](../../docs/run.md) to run the image. diff --git a/.github/workflows/build-rpms.yaml b/.github/workflows/build-rpms.yaml index 55247d9..796dc80 100644 --- a/.github/workflows/build-rpms.yaml +++ b/.github/workflows/build-rpms.yaml @@ -1,78 +1,122 @@ -name: Trigger Microshift upstream build +name: MicroShift RPM and Container Image Builder on: workflow_dispatch: inputs: - okd-version: - default: "4.18.0-okd-scos.4" - description: okd release from https://quay.io/repository/okd/scos-release?tab=tags + ushift-branch: + default: "main" + description: MicroShift branch from https://github.com/openshift/microshift/branches + type: string + okd-version-tag: + default: "4.19.0-okd-scos.19" + description: OKD version tag from https://quay.io/repository/okd/scos-release?tab=tags type: string action: type: choice - description: what to do? - default: run-in-bootc-container - options: - - build-upstream-rpms - - run-in-bootc-container + description: Action to perform + default: build-all + options: + - build-all + - build-rpms + - build-bootc-image + jobs: build: strategy: matrix: - #disabled arm runner because images for arm no available in okd payload- see USHIFT-5570 + # The ARM runner is disabled because OKD images for ARM are not available. + # See USHIFT-5570 runners: [ubuntu-24.04] - name: build microshift upstream + name: Build MicroShift upstream runs-on: ${{ matrix.runners }} steps: - - name: Check out microshift-upstream CI repository + - name: Check out MicroShift upstream repository uses: actions/checkout@v4 - - name: Check out microshift repository - uses: actions/checkout@v4 - with: - repository: openshift/microshift - path: microshift - ref: main + - name: Prepare the build and run environment + shell: bash + run: | + # The /dev/sdb1 partition is mounted as /mnt. + sudo mkdir -p /mnt/tmp /mnt/rpms /mnt/storage /mnt/release + sudo chmod 1777 /mnt/tmp - - name: Add cwd to path for kubectl. - run: echo `pwd` >> $GITHUB_PATH + sudo apt-get install -y make lvm2 podman - - name: Build Microshift RPMs and Container + # Redirect the container build directories to /mnt/ to avoid running out of disk space. + sudo mv /var/tmp /var/tmp.orig + sudo mv /var/lib/containers/storage /var/lib/containers/storage.orig + sudo ln -s /mnt/tmp /var/tmp + sudo ln -s /mnt/storage /var/lib/containers/storage + + - name: Build MicroShift RPMs + if: inputs.action == 'build-rpms' || inputs.action == 'build-all' shell: bash run: | - # /dev/sdb1 is mounted as /mnt - disk space needed for the podman build containers layers. - sudo mkdir -p /mnt/tmp/output + # See https://github.com/microshift-io/microshift/blob/main/docs/build.md + # for more information about the build process. + + # Raise open file limits to avoid "too many open files" errors. + ulimit -n 65536 + + # Run the RPM build process. + cd ${GITHUB_WORKSPACE}/ + make rpm \ + USHIFT_BRANCH=${{ inputs.ushift-branch }} \ + OKD_VERSION_TAG=${{ inputs.okd-version-tag }} \ + RPM_OUTDIR=/mnt/rpms + + - name: Build MicroShift bootc container image + if: inputs.action == 'build-bootc-image' || inputs.action == 'build-all' + shell: bash + run: | + # See https://github.com/microshift-io/microshift/blob/main/docs/build.md + # for more information about the build process. + + # Raise open file limits to avoid "too many open files" errors. + ulimit -n 65536 + + # Run the container image build process, first cleaning up any + # existing container images to generate a smaller artifact. cd ${GITHUB_WORKSPACE}/ - sudo apt-get install podman -y - export OKD_REPO=quay.io/okd/scos-release - # podman version applies bad ulimits default causing "too many open files" errors so we override ulimits. - TMPDIR=/mnt/tmp sudo podman build --layers=false --ulimit nofile=65536:65536 \ - --build-arg OKD_VERSION_TAG=${{ inputs.okd-version }} \ - --build-arg OKD_REPO=${OKD_REPO} \ - --env WITH_TOPOLVM=1 \ - --env WITH_KINDNET=1 \ - --env OUTPUT_DIR=/output \ - -f microshift-okd-multi-build.Containerfile \ - -t microshift-okd \ - -v /mnt/tmp/output:/output:z . - - name: run test verifying that Microshift is running - if: inputs.action == 'run-in-bootc-container' + make clean image \ + USHIFT_BRANCH=${{ inputs.ushift-branch }} \ + OKD_VERSION_TAG=${{ inputs.okd-version-tag }} + + - name: Run a test to verify that MicroShift is functioning properly. + if: inputs.action == 'build-bootc-image' || inputs.action == 'build-all' shell: bash run: | - sudo apt-get -y install lvm2 - sudo truncate --size=20G /tmp/lvmdisk - sudo losetup -f /tmp/lvmdisk - device_name=$(losetup -j /tmp/lvmdisk | cut -d: -f1) - sudo vgcreate -f -y myvg1 ${device_name} - sudo lvcreate -T myvg1/thinpool -L 6G - sudo podman run --privileged --rm --name microshift-okd --volume /dev:/dev:rslave --hostname 127.0.0.1.nip.io -d microshift-okd - sleep 3 - # wait until everything is running - sudo podman exec -ti microshift-okd bash -c 'microshift healthcheck --namespace topolvm-system --deployments topolvm-controller' - - name: prepare release acrhive + # See https://github.com/microshift-io/microshift/blob/main/docs/run.md + # for more information about the run process. + + # Prepare the TopoLVM CSI backend on the host to be used by MicroShift when compiled with the default `WITH_TOPOLVM=1` built option. + LVM_DISK=/mnt/lvmdisk.image + VG_NAME=myvg1 + + sudo truncate --size=1G "${LVM_DISK}" + sudo losetup -f "${LVM_DISK}" + + DEVICE_NAME="$(sudo losetup -j "${LVM_DISK}" | cut -d: -f1)" + sudo vgcreate -f -y "${VG_NAME}" "${DEVICE_NAME}" + + # Run the MicroShift container. + make run && sleep 5 + + # Wait until everything is up and running. + sudo podman exec -it microshift-okd \ + bash -c 'microshift healthcheck -v=2 --timeout=600s --namespace topolvm-system --deployments topolvm-controller' + + # Stop the MicroShift container. + make stop + + - name: Prepare the RPM archive. + if: inputs.action == 'build-rpms' || inputs.action == 'build-all' shell: bash run : | - cd /mnt/tmp/output/rpmbuild/RPMS/ - sudo zip microshift-x86_64.zip \ + cd /mnt/rpms + find . -type f -name "microshift-*.rpm" + + sudo tar zcvf /mnt/release/microshift-rpms-x86_64.tgz \ x86_64/microshift-[0-9]*.rpm \ x86_64/microshift-topolvm-*.rpm \ x86_64/microshift-networking-*.rpm \ @@ -80,13 +124,30 @@ jobs: noarch/microshift-release-info-*.rpm \ noarch/microshift-greenboot-*.rpm \ noarch/microshift-selinux-*.rpm \ - noarch/microshift-topolvm-*.rpm \ noarch/microshift-kindnet-*.rpm + - name: Prepare the bootc image archive. + if: inputs.action == 'build-bootc-image' || inputs.action == 'build-all' + shell: bash + run : | + sudo bash -c \ + 'podman save microshift-okd | gzip > /mnt/release/microshift-bootc-image-x86_64.tgz' + + - name: Release RPMs. + if: inputs.action == 'build-rpms' || inputs.action == 'build-all' + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ inputs.ushift-branch }}-${{ inputs.okd-version-tag }} + files: | + /mnt/release/microshift-rpms-x86_64.tgz + overwrite_files: true - - name: Release if the previous test passed + - name: Release bootc image. + if: inputs.action == 'build-bootc-image' || inputs.action == 'build-all' uses: softprops/action-gh-release@v2 with: - tag_name: 4.19.0 + tag_name: ${{ inputs.ushift-branch }}-${{ inputs.okd-version-tag }} files: | - /mnt/tmp/output/rpmbuild/RPMS/microshift-x86_64.zip + /mnt/release/microshift-bootc-image-x86_64.tgz + overwrite_files: true + body_path: .github/workflows/build-rpms.md diff --git a/Makefile b/Makefile index 152dcf2..3c4c8c4 100644 --- a/Makefile +++ b/Makefile @@ -72,6 +72,7 @@ run: sudo podman run --privileged --rm -d \ --name microshift-okd \ --volume /dev:/dev:rslave \ + --hostname 127.0.0.1.nip.io \ microshift-okd .PHONY: login diff --git a/README.md b/README.md index b17c711..edd27cb 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,8 @@ 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. -## Build and Run +## Documentation * [Build MicroShift Upstream](./docs/build.md) * [Run MicroShift Upstream](./docs/run.md) +* [GitHub Workflows](./docs/workflows.md) diff --git a/docs/workflows.md b/docs/workflows.md new file mode 100644 index 0000000..1fd7dee --- /dev/null +++ b/docs/workflows.md @@ -0,0 +1,34 @@ +## GitHub Workflows + +The following GitHub workflows are defined at the `.github/workflows` folder: +* `MicroShift RPM and Container Image Builder` in `build-rpms.yaml` + +These workflows can be run under the [Actions](https://github.com/microshift-io/microshift/actions) +tab by the repository maintainers. Other contributors can +[create a fork](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo#forking-a-repository) +from the [MicroShift Upstream](https://github.com/microshift-io/microshift) repository +and run existing or create new workflows in their private repository branches. + +The remainder of this document describes the existing workflows and their functionality. + +### MicroShift RPM and Container Image Builder + +The workflow implements a build process producing MicroShift RPM and Bootc +container image artifacts. + +The following parameters determine the MicroShift source code branch and OKD +container dependencies used during the build process. +* MicroShift branch from https://github.com/openshift/microshift/branches +* OKD version tag from https://quay.io/repository/okd/scos-release?tab=tags + +The following actions are suppported. +* `build-all`: Builds both MicroShift RPMs and Bootc container images +* `build-rpms`: Builds only the MicroShift RPM packages +* `build-bootc-images`: Builds only the Bootc container images + +Note: When the Bootc container images are built, one of the workflow steps tests +the validity of the produced artifacts by attempting to run the container image +and making sure all the MicroShift services are functional. + +The build artifacts are available for download under [Releases](https://github.com/microshift-io/microshift/releases) +after the job finishes successfully. diff --git a/gh-workflows/README.md b/gh-workflows/README.md deleted file mode 100644 index 6d3515c..0000000 --- a/gh-workflows/README.md +++ /dev/null @@ -1,20 +0,0 @@ - -### Goals -- **Create a CI job that runs on demand to build and test MicroShift upstream.** - > This job should combine the MicroShift sources with the specified OKD release payload for testing. -- **Create a CI job that runs on demand to build and produce MicroShift upstream RPMs.** - > This job should combine the latest MicroShift sources with the specified OKD release payload - -### installing the example workflow -1. [Create](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo#forking-a-repository) a fork from https://github.com/openshift/microshift -2. Copy the gh-action workflow example from `okd/gh-workflows/microshift-build-example.yml` to `.github/workflows/main.yaml` and push to the forked repository. -### Building upstream RPMs -1. From within GH Actions UI select the workflow and click `Run Workflow` -2. Run the workflow with the following input options: - - Released/Publish OKD version in [okd/scos-release](https://quay.io/repository/okd/scos-release?tab=tags): ie `4.17.0-okd-scos.ec.2` - - what to do: - - Building upstream RPMs Only - > ![Build upstream RPMs](build-upstream-rpms-only.png) - - Building & running MicroShift in a bootc container, making sure all the MicroShift services are up and functional (using greenboot checks). - > ![Run bootc container](run-in-bootc-container.png) -3. RPM artifacts will be available for download after the job completes. diff --git a/gh-workflows/build-upstream-rpms-only.png b/gh-workflows/build-upstream-rpms-only.png deleted file mode 100644 index 211dc36..0000000 Binary files a/gh-workflows/build-upstream-rpms-only.png and /dev/null differ diff --git a/gh-workflows/microshift-build-example.yaml b/gh-workflows/microshift-build-example.yaml deleted file mode 100644 index d76d27c..0000000 --- a/gh-workflows/microshift-build-example.yaml +++ /dev/null @@ -1,68 +0,0 @@ - -name: Trigger Microshift upstream build - -on: - workflow_dispatch: - inputs: - okd-version: - default: "4.17.0-okd-scos.ec.2" - description: okd release from https://quay.io/repository/okd/scos-release?tab=tags - type: string - action: - type: choice - description: what to do? - default: run-in-bootc-container - options: - - build-upstream-rpms - - run-in-bootc-container -jobs: - build: - name: build microshift upstream - runs-on: ubuntu-24.04 - steps: - - name: Check out microshift repository - uses: actions/checkout@v3 - - - name: Add cwd to path for kubectl. - run: echo `pwd` >> $GITHUB_PATH - - - name: Build Microshift RPMs - shell: bash - run: | - # /dev/sdb1 is mounted as /mnt - disk space needed for the podman build containers layers. - sudo mkdir -p /mnt/tmp - sudo chown 1001:127 /mnt/tmp - - cd ${GITHUB_WORKSPACE} - mkdir output - sudo apt-get install podman -y - - # podman version applies bad ulimits default causing "too many open files" errors so we override ulimits. - TMPDIR=/mnt/tmp podman build --ulimit nofile=65536:65536 \ - --build-arg OKD_VERSION_TAG=${{ inputs.okd-version }} \ - --env WITH_KINDNET=1 \ - -f okd/src/microshift-okd-build-rpms.Containerfile \ - -v $(pwd)/output/:/src/_output/rpmbuild/RPMS/:z . - - - name: uploads artifacts - uses: actions/upload-artifact@v4 - with: - name: RPMs - path: output/ - - - name: build Microshift image with sudo - if: inputs.action == 'run-in-bootc-container' - shell: bash - run: | - cd ${GITHUB_WORKSPACE} - sudo podman build --env WITH_KINDNET=1 -f okd/src/microshift-okd-run.Containerfile -v $(pwd)/output/:/tmp/rpm-repo:z . -t microshift-okd - - - - name: run Microshift container with sudo - if: inputs.action == 'run-in-bootc-container' - shell: bash - run: | - sudo podman run --privileged --rm --name microshift-okd -d microshift-okd - sleep 3 - # wait until everything is running - sudo podman exec -ti microshift-okd bash -c '/etc/greenboot/check/required.d/40_microshift_running_check.sh && oc get pods -A' diff --git a/gh-workflows/run-in-bootc-container.png b/gh-workflows/run-in-bootc-container.png deleted file mode 100644 index c462293..0000000 Binary files a/gh-workflows/run-in-bootc-container.png and /dev/null differ diff --git a/packaging/microshift-cos9.Containerfile b/packaging/microshift-cos9.Containerfile index b6dec3a..d6f269c 100644 --- a/packaging/microshift-cos9.Containerfile +++ b/packaging/microshift-cos9.Containerfile @@ -43,7 +43,7 @@ RUN echo '{"auths":{"fake":{"auth":"aWQ6cGFzcwo="}}}' > /tmp/.pull-secret && \ # Building Microshift RPMs and local repo RUN WITH_KINDNET="${WITH_KINDNET}" WITH_TOPOLVM="${WITH_TOPOLVM}" WITH_OLM="${WITH_OLM}" \ - make rpm srpm && \ + make rpm && \ createrepo -v "${REPO_DIR}" # Building microshift container from local RPMs