diff --git a/.github/actions/build-deb/action.yaml b/.github/actions/build-deb/action.yaml index d9a8e495..d2b1f217 100644 --- a/.github/actions/build-deb/action.yaml +++ b/.github/actions/build-deb/action.yaml @@ -39,9 +39,11 @@ runs: # Run the RPM build process. cd ${GITHUB_WORKSPACE}/ - make rpm \ + make srpm \ USHIFT_GITREF=${{ inputs.ushift-gitref }} \ - OKD_VERSION_TAG=${{ inputs.okd-version-tag }} \ + OKD_VERSION_TAG=${{ inputs.okd-version-tag }} + + make rpm \ RPM_OUTDIR=/mnt/rpms - name: Convert the MicroShift RPMs to Debian packages diff --git a/.github/actions/build/action.yaml b/.github/actions/build/action.yaml index bc113db5..4d8e9055 100644 --- a/.github/actions/build/action.yaml +++ b/.github/actions/build/action.yaml @@ -50,9 +50,11 @@ runs: # Run the RPM build process. cd ${GITHUB_WORKSPACE}/ - make rpm \ + make srpm \ USHIFT_GITREF="${{ inputs.ushift-gitref }}" \ - OKD_VERSION_TAG="${{ inputs.okd-version-tag }}" \ + OKD_VERSION_TAG="${{ inputs.okd-version-tag }}" + + make rpm \ RPM_OUTDIR=/mnt/rpms - name: Build MicroShift bootc container image diff --git a/Makefile b/Makefile index 71447dc9..f3f10140 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ else OKD_VERSION_TAG ?= $$(./src/okd/get_version.sh latest-amd64) endif RPM_OUTDIR ?= +SRPM_WORKDIR ?= # Options used in the 'image' target BOOTC_IMAGE_URL ?= quay.io/centos-bootc/centos-bootc @@ -37,7 +38,7 @@ else OKD_RELEASE_IMAGE ?= $(OKD_RELEASE_IMAGE_X86_64) endif -BUILDER_IMAGE := microshift-okd-builder +RPM_IMAGE := microshift-okd-rpm USHIFT_IMAGE := microshift-okd SRPM_IMAGE := microshift-okd-srpm LVM_DISK := /var/lib/microshift-okd/lvmdisk.image @@ -71,20 +72,22 @@ all: .PHONY: rpm rpm: - @echo "Building the MicroShift builder image" + @if ! sudo podman image exists "${SRPM_IMAGE}" ; then \ + echo "ERROR: Run 'make srpm' to build the MicroShift SRPMs" ; \ + exit 1 ; \ + fi + + @echo "Building the MicroShift RPMs image" sudo podman build \ - -t "${BUILDER_IMAGE}" \ + -t "${RPM_IMAGE}" \ --ulimit nofile=524288:524288 \ - --build-arg USHIFT_GITREF="${USHIFT_GITREF}" \ - --build-arg OKD_VERSION_TAG="${OKD_VERSION_TAG}" \ - --build-arg OKD_RELEASE_IMAGE="${OKD_RELEASE_IMAGE}" \ - -f packaging/microshift-builder.Containerfile . + -f packaging/rpm.Containerfile . @echo "Extracting the MicroShift RPMs" outdir="$${RPM_OUTDIR:-$$(mktemp -d /tmp/microshift-rpms-XXXXXX)}" && \ - mntdir="$$(sudo podman image mount "${BUILDER_IMAGE}")" && \ + mntdir="$$(sudo podman image mount "${RPM_IMAGE}")" && \ sudo cp -r "$${mntdir}/home/microshift/microshift/_output/rpmbuild/RPMS/." "$${outdir}" && \ - sudo podman image umount "${BUILDER_IMAGE}" && \ + sudo podman image umount "${RPM_IMAGE}" && \ echo "" && \ echo "Build completed successfully" && \ echo "RPMs are available in '$${outdir}'" @@ -116,7 +119,7 @@ rpm-to-deb: .PHONY: image image: - @if ! sudo podman image exists microshift-okd-builder ; then \ + @if ! sudo podman image exists "${RPM_IMAGE}" ; then \ echo "ERROR: Run 'make rpm' to build the MicroShift RPMs" ; \ exit 1 ; \ fi @@ -133,7 +136,7 @@ image: --env WITH_TOPOLVM="${WITH_TOPOLVM}" \ --env WITH_OLM="${WITH_OLM}" \ --env EMBED_CONTAINER_IMAGES="${EMBED_CONTAINER_IMAGES}" \ - -f packaging/microshift-runner.Containerfile . + -f packaging/bootc.Containerfile . .PHONY: run run: @@ -190,7 +193,8 @@ clean-all: @echo "Performing a full cleanup" $(MAKE) clean sudo podman rmi -f "${USHIFT_IMAGE}" || true - sudo podman rmi -f "${BUILDER_IMAGE}" || true + sudo podman rmi -f "${RPM_IMAGE}" || true + sudo podman rmi -f "${SRPM_IMAGE}" || true .PHONY: check check: _hadolint _shellcheck diff --git a/docs/build.md b/docs/build.md index 1d1c96d5..c15343df 100644 --- a/docs/build.md +++ b/docs/build.md @@ -16,9 +16,9 @@ Install the software necessary for running the build process: sudo dnf install -y make podman ``` -### Create RPM Packages +### Create SRPM Package -Create the MicroShift RPM packages by running the `make rpm` command. +Create the MicroShift SRPM package by running the `make srpm` command. The following options can be specified in the make command line using the `NAME=VAL` format. @@ -26,17 +26,50 @@ The following options can be specified in the make command line using the `NAME= |-----------------|----------|----------|----------| | USHIFT_GITREF | no | main | [MicroShift repository branches](https://github.com/openshift/microshift/branches) | | OKD_VERSION_TAG | no | latest | [OKD version tags](https://quay.io/repository/okd/scos-release?tab=tags) | -| RPM_OUTDIR | no | /tmp/... | RPM repository output directory | +| SRPM_WORKDIR | no | /tmp/... | SRPM repository output directory | -The `make rpm` command builds MicroShift RPMs based on CentOS Stream 9 operating -system. The `main` MicroShift repository branch and the latest OKD version tag +The `main` MicroShift repository branch and the latest OKD version tag are used by default if unspecified. +```bash +make srpm +``` + +If the build completes successfully, the `microshift-okd-srpm` container image +is created and the MicroShift SRPM and version.txt file is copied to +the `SRPM_WORKDIR` directory on the host. + +``` +... +... +SRPMs are available in '/tmp/microshift-srpms-1tzW3h' +``` + +Notes: +- The MicroShift repository branch and the OKD version tag used to build the + SRPM can be overridden by specifying `USHIFT_GITREF` and `OKD_VERSION_TAG` + make command line arguments. +- The path to the `SRPM_WORKDIR` directory (either temporary or specified in + the `make srpm` command line) is displayed in the end of the build procedure. + +### Create RPM Packages + +Create the MicroShift RPM packages by running the `make rpm` command. + +The `make rpm` command builds MicroShift RPMs for CentOS Stream 9 operating +system. RPMs are build from the SRPM built by running `make srpm`. + +The following options can be specified in the make command line using the `NAME=VAL` format. + +| Name | Required | Default | Comments | +|-----------------|----------|----------|----------| +| RPM_OUTDIR | no | /tmp/... | RPM repository output directory | + ```bash make rpm ``` -If the build completes successfully, the `microshift-okd-builder` container image +If the build completes successfully, the `microshift-okd-rpm` container image is created and the MicroShift RPM repository is copied to the `RPM_OUTDIR` directory on the host. The packages from this repository can be used to install MicroShift on the supported operating systems. @@ -49,9 +82,6 @@ RPMs are available in '/tmp/microshift-rpms-EI3IXg' ``` Notes: -- The MicroShift repository branch and the OKD version tag used to build the - packages can be overridden by specifying `USHIFT_GITREF` and `OKD_VERSION_TAG` - make command line arguments. - The path to the `RPM_OUTDIR` directory (either temporary or specified in the `make rpm` command line) is displayed in the end of the build procedure. @@ -102,7 +132,7 @@ The following options can be specified in the make command line using the `NAME= The `make image` command builds a MicroShift Bootc image based on CentOS Stream 9 operating system with the default options. The command uses artifacts from the -`microshift-okd-builder` container image created by `make rpm`. +`microshift-okd-rpm` container image created by `make rpm`. ```bash make image diff --git a/packaging/microshift-runner.Containerfile b/packaging/bootc.Containerfile similarity index 98% rename from packaging/microshift-runner.Containerfile rename to packaging/bootc.Containerfile index 3c16b991..fab3ebe0 100644 --- a/packaging/microshift-runner.Containerfile +++ b/packaging/bootc.Containerfile @@ -2,7 +2,7 @@ ARG BOOTC_IMAGE_URL=quay.io/centos-bootc/centos-bootc ARG BOOTC_IMAGE_TAG=stream9 -FROM localhost/microshift-okd-builder:latest AS builder +FROM localhost/microshift-okd-rpm:latest AS builder FROM ${BOOTC_IMAGE_URL}:${BOOTC_IMAGE_TAG} ARG REPO_CONFIG_SCRIPT=/tmp/create_repos.sh diff --git a/packaging/microshift-builder.Containerfile b/packaging/microshift-builder.Containerfile deleted file mode 100644 index a8d68ee8..00000000 --- a/packaging/microshift-builder.Containerfile +++ /dev/null @@ -1,81 +0,0 @@ -FROM quay.io/centos-bootc/centos-bootc:stream9 - -# Variables controlling the source of MicroShift components to build -ARG USHIFT_GITREF=main -ARG OKD_RELEASE_IMAGE=quay.io/okd/scos-release -ARG OKD_VERSION_TAG - -ENV OKD_VERSION_TAG=${OKD_VERSION_TAG} -ENV USHIFT_GITREF=${USHIFT_GITREF} - -# Internal variables -ARG USHIFT_GIT_URL=https://github.com/openshift/microshift.git -ENV USER=microshift -ENV HOME=/home/microshift -ARG BUILDER_RPM_REPO_PATH=${HOME}/microshift/_output/rpmbuild/RPMS -ARG USHIFT_PREBUILD_SCRIPT=/tmp/prebuild.sh -ARG USHIFT_POSTBUILD_SCRIPT=/tmp/postbuild.sh -ARG USHIFT_MODIFY_SPEC_SCRIPT=/tmp/modify-spec.py -ARG USHIFT_BUILDRPMS_SCRIPT=/tmp/build-rpms.sh -ARG SPECFILE_KINDNET=/tmp/kindnet.spec -ARG SPECFILE_TOPOLVM=/tmp/topolvm.spec - -# Verify mandatory build arguments -RUN if [ -z "${OKD_VERSION_TAG}" ] ; then \ - echo "ERROR: OKD_VERSION_TAG is not set" ; \ - echo "See ${OKD_RELEASE_IMAGE} for a list of tags" ; \ - exit 1; \ - fi - -# System setup for the build -RUN useradd -m -s /bin/bash "${USER}" && \ - echo "${USER} ALL=(ALL) NOPASSWD: ALL" > "/etc/sudoers.d/${USER}" && \ - chmod 0640 /etc/shadow && \ - dnf install -y \ - --setopt=install_weak_deps=False \ - git rpm-build jq python3-pip createrepo && \ - dnf clean all && \ - pip install specfile - -# Set the user and work directory -USER ${USER}:${USER} -WORKDIR ${HOME} - -# Preparing the OS configuration for the build -RUN git clone --branch "${USHIFT_GITREF}" --single-branch "${USHIFT_GIT_URL}" "${HOME}/microshift" && \ - echo '{"auths":{"fake":{"auth":"aWQ6cGFzcwo="}}}' > /tmp/.pull-secret && \ - "${HOME}/microshift/scripts/devenv-builder/configure-vm.sh" --no-build --no-set-release-version --skip-dnf-update /tmp/.pull-secret - -WORKDIR ${HOME}/microshift/ - -COPY --chmod=755 ./src/image/prebuild.sh ${USHIFT_PREBUILD_SCRIPT} -RUN "${USHIFT_PREBUILD_SCRIPT}" --replace "${OKD_RELEASE_IMAGE}" "${OKD_VERSION_TAG}" - -COPY --chown=${USER}:${USER} ./src/kindnet/kindnet.spec "${SPECFILE_KINDNET}" -COPY --chown=${USER}:${USER} ./src/kindnet/assets/ "${HOME}/microshift/assets/optional/" -COPY --chown=${USER}:${USER} ./src/kindnet/dropins/ "${HOME}/microshift/packaging/kindnet/" -COPY --chown=${USER}:${USER} ./src/kindnet/crio.conf.d/ "${HOME}/microshift/packaging/crio.conf.d/" -RUN "${USHIFT_PREBUILD_SCRIPT}" --replace-kindnet "${OKD_RELEASE_IMAGE}" "${OKD_VERSION_TAG}" - -COPY --chown=${USER}:${USER} ./src/topolvm/topolvm.spec "${SPECFILE_TOPOLVM}" -COPY --chown=${USER}:${USER} ./src/topolvm/assets/ "${HOME}/microshift/assets/optional/topolvm/" -COPY --chown=${USER}:${USER} ./src/topolvm/dropins/ "${HOME}/microshift/packaging/microshift/dropins/" -COPY --chown=${USER}:${USER} ./src/topolvm/greenboot/ "${HOME}/microshift/packaging/greenboot/" -COPY --chown=${USER}:${USER} ./src/topolvm/release/ "${HOME}/microshift/assets/optional/topolvm/" - -COPY --chmod=755 ./src/image/modify-spec.py ${USHIFT_MODIFY_SPEC_SCRIPT} -# Modify the microshift.spec: -# - remove packages not yet supported by the upstream -# - merge the kindnet.spec and topolvm.spec into the microshift.spec -# Disable the RPM and SRPM checks in the make-rpm.sh script to not complain about removed packages -RUN "${USHIFT_MODIFY_SPEC_SCRIPT}" ./packaging/rpm/microshift.spec "${SPECFILE_KINDNET}" "${SPECFILE_TOPOLVM}" && \ - sed -i -e 's,CHECK_RPMS="y",,g' -e 's,CHECK_SRPMS="y",,g' ./packaging/rpm/make-rpm.sh - -# Build all MicroShift downstream RPMs and SRPMs -COPY --chmod=755 ./src/image/build-rpms.sh ${USHIFT_BUILDRPMS_SCRIPT} -# hadolint ignore=DL3059 -RUN "${USHIFT_BUILDRPMS_SCRIPT}" all - -# Post-build MicroShift configuration -COPY --chmod=755 ./src/image/postbuild.sh ${USHIFT_POSTBUILD_SCRIPT} -RUN "${USHIFT_POSTBUILD_SCRIPT}" "${BUILDER_RPM_REPO_PATH}" diff --git a/packaging/rpm.Containerfile b/packaging/rpm.Containerfile new file mode 100644 index 00000000..85e8fd96 --- /dev/null +++ b/packaging/rpm.Containerfile @@ -0,0 +1,31 @@ +FROM localhost/microshift-okd-srpm:latest AS srpm + +FROM quay.io/centos/centos:stream9 + +RUN dnf install -y \ + --setopt=install_weak_deps=False \ + rpm-build which git cpio createrepo \ + gcc gettext golang jq make policycoreutils selinux-policy selinux-policy-devel systemd && \ + dnf clean all + +COPY --from=srpm /home/microshift/microshift/_output/rpmbuild/SRPMS/ /tmp/ + +ARG BUILDER_RPM_REPO_PATH=/home/microshift/microshift/_output/rpmbuild/ + +WORKDIR /tmp + +# hadolint ignore=DL4006 +RUN \ + echo "# Extract the MicroShift source code into /home/microshift/microshift - bootc builder is reusing file" && \ + rpm2cpio ./microshift-*.src.rpm | cpio -idmv && \ + mkdir -p /home/microshift/microshift && \ + tar xf ./microshift-*.tar.gz -C /home/microshift/microshift --strip-components=1 && \ + \ + echo "# Build the RPMs from the SRPM" && \ + rpmbuild --quiet --define 'microshift_variant community' --rebuild ./microshift-*.src.rpm && \ + \ + echo "# Finally, move the RPMs" && \ + mkdir -p ${BUILDER_RPM_REPO_PATH} && \ + mv /root/rpmbuild/RPMS ${BUILDER_RPM_REPO_PATH}/ && \ + createrepo -v ${BUILDER_RPM_REPO_PATH}/RPMS && \ + rm -rf /root/rpmbuild /tmp/*