fix cross-compile and packge build for platforms - first fully working state

This commit is contained in:
Mario Voigt 2025-03-11 03:02:58 +01:00
parent e92cb9a153
commit 98041ee793
4 changed files with 69 additions and 29 deletions

View File

@ -10,7 +10,8 @@
echo -e "\n+++++++++++++++++++++++++++++++++++++++++++"
echo -e "installing requirements ..."
echo -e "+++++++++++++++++++++++++++++++++++++++++++\n"
sudo apt install podman
sudo apt install podman gsasl libgsasl7-dev libssl-dev libclang-dev cmake clang capnproto mosquitto mosquitto-clients build-essential libpcsclite-dev
cargo install cross
echo -e "\n+++++++++++++++++++++++++++++++++++++++++++"

View File

@ -2,11 +2,11 @@
#the dir containing our debian source data
SRCDIR=$(pwd)
REPODIR="$(dirname "$SRCDIR")"
REPODIR="$(dirname "${SRCDIR}")"
#target dir where to put build packages
DOWNLOAD=$HOME/bffh-debian/
mkdir -p ${DOWNLOAD}
DOWNLOAD=${HOME}/bffh-debian
mkdir -p ${DOWNLOAD}/
# architecture mapping array linux <-> rust
declare -A ARCHES_LR=(
@ -24,31 +24,44 @@ declare -A ARCHES_LD=(
["amd64"]=NATIVE #just some pseudo
)
echo SRCDIR: $SRCDIR
#architecture mapping array linux <-> debian package control file
declare -A ARCHES_DP=(
["armv7"]=armhf
["aarch64"]=arm64
["amd64"]=amd64
)
echo -e "SRCDIR: ${SRCDIR}"
BFFHV=$(grep "Standards-Version: " fabaccess-bffh-src/debian/control | awk -F ' ' '{print $2}')
echo BFFH target build version: ${BFFHV}
echo -e "BFFH target build version: ${BFFHV}"
echo -e "BFFH packages (*.deb/*.rpm) will be put here: ${DOWNLOAD}"
# https://www.cyberciti.biz/faq/bash-for-loop-array/
for ARCH_L in "${!ARCHES_LR[@]}"; do
ARCH_R=${ARCHES_LR[$ARCH_L]}
ARCH_D=${ARCHES_LD[$ARCH_L]}
ARCH_P=${ARCHES_DP[$ARCH_L]}
echo -e "\n+++++++++++++++++++++++++++++++++++++++++++"
echo -e "ARCH_L (Linux) : $ARCH_L"
echo -e "ARCH_R (Rust) : $ARCH_R"
echo -e "ARCH_D (Docker) : $ARCH_D"
echo -e "ARCH_L (Linux) : ${ARCH_L}"
echo -e "ARCH_R (Rust) : ${ARCH_R}"
echo -e "ARCH_D (Docker Registry) : ${ARCH_D}"
echo -e "ARCH_P (Debian Package) : ${ARCH_P}"
echo -e "+++++++++++++++++++++++++++++++++++++++++++\n"
# remove existing target dir if exists (from possible previous builds)
if [ -f fabaccess-bffh-${BFFHV}/ ]; then
rm -rf fabaccess-bffh-${BFFHV}/
sudo rm -rf fabaccess-bffh-${BFFHV}/ #we use sudo because podman will use root permissions
fi
# Create a working dir copy which has the correct name (required by dpkg-buildpackage command)
# fix possible permission issues from previous builds
sudo chown -R $USER:$USER ${SRCDIR}/
# create a working dir copy which has the correct name (required by dpkg-buildpackage command)
cp -R fabaccess-bffh-src/ fabaccess-bffh-${BFFHV}/
# Replace target architecture in control file
# replace target architecture in control file
sed "s/Architecture: {{REPLACE_ME}}/Architecture: any/" -i fabaccess-bffh-${BFFHV}/debian/control
# declare required compiled binaries and check for existence
@ -58,21 +71,31 @@ for ARCH_L in "${!ARCHES_LR[@]}"; do
if [ -f ${BIN_BFFHD} ]; then
cp ${BIN_BFFHD} fabaccess-bffh-${BFFHV}/usr/bin/
else
echo "Error: ${BIN_BFFHD} does not exist!"
echo -e "Error: ${BIN_BFFHD} does not exist!"
exit 1
fi
if [ -f ${BIN_FABFIRE_PROVISION} ]; then
cp ${BIN_FABFIRE_PROVISION} fabaccess-bffh-${BFFHV}/usr/bin/
else
echo "Error: ${BIN_FABFIRE_PROVISION} does not exist!"
echo -e "Error: ${BIN_FABFIRE_PROVISION} does not exist!"
exit 1
fi
if [[ "$ARCH_L" == "amd64" ]]; then
echo "native architecture. no podman required"
if [[ "${ARCH_L}" == "amd64" ]]; then
echo -e "native architecture. no podman required. Building deb + rpm"
cd ${SRCDIR}/fabaccess-bffh-${BFFHV}/
#dpkg-buildpackage -us -uc -k=B8F5D56C64A6161B35FB4892188C8D1E501EBD41 --host-arch "${ARCH_L}" --target-arch "${ARCH_L}"
dpkg-buildpackage -us -uc -k=B8F5D56C64A6161B35FB4892188C8D1E501EBD41
cd ${SRCDIR}/
cp fabaccess-bffh_${BFFHV}_${ARCH_L}.deb /tmp/
cd /tmp/
sudo alien --keep-version --verbose --scripts --to-rpm /tmp/fabaccess-bffh_${BFFHV}_${ARCH_L}.deb
cp /tmp/fabaccess-bffh_${BFFHV}_*.deb ${DOWNLOAD}/
cp /tmp/fabaccess-bffh-${BFFHV}-*.rpm ${DOWNLOAD}/
else
echo "using podman"
echo -e "using podman. Building deb + rpm"
#podman ps -a
# create fresh podman container with ...
@ -81,11 +104,25 @@ for ARCH_L in "${!ARCHES_LR[@]}"; do
# - starting detached (-d) to run in background (for attaching later on)
# - start to operate on it with interactive shell --interactive --tty (or short: -it)
# - overwrite existing container if existent by using --replace
# - adding the src directory to pass it into container by -v <host_dir>:<container_dir>
# - adding the src and download directories to pass it into container by -v <host_dir>:<container_dir>
# - some environment vars (ARCH_LINUX, ARCH_RUST, required by the debian packager)
echo podman run --replace -d --tty --interactive -v ${SRCDIR}:/work -e ARCH_LINUX=${ARCH_L} -e ARCH_RUST=${ARCH_R} --name fabinfra_deb_${ARCH_L} --platform linux/${ARCH_D} localhost/fabinfra/debianpackage_${ARCH_D}
sudo podman run --replace -d --tty --interactive -v ${SRCDIR}:/srcdir -v ${DOWNLOAD}:/download -e ARCH_LINUX=${ARCH_L} -e ARCH_RUST=${ARCH_R} --name fabinfra_deb_${ARCH_L} --platform linux/${ARCH_D} localhost/fabinfra/debianpackage_${ARCH_D}
# now attach to that container and start building the packages
echo podman exec -u 0 --tty --interactive fabinfra_deb_${ARCH_L} bash
#sudo podman exec -u 0 --tty --interactive fabinfra_deb_${ARCH_L} bash
sudo podman exec -u 0 --tty --interactive fabinfra_deb_${ARCH_L} bash -c "
cd /srcdir/fabaccess-bffh-${BFFHV}/;
dpkg-buildpackage -us -uc -k=B8F5D56C64A6161B35FB4892188C8D1E501EBD41;
cd /srcdir/;
cp fabaccess-bffh_${BFFHV}_${ARCH_P}.deb /tmp/;
cd /tmp/;
alien --keep-version --verbose --scripts --to-rpm /tmp/fabaccess-bffh_${BFFHV}_${ARCH_P}.deb;
cp /tmp/fabaccess-bffh_${BFFHV}_*.deb /download/;
cp /tmp/fabaccess-bffh-${BFFHV}-*.rpm /download/
"
fi
done
echo -e "\n+++++++++++++++++++++++++++++++++++++++++++"
echo -e "Everything done. Built BFFH packages (*.deb/*.rpm) moved to: ${DOWNLOAD}"
echo -e "+++++++++++++++++++++++++++++++++++++++++++\n"

View File

@ -44,11 +44,11 @@ echo -e " \e[33m🎆\e[0m FabAccess Diflouroborane Server (bffh) was installed/u
echo -e " \e[33m⚠ PLEASE CONSIDER:\e[0m"
echo -e " - if not already changed by you, this is the minimum working localhost listening"
echo -e " setup WITHOUT any users, roles, ressources, actors, actor_connections"
echo -e " - iif not done yet: please update the self-signed TLS certificate to a proper one to go for production"
echo -e " - if not done yet: please update the self-signed TLS certificate to a proper one to go for production"
echo -e " - remember to configure and run a well-defined Mosquitto MQTT server"
echo -e " - please check the CHANGELOG for latest modifications to the server at https://y.fab-access.org/changelog-bffh"
echo -e " - further information about configuration and usage can be found at https://fab-access.org/configure"
echo -e " - the client application to access your server (called 'Borepin') can be found at https://fab-access.org/download\n"
echo -e " - please check the CHANGELOG for latest modifications to the server at \e[36mhttps://y.fab-access.org/changelog-bffh\e[0m"
echo -e " - further information about configuration and usage can be found at \e[36mhttps://fab-access.org/configure\e[0m"
echo -e " - the client application to access your server (called 'Borepin') can be found at \e[36mhttps://fab-access.org/download\e[0m\n"
# check for Mosquitto availability on local system
if command -v dnf 2>&1 >/dev/null; then
@ -59,7 +59,7 @@ if command -v dpkg 2>&1 >/dev/null; then
fi
MOSQUITTO_INSTALLED=$?
if [[ ! $MOSQUITTO_INSTALLED -eq 0 ]]; then
echo -e " Could not find a local Mosquitto MQTT server. Please install it with 'sudo "$PACKMAN" install mosquitto' or configure an external MQTT server in /etc/bffh/bffh.dhall file. Otherwise BFFH will refuse to start!\e[0m"
echo -e " Could not find a local Mosquitto MQTT server. Please install it with \e[33m'sudo "$PACKMAN" install mosquitto'\e[0m or configure an external MQTT server in /etc/bffh/bffh.dhall file. Otherwise BFFH will refuse to start!\e[0m"
fi
# handle service file. We restart bffh only if it waas running before (keep the state)
@ -75,14 +75,14 @@ if command -v systemctl >/dev/null; then
systemctl restart bffh.service
else
echo -e " - systemctl: bffh.service did not run before installation."
echo -e " Please start it manually by 'systemctl start bffh.service && journalctl -f -u bffh.service'\n"
echo -e " Please start it manually by '\e[33msystemctl start bffh.service && journalctl -f -u bffh.service\e[0m'\n"
fi
fi
echo -e " - Last hint: don't forget to import a proper users.toml into the database"
echo -e " (should fit to your main configuration bffh.dhall as well)."
echo -e " You can import an example (let's use 'showcase') users database with"
echo -e " the command '/usr/bin/bffhd --load /etc/bffh/config_examples/showcase/users.toml'"
echo -e " the command '\e[33m/usr/bin/bffhd --load /etc/bffh/config_examples/showcase/users.toml\e[0m'"
echo -e " Then you should overwrite /etc/bffh/bffh.dhall with the one from"
echo -e " /etc/bffh/config_examples/showcase/bffh.dhall and restart the bffh.service"
echo -e " If you messed up, you can restore your default settings from /etc/bffh/config_examples/minimum_working/\n"

View File

@ -1,13 +1,15 @@
#!/bin/bash
# We install some required libraries for building/compiling
# This script installs podman and qemu-user-static, which is required for the following Dockerfile to work.
# It omits the error "exec container process `/bin/sh`: Exec format error"
# The Dockerfile inside THIS directory is used to create two different arches for cross-building of the *.deb and *.rpm files
# Please note: we need to install these images as root user!
sudo apt install podman qemu-user-static
sudo apt install podman gsasl libgsasl7-dev libssl-dev libclang-dev cmake clang capnproto mosquitto mosquitto-clients devscripts build-essential debhelper debtags alien libpcsclite-dev qemu-user-static
sudo systemctl daemon-reload
# Please note: we need to install these images as root user!
pack="fabinfra/debianpackage"
arch="arm64/v8"