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
83 changes: 83 additions & 0 deletions packaging/rpm/make-microshift-app-images-rpm.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably propagate the changes from the other spec here.

But I propose we merge, and then we keep working on the userland side.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mangelajo good idea. Could you open an issue for that please so we don't forget?

%global _img_dir $_img_dir_
%global imageStore %{buildroot}%{_img_dir}
%global _IMAGES_ ${ARRAY[@]}

Name: microshift-app-images
Version: 1
Release: 1
Summary: Creates RO container storage for user applications
License: Apache License 2.0
URL: https://github.com/redhat-et/microshift

BuildRequires: podman
BuildRequires: crio


%description
This rpm creates a RO container storage for user applications, pull the app images and add the path to additional container image stores on target machine.

%prep

if [ -d %{imageStore} ]
then
sudo rm -rf %{imageStore}
fi

%build

%install

mkdir -p %{imageStore}

declare -a ListOfImages=(%{_IMAGES_})


for val in \${ListOfImages[@]}; do
sudo podman pull --root %{imageStore} \$val
done
sudo chmod -R a+rx %{imageStore}


%post
sudo sed -i '/^additionalimagestores =*/a "$_img_dir_",' /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


%files
%{_img_dir}/*

EOF
cp ./microshift-app-images.spec $RPMBUILD_DIR/SPECS/microshift-app-images.spec

rpmbuild -bb --define "_topdir ${RPMBUILD_DIR}" $RPMBUILD_DIR/SPECS/microshift-app-images.spec
48 changes: 48 additions & 0 deletions packaging/rpm/make-microshift-images-rpm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
set -e -o pipefail

# generated from other info
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /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 <<EOF
%global baseVersion ${BASE_VERSION}

EOF
for arch in $ARCHITECTURES; do
echo "%define images_${arch} \"$(${SCRIPT_DIR}/../../pkg/release/get.sh images $arch | tr '\n' ' ')\"" >> "${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
116 changes: 116 additions & 0 deletions packaging/rpm/microshift-images.spec
Original file line number Diff line number Diff line change
@@ -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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this belong into the %build section, such that the RPM contains the images (rather than pulling them when installed)? Not sure the ImageBuilder can actually run stuff on podman when building ostrees.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per the doc, https://rpm-packaging-guide.github.io/#what-is-a-spec-file

%build: Command or series of commands for actually building the software into machine code (for compiled languages) or byte code (for some interpreted languages).
%Install: Command or series of commands for copying the desired build artifacts from the %builddir (where the build happens) to the %buildroot directory (which contains the directory structure with the files to be packaged). This usually means copying files from ~/rpmbuild/BUILD to ~/rpmbuild/BUILDROOT and creating the necessary directories in ~/rpmbuild/BUILDROOT. This is only run when creating a package, not when the end-user installs the package. See [Working with SPEC files](https://rpm-packaging-guide.github.io/#working-with-spec-files) for details.

Since we are not building s/w and only using rpm to package files, I put it under %install

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's .spec files just being confusing,

What you expect for install is %post

%install is the phase that takes the %build, and put's it into the fake root filesystem,
from where %file will gather stuff.


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
Comment thread
husky-parul marked this conversation as resolved.
systemctl is-active --quiet crio && systemctl restart --quiet crio

fi

%files
%{imageStore}/*

%changelog
* Wed Mar 2 2022 Miguel Angel Ajo <majopela@redhat.com> . 4.8.0_0.okd_2021_10_10_030117-2
- Automatically get architecture images and OKD base version

* Wed Feb 16 2022 Parul Singh <parsingh@redhat.com> . 4.8.0-0.microshiftr-2022_02_02_194009_3
- Initial packaging of additional RO container storage.
41 changes: 41 additions & 0 deletions pkg/release/get.sh
Original file line number Diff line number Diff line change
@@ -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 <architecture> : prints image list used by this MicroShift codebase and architecture"
exit 1
}

case $1 in
base) get_base ;;
images) get_images $2 ;;
*) usage
esac