Add --add-i386 option to RPM build script#6251
Conversation
In commit git-lfs/build-dockers@cc16329 of PR git-lfs/build-dockers#71 we added a Dockerfile to build RPM packages of Git LFS for the Red Hat Enterprise Linux (RHEL) 10.0 and Rocky Linux 10.0 platforms. This Dockerfile originally followed the same set of steps as our Dockerfiles for the earlier RHEL/CentOS 8 and RHEL/Rocky Linux 9 platforms, and so was intended to build both 32-bit and 64-bit binaries in two separate RPM packages. However, the RHEL 10.0 and Rocky Linux 10.0 platforms only provide support for 64-bit systems, which means we should only be building 64-bit RPM packages of Git LFS for them: https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html-single/10.0_release_notes/index https://rockylinux.org/news/rocky-linux-10-0-ga-release To help resolve this issue, in commit git-lfs/build-dockers@1caa5b3 of PR git-lfs/build-dockers#76 we updated the Dockerfiles for the RHEL/CentOS 8 and RHEL/Rocky Linux 9 platforms so they now pass an explicit --add-i386 option to the "centos_script.bsh" shell script in that repository. At the same time, we also revised the script so that it passes its command-line arguments through to the "rpm/build_rpms.bsh" script in this repository. To fully resolve the issue, we now update the "rpm/build_rpms.bsh" script so that it only builds a package with a 32-bit binary if the --add-i386 option is provided. Because our Dockerfile for the RHEL/Rocky Linux 10 platforms does not pass the --add-i386 option to the "centos_script.bsh" script, the "rpm/build_rpms.bsh" script will now build only one package for these platforms, containing a 64-bit Git LFS binary. For the earlier RHEL-based platforms, though, the "rpm/build_rpms.bsh" script will receive the --add-i386 option, and will build both 32-bit and 64-bit packages.
| "${RPMBUILD[@]}" --nodeps -ba "$SPEC" | ||
| "${RPMBUILD[@]}" --nodeps --target=i686 -bb "$SPEC" | ||
|
|
||
| if [ "$#" -eq 1 ] && [ "$1" = "--add-i386" ]; then |
There was a problem hiding this comment.
nit: why do we do the args length check here? wouldn't the 2nd condition be sufficient if there is just one arg?
There was a problem hiding this comment.
It's because we run the script with the nounset shell attribute enabled.
At the top of the script, we call set -eu, and it's the -u (or nounset) attribute which will cause the script to exit if it tries to read an undefined variable.
The POSIX specification for the set shell utility describes it this way:
-uThe shell shall write a message to standard error when it tries to expand a variable that is not set and immediately exit. An interactive shell shall not exit.
Here's a small example of what happens if we were to access $1 in a script that's run without any arguments:
$ cat <<'EOF' >example.sh
#!/usr/bin/env bash
set -eu
echo "$1"
EOF
$ chmod 755 example.sh
$ ./example.sh
./example.sh: line 3: $1: unbound variable
Since we won't always pass our --add-i386 argument, so long as we've got set -u in place we have to guard against reading potentially undefined variables.
Now we could drop the nounset attribute, of course, but since it's been there a long time, I figured it was easiest just to go with what was in place already.
This PR updates the
rpm/build_rpms.bshscript we use to generate RPM packages for Git LFS releases so that the script will only build a 32-bit binary when the new--add-i386option is provided.In conjunction with the changes from PR git-lfs/build-dockers#76, this PR should ensure we only publish 64-bit RPM packages for platforms based on Red Hat Enterprise Linux (RHEL) 10.0 and the distributions we consider equivalent to it.
This PR's changes have been tested with our GitHub Actions CI and release workflows using a private repository.
Details
In commit git-lfs/build-dockers@cc16329 of PR git-lfs/build-dockers#71 we added a
Dockerfileto build RPM packages of Git LFS for the Red Hat Enterprise Linux (RHEL) 10.0 and Rocky Linux 10.0 platforms. ThisDockerfileoriginally followed the same set of steps as ourDockerfiles for the earlier RHEL/CentOS 8 and RHEL/Rocky Linux 9 platforms, and so was intended to build both 32-bit and 64-bit binaries in two separate RPM packages.However, the RHEL 10.0 and Rocky Linux 10.0 platforms only provide support for 64-bit systems, as noted in their release announcements, which means we should only be building 64-bit RPM packages of Git LFS for them.
To help resolve this issue, in commit git-lfs/build-dockers@1caa5b3 of PR git-lfs/build-dockers#76 we updated the
Dockerfiles for the RHEL/CentOS 8 and RHEL/Rocky Linux 9 platforms so they now pass an explicit--add-i386option to thecentos_script.bshshell script in that repository. At the same time, we also revised the script so that it passes its command-line arguments through to therpm/build_rpms.bshscript in this repository.To fully resolve the issue, we now update the
rpm/build_rpms.bshscript so that it only builds a package with a 32-bit binary if the--add-i386option is provided.Because our
Dockerfilefor the RHEL/Rocky Linux 10 platforms does not pass the--add-i386option to thecentos_script.bshscript, therpm/build_rpms.bshscript will now build only one package for these platforms, containing a 64-bit Git LFS binary. For the earlier RHEL-based platforms, though, therpm/build_rpms.bshscript will receive the--add-i386option, and will build both 32-bit and 64-bit packages.