Skip to content

Commit

Permalink
support building x86 and aarch64 RPMs, to handle the oras binary (#24)
Browse files Browse the repository at this point in the history
* support building x86 and aarch64 RPMs, to handle the oras binary
* bump to v4.0.1
  • Loading branch information
bcumming authored Apr 6, 2024
1 parent a290224 commit bae3315
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 12 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ jobs:
zypper install -y libmount-devel gcc make rpm-build git sudo python3 wget
- name: clone
uses: actions/checkout@v2
- name: build-srpm
- name: build
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"
sudo rpm --install "$(find rpm-build/RPMS -name '*.rpm' -type f -print -quit)"
# x86
./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"
find rpm-build -name '*.rpm' -type f -exec cp {} . \;
# aarch64
sudo 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"
find rpm-build -name '*.rpm' -type f -exec cp {} . \;
- name: upload-rpm
uses: actions/upload-artifact@v3
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__
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1.0-dev
4.0.1
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 bae3315

Please sign in to comment.