Skip to content

Commit

Permalink
support building x86 and aarch64 RPMs, to handle the oras binary
Browse files Browse the repository at this point in the history
  • Loading branch information
bcumming committed Apr 5, 2024
1 parent a290224 commit 6a6c147
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 9 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,17 @@ jobs:
- name: build-srpm
run: |
set -x
./rpm/generate-rpm.sh -s . -b rpm-build
rpmbuild -bs --define "_topdir rpm-build" rpm-build/SPECS/uenv.spec
sudo rpmbuild --rebuild "$(find rpm-build/SRPMS -name '*.rpm' -type f -print -quit)" --define "_topdir $(pwd)/rpm-build"
# build x86)64
./rpm/generate-rpm.sh -s . -b rpm-build -a x86_64
rpmbuild -bs --define "_topdir rpm-build" --target=x86_64 rpm-build/SPECS/uenv.spec
sudo rpmbuild --target=x86_64 --rebuild "$(find rpm-build/SRPMS -name '*.rpm' -type f -print -quit)" --define "_topdir $(pwd)/rpm-build"
sudo rpm --install "$(find rpm-build/RPMS -name '*.rpm' -type f -print -quit)"
find rpm-build -name '*.rpm' -type f -exec cp {} . \;
# build aarch64
rm -rf ./rpm-build
./rpm/generate-rpm.sh -s . -b rpm-build -a aarch64
rpmbuild -bs --define "_topdir rpm-build" --target=aarch64 rpm-build/SPECS/uenv.spec
sudo rpmbuild --target=aarch64 --rebuild "$(find rpm-build/SRPMS -name '*.rpm' -type f -print -quit)" --define "_topdir $(pwd)/rpm-build"
sudo rpm --install "$(find rpm-build/RPMS -name '*.rpm' -type f -print -quit)"
find rpm-build -name '*.rpm' -type f -exec cp {} . \;
- name: upload-rpm
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ test/scratch
# site generated by mkdocs
site

# build path for rpms
rpm-build

__pycache__
27 changes: 25 additions & 2 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ version=$(cat "$script_path/VERSION")
# default installation destination, only required for building rpm packages
destdir=""

# takes an argument, either aarch64 or x86_64
# returns arm64 or amd64, accordingly
get_oras_arch() {
case "$(uname -m)" in
case "$1" in
aarch64)
echo "arm64"
;;
Expand All @@ -19,6 +21,10 @@ get_oras_arch() {
esac
}

detect_oras_arch() {
echo $(get_oras_arch "$(uname -m)")
}

function usage {
echo "uenv installer"
echo "Usage: install [--prefix=] [--yes] [--help]"
Expand All @@ -27,6 +33,7 @@ function usage {
echo "--local : install locally for this user (default prefix \$HOME/.local)"
echo "--yes : default response to all queries is yes"
echo "--help : print this message"
echo "--arch : force installing for a specific arch: x86_64 or aarch64"
}

function prompt_bash_update {
Expand Down Expand Up @@ -79,6 +86,13 @@ always_yes=no
# default install system wide
local_install=no

# Set the architecture of the system we are installing on.
# Required when building RPMs on a system with a different arch
# than the RPM target.
# Note: only needed to download the appropriate oras tar ball
# by default we set it to auto, which tries to automatically detect the arch
oras_arch=auto

# dry-run (systemwide install only)
uenv_debug=no

Expand All @@ -105,6 +119,9 @@ do
--debug)
uenv_debug=yes
;;
--arch=*)
oras_arch="${arg#*=}"
;;
--help)
usage
exit 0
Expand Down Expand Up @@ -166,7 +183,13 @@ run install -D -m755 <(sed "s|@@version@@|$version|g" $script_path/uenv-impl) ${

# install the oras client
echo "installing oras client"
oras_arch=$(get_oras_arch)
# if an architecture is not provided -> auto detect arch
if [[ "$oras_arch" == "auto" ]]
then
oras_arch=$(detect_oras_arch)
else
oras_arch=$(get_oras_arch "$oras_arch")
fi
oras_version=1.1.0
oras_file=oras_${oras_version}_linux_${oras_arch}.tar.gz
oras_url=https://github.com/oras-project/oras/releases/download/v${oras_version}/${oras_file}
Expand Down
11 changes: 9 additions & 2 deletions rpm/generate-rpm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ set -e

# By default use the current path as the root for source and build.
# This can be configured using command line args for out of tree builds.

source_path="$PWD"
build_path="$PWD/rpmbuild"
while getopts s:b: flag

# By default build for x86_64
# We don't actually build anything - instead the arch is needed to install the
# correct oras executable.
uenv_arch="x86_64"

while getopts s:b:a: flag
do
case "${flag}" in
s) source_path=${OPTARG};;
b) build_path=${OPTARG};;
a) uenv_arch=${OPTARG};;
*) echo "unknown flag ${flag}"; exit 1 ;;
esac
done
Expand Down Expand Up @@ -40,3 +46,4 @@ tar -czf "${tar_file}" --directory "${build_path}" "${pkg_name}"
spec_file="${build_path}/SPECS/uenv.spec"
cp ${source_path}/rpm/uenv.spec.in "${spec_file}"
sed -i "s|UENV_VERSION|${version}|g" "${spec_file}"
sed -i "s|UENV_ARCH|${uenv_arch}|g" "${spec_file}"
3 changes: 1 addition & 2 deletions rpm/uenv.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Summary: A command line interface for interacting with user environments
URL: https://eth-cscs.github.io/uenv
Source: %{name}-%{version}.tar.gz
License: ETH Zürich/CSCS
BuildArch: noarch

%description
A command line interface for interacting with user environments on Alps at CSCS.
Expand All @@ -15,7 +14,7 @@ A command line interface for interacting with user environments on Alps at CSCS.
%setup -q

%install
./install --yes --destdir=%{buildroot} --prefix=/opt/cscs
./install --yes --destdir=%{buildroot} --prefix=/opt/cscs --arch=UENV_ARCH

%files
/opt/cscs/uenv/
Expand Down

0 comments on commit 6a6c147

Please sign in to comment.