Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ ISOLATED_NETWORK ?= 0
# Internal variables
SHELL := /bin/bash
# Override the default OKD_RELEASE_IMAGE variable based on the architecture
OKD_RELEASE_IMAGE_X86_64 ?= quay.io/okd/scos-release
OKD_RELEASE_IMAGE_AARCH64 ?= ghcr.io/microshift-io/okd/okd-release-arm64
ifeq ($(ARCH),aarch64)
OKD_RELEASE_IMAGE ?= ghcr.io/microshift-io/okd/okd-release-arm64
OKD_RELEASE_IMAGE ?= $(OKD_RELEASE_IMAGE_AARCH64)
else
OKD_RELEASE_IMAGE ?= quay.io/okd/scos-release
OKD_RELEASE_IMAGE ?= $(OKD_RELEASE_IMAGE_X86_64)
endif

BUILDER_IMAGE := microshift-okd-builder
USHIFT_IMAGE := microshift-okd
SRPM_IMAGE := microshift-okd-srpm
LVM_DISK := /var/lib/microshift-okd/lvmdisk.image
VG_NAME := myvg1

Expand All @@ -44,8 +47,9 @@ VG_NAME := myvg1
#
.PHONY: all
all:
@echo "make <rpm | image | run | add-node | start | stop | clean | check>"
@echo "make <rpm | srpm | image | run | add-node | start | stop | clean | check>"
@echo " rpm: build the MicroShift RPMs"
@echo " srpm: build the MicroShift SRPM"
@echo " image: build the MicroShift bootc container image"
@echo " run: create and run a MicroShift cluster (1 node) in a bootc container"
@echo " add-node: add a new node to the MicroShift cluster in a bootc container"
Expand Down Expand Up @@ -82,6 +86,20 @@ rpm:
echo "Build completed successfully" && \
echo "RPMs are available in '$${outdir}'"

.PHONY: srpm
srpm:
@echo "Building the MicroShift SRPM image"
outdir="$${SRPM_WORKDIR:-$$(mktemp -d /tmp/microshift-srpms-XXXXXX)}" && \
sudo podman build \
-t "${SRPM_IMAGE}" \
--build-arg USHIFT_GITREF="${USHIFT_GITREF}" \
--build-arg OKD_VERSION_TAG="${OKD_VERSION_TAG}" \
--build-arg OKD_RELEASE_IMAGE_X86_64="${OKD_RELEASE_IMAGE_X86_64}" \
--build-arg OKD_RELEASE_IMAGE_AARCH64="${OKD_RELEASE_IMAGE_AARCH64}" \
--volume "$${outdir}:/output:Z" \
-f packaging/srpm.Containerfile . && \
echo "SRPMs are available in '$${outdir}'"

.PHONY: rpm-to-deb
rpm-to-deb:
if [ -z "${RPM_OUTDIR}" ] ; then \
Expand Down
72 changes: 72 additions & 0 deletions packaging/srpm.Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Using Fedora for easy access to the dependencies (no need to install EPEL or use pip)
FROM quay.io/fedora/fedora:42

RUN dnf install -y \
--setopt=install_weak_deps=False \
git rpm-build jq python3-pip python3-specfile && \
dnf clean all

# Variables controlling the source of MicroShift components to build
ARG USHIFT_GITREF=main
ARG OKD_VERSION_TAG

# Internal variables
ARG OKD_RELEASE_IMAGE_X86_64=quay.io/okd/scos-release
ARG OKD_RELEASE_IMAGE_AARCH64=ghcr.io/microshift-io/okd/okd-release-arm64
ARG USHIFT_GIT_URL=https://github.com/openshift/microshift.git
ENV HOME=/home/microshift
ARG USHIFT_PREBUILD_SCRIPT=/tmp/prebuild.sh
ARG USHIFT_BUILDRPMS_SCRIPT=/tmp/build-rpms.sh
ARG USHIFT_MODIFY_SPEC_SCRIPT=/tmp/modify-spec.py
ARG SPEC_KINDNET=/tmp/kindnet.spec
ARG SPEC_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 quay.io/okd/scos-release for a list of tags"; \
exit 1; \
fi

RUN [ "$(uname -m)" = "aarch64" ] && ARCH="-arm64" || ARCH="" ; \
OKD_CLIENT_URL="https://github.com/okd-project/okd/releases/download/${OKD_VERSION_TAG}/openshift-client-linux${ARCH}-${OKD_VERSION_TAG}.tar.gz" && \
echo "OKD_CLIENT_URL: ${OKD_CLIENT_URL}" && \
curl -L --retry 5 -o /tmp/okd-client.tar.gz "${OKD_CLIENT_URL}" && \
tar -xzf /tmp/okd-client.tar.gz -C /tmp && \
mv /tmp/oc /usr/local/bin/oc && \
rm -rf /tmp/okd-client.tar.gz ;

WORKDIR ${HOME}

RUN git clone --branch "${USHIFT_GITREF}" --single-branch "${USHIFT_GIT_URL}" "${HOME}/microshift"

# Replace component images with OKD image references
COPY --chmod=755 ./src/image/prebuild.sh ${USHIFT_PREBUILD_SCRIPT}
RUN ARCH="x86_64" "${USHIFT_PREBUILD_SCRIPT}" --replace "${OKD_RELEASE_IMAGE_X86_64}" "${OKD_VERSION_TAG}" && \
ARCH="aarch64" "${USHIFT_PREBUILD_SCRIPT}" --replace "${OKD_RELEASE_IMAGE_AARCH64}" "${OKD_VERSION_TAG}"

WORKDIR ${HOME}/microshift/

COPY ./src/kindnet/kindnet.spec "${SPEC_KINDNET}"
COPY ./src/kindnet/assets/ ./assets/optional/
COPY ./src/kindnet/dropins/ ./packaging/kindnet/
COPY ./src/kindnet/crio.conf.d/ ./packaging/crio.conf.d/

COPY ./src/topolvm/topolvm.spec "${SPEC_TOPOLVM}"
COPY ./src/topolvm/assets/ ./assets/optional/topolvm/
COPY ./src/topolvm/dropins/ ./packaging/microshift/dropins/
COPY ./src/topolvm/greenboot/ ./packaging/greenboot/
COPY ./src/topolvm/release/ ./assets/optional/topolvm/

RUN ARCH="x86_64" "${USHIFT_PREBUILD_SCRIPT}" --replace-kindnet "${OKD_RELEASE_IMAGE_X86_64}" "${OKD_VERSION_TAG}" && \
ARCH="aarch64" "${USHIFT_PREBUILD_SCRIPT}" --replace-kindnet "${OKD_RELEASE_IMAGE_AARCH64}" "${OKD_VERSION_TAG}"

COPY --chmod=755 ./src/image/modify-spec.py ${USHIFT_MODIFY_SPEC_SCRIPT}
# Disable the RPM and SRPM checks in the make-rpm.sh script
# and modify the microshift.spec to remove packages not yet supported by the upstream
RUN sed -i -e 's,CHECK_RPMS="y",,g' -e 's,CHECK_SRPMS="y",,g' ./packaging/rpm/make-rpm.sh && \
"${USHIFT_MODIFY_SPEC_SCRIPT}" ./packaging/rpm/microshift.spec "${SPEC_KINDNET}" "${SPEC_TOPOLVM}"

COPY --chmod=755 ./src/image/build-rpms.sh ${USHIFT_BUILDRPMS_SCRIPT}
RUN "${USHIFT_BUILDRPMS_SCRIPT}" srpm && \
cp ./_output/rpmbuild/SRPMS/* /output/
3 changes: 2 additions & 1 deletion src/image/build-rpms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ export MICROSHIFT_VARIANT

if [[ "${target}" == "all" || "${target}" == "rpm" ]]; then
./packaging/rpm/make-rpm.sh rpm local
echo "${MICROSHIFT_VERSION}" > _output/rpmbuild/RPMS/version.txt
fi

if [[ "${target}" == "all" || "${target}" == "srpm" ]]; then
./packaging/rpm/make-rpm.sh srpm local
echo "${MICROSHIFT_VERSION}" > _output/rpmbuild/SRPMS/version.txt
fi

echo "${MICROSHIFT_VERSION}" > _output/rpmbuild/RPMS/version.txt
2 changes: 1 addition & 1 deletion src/image/modify-spec.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

"""
Following script modifies downstream microshift.spec to remove packages not yet supported by the upstream.
Expand Down
17 changes: 12 additions & 5 deletions src/image/prebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
set -euo pipefail

MICROSHIFT_ROOT="/home/microshift/microshift"
ARCH="$(uname -m)"
ARCH="${ARCH:-$(uname -m)}"
declare -A UNAME_TO_GOARCH_MAP=( ["x86_64"]="amd64" ["aarch64"]="arm64" )

RELEASE_IMAGE_CACHE=$(mktemp "/tmp/release-image-cache-${ARCH}.XXXXX.json")
Comment thread
pmtk marked this conversation as resolved.
trap 'rm -f "${RELEASE_IMAGE_CACHE}"' EXIT

oc_release_info() {
local -r okd_url=$1
local -r okd_releaseTag=$2
Expand All @@ -15,7 +18,11 @@ oc_release_info() {
return
fi

local -r okd_image="$(oc adm release info --image-for="${image}" "${okd_url}:${okd_releaseTag}")"
if [ ! -s "${RELEASE_IMAGE_CACHE}" ] ; then
oc adm release info "${okd_url}:${okd_releaseTag}" -o json > "${RELEASE_IMAGE_CACHE}"
fi

local -r okd_image="$(jq -r --arg IMAGE "${image}" '.references.spec.tags[] | select(.name == $IMAGE) | .from.name' "${RELEASE_IMAGE_CACHE}")"
if [ -z "${okd_image}" ] ; then
echo "ERROR: No OKD image found for '${image}'"
exit 1
Expand Down Expand Up @@ -49,7 +56,7 @@ replace_base_assets() {
local new_image
new_image=$(oc_release_info "${okd_url}" "${okd_releaseTag}" "${cur_image}")

echo "Replacing '${cur_image}' with '${new_image}'"
echo "[${ARCH}] Replacing '${cur_image}' with '${new_image}'"
jq --arg a "${cur_image}" --arg b "${new_image}" '.images[$a] = $b' "${MICROSHIFT_ROOT}/assets/release/release-${ARCH}.json" >"${temp_json}"
mv "${temp_json}" "${MICROSHIFT_ROOT}/assets/release/release-${ARCH}.json"
done
Expand Down Expand Up @@ -93,7 +100,7 @@ EOF
# Get the new image from OKD release
local new_image
new_image=$(oc_release_info "${okd_url}" "${okd_releaseTag}" "${container}")
echo "Replacing '${container}' with '${new_image}'"
echo "[${ARCH}] Replacing '${container}' with '${new_image}'"
local new_image_name="${new_image%@*}"
local new_image_digest="${new_image#*@}"

Expand Down Expand Up @@ -142,7 +149,7 @@ replace_kindnet_assets() {

# Kube proxy is required for kindnet
local -r image_with_hash=$(oc_release_info "${okd_url}" "${okd_releaseTag}" "kube-proxy")
echo "Replacing 'kube-proxy' with '${image_with_hash}'"
echo "[${ARCH}] Replacing 'kube-proxy' with '${image_with_hash}'"
# The OKD image we retrieve is in the format quay.io/okd/scos-content@sha256:<hash>,
# where the image name and digest (hash) are combined in a single string.
# However, in the kustomization.${arch}.yaml file, we need the image name (newName) and
Expand Down
Loading