diff --git a/packaging/rpm/make-microshift-app-images-rpm.sh b/packaging/rpm/make-microshift-app-images-rpm.sh new file mode 100755 index 0000000000..1c52ce1d3c --- /dev/null +++ b/packaging/rpm/make-microshift-app-images-rpm.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash + +# First arg: file path containing user images per line +# Second arg: container storage dir path +# Third arg: RPMBUILD_DIR + +RPMBUILD_DIR=$3 +_img_dir_=$2 + +declare -a ARRAY + +#link filedescriptor 10 with stdin (standard input) +exec 10<&0 + +#stdin replaced with a file supplied as a first argument +exec < $1 +let count=0 + +#read user images into ARRAY +while read LINE; do + ARRAY[$count]=$LINE + ((count++)) +done + +#restore stdin from file descriptor 10 then close filedescriptor 10 +exec 0<&10 10<&- + +#Generate microshift-app-images.spec +touch ./microshift-app-images.spec +cat >./microshift-app-images.spec < /dev/null && pwd )" +BASE_VERSION="$(${SCRIPT_DIR}/../../pkg/release/get.sh base)" +TARBALL_FILE="microshift-pkg-release-${BASE_VERSION}.tar.gz" +RPMBUILD_DIR="${SCRIPT_DIR}/_rpmbuild/" +BUILD=${BUILD:-$2} +BUILD=${BUILD:-all} +TARGET=${TARGET:-$3} +TARGET=${TARGET:-x86_64} + + +case $BUILD in + all) RPMBUILD_OPT=-ba ;; + rpm) RPMBUILD_OPT=-bb ;; + srpm) RPMBUILD_OPT=-bs ;; +esac + +ARCHITECTURES=${ARCHITECTURES:-"x86_64 arm64 arm ppc64le riscv64"} + +build() { + cat >"${RPMBUILD_DIR}"SPECS/microshift-images.spec <> "${RPMBUILD_DIR}"SPECS/microshift-images.spec + echo "" >> "${RPMBUILD_DIR}"SPECS/microshift-images.spec + done + + cat "${SCRIPT_DIR}/microshift-images.spec" >> "${RPMBUILD_DIR}SPECS/microshift-images.spec" + + sudo rpmbuild "${RPMBUILD_OPT}" --target $TARGET --define "_topdir ${RPMBUILD_DIR}" "${RPMBUILD_DIR}SPECS/microshift-images.spec" +} + +# prepare the rpmbuild env +mkdir -p "${RPMBUILD_DIR}"/{BUILD,RPMS,SOURCES,SPECS,SRPMS} + +case $1 in + local) + build + ;; + *) + echo "Usage: $0 local [all|rpm|srpm]" + exit 1 +esac diff --git a/packaging/rpm/microshift-images.spec b/packaging/rpm/microshift-images.spec new file mode 100644 index 0000000000..6d2abcabbe --- /dev/null +++ b/packaging/rpm/microshift-images.spec @@ -0,0 +1,116 @@ +Name: microshift-images + +# disable dynamic rpmbuild checks +%global __os_install_post /bin/true +%global __arch_install_post /bin/true +AutoReqProv: no + +# where do we want the images to be stored on the final system +%global imageStore /opt/microshift/images +%global imageStoreSed %(echo %{imageStore} | sed 's/\//\\\//g') + +%define version %(echo %{baseVersion} | sed s/-/_/g) + +# to-be-improved: +# avoid warnings for container layers: +# - warning: absolute symlink: +# - warning: Duplicate build-ids + +Version: %{version} +Release: 2 + +Summary: MicroShift related container images +License: Apache License 2.0 +URL: https://github.com/redhat-et/microshift + +BuildRequires: podman +Requires: crio + + +%description +This rpm creates a custom RO container storage for the MicroShift container images +and pull images and add path to additional container image stores. + +%prep + + +if [ -d %{buildroot}%{imageStore} ] +then + sudo rm -rf %{buildroot}%{imageStore} +fi + +%build + + +%install + +mkdir -p %{buildroot}%{imageStore} + +%define arch %{_arch} + +# aarch64 is arm64 for container regisitries + +%ifarch %{arm} aarch64 +%define arch arm64 +%endif + +pull_arch="--arch %{arch}" + +# for x86_64 we don't want to specify the arch otherwise quay gets grumpy + +%ifarch x86_64 +pull_arch="" +images=%{images_x86_64} +%endif + +%ifarch %{arm} +images=%{images_arm} +%endif + +%ifarch %{arm} aarch64 +images=%{images_arm64} +%endif + +%ifarch ppc64le +images=%{images_ppc64le} +%endif + +%ifarch riscv64 +images=%{images_riscv64} +%endif + + +for val in ${images}; do + podman pull ${pull_arch} --root %{buildroot}%{imageStore} $val +done + +# check, why do we need this? +# sudo chmod -R a+rx %{imageStore} + +%post + +# only on install (1), not on upgrades (2) +if [ $1 -eq 1 ]; then + sed -i '/^additionalimagestores =*/a "%{imageStore}",' /etc/containers/storage.conf + # if crio was already started, restart it so it read from new imagestore + systemctl is-active --quiet crio && systemctl restart --quiet crio +fi + +%postun + +# only on uninstall (0), not on upgrades(1) +if [ $1 -eq 0 ]; + sed -i '/"${imageStoreSed}",/d" /etc/containers/storage.conf + systemctl is-active --quiet crio && systemctl restart --quiet crio + +fi + +%files +%{imageStore}/* + +%changelog +* Wed Mar 2 2022 Miguel Angel Ajo . 4.8.0_0.okd_2021_10_10_030117-2 +- Automatically get architecture images and OKD base version + +* Wed Feb 16 2022 Parul Singh . 4.8.0-0.microshiftr-2022_02_02_194009_3 +- Initial packaging of additional RO container storage. diff --git a/pkg/release/get.sh b/pkg/release/get.sh new file mode 100755 index 0000000000..2b3ad3ddff --- /dev/null +++ b/pkg/release/get.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +function get_base { + grep "var Base" "${SCRIPT_DIR}/release.go" | cut -d\" -f 2 +} + +function add_bases { + base=$(get_base) + sed "s/:$/:${base}/g" # some lines have "xxxxx:" + Base like flannel +} + +function get_image_list { + + cat $1 | grep "Image = map\[string\]string" -A 100 | grep '":' | cut -d\" -f4 | \ + add_bases +} + +function get_images { + arch=$1 + case $arch in + x86_64|amd64) get_image_list "${SCRIPT_DIR}/release_amd64.go" ;; + *) get_image_list "${SCRIPT_DIR}/release.go" ;; + esac +} + +function usage { + echo "usage:" + echo " get.sh base : prints the OKD base version for this MicroShift codebase" + echo " get.sh images : prints image list used by this MicroShift codebase and architecture" + exit 1 +} + +case $1 in + base) get_base ;; + images) get_images $2 ;; + *) usage +esac + +