Skip to content

Commit

Permalink
fixes related to a new version of rbfeeder:armhf and some general cle…
Browse files Browse the repository at this point in the history
…anup (#184)

* use native on all arm archs, cleanup logging

* fix - changelog.gz doesn't always exist

* add check for CPU serial number (again required from rbfeeder 1.0.9)

* doc update: ensure hexdump is installed when adding FakeCpuSerial

* only explicitly load armhf packages when arch needs to be emulated

* fix typo

* only do `dpkg --add-architecture armhf` when really needed

* remove i386 building from test builds

* make checking for cpu serial case independent
  • Loading branch information
kx1t authored Nov 21, 2023
1 parent 5e13ad2 commit 2b99345
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/on_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
with:
push_enabled: false
platform_linux_arm32v6_enabled: false
platform_linux_i386_enabled: true
platform_linux_i386_enabled: false
get_version_method: file_in_container:file=/CONTAINER_VERSION

# test_build:
Expand Down
50 changes: 30 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM ghcr.io/sdr-enthusiasts/docker-baseimage:base as downloader

# This downloader image has the rb24 apt repo added, and allows for downloading and extracting of rbfeeder binary deb package.
ARG TARGETPLATFORM TARGETOS TARGETARCH

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

Expand All @@ -14,19 +15,17 @@ RUN set -x && \
xz-utils \
&& \
# add rb24 repo
dpkg --add-architecture armhf && \
if [ "${TARGETARCH:0:3}" != "arm" ]; then \
dpkg --add-architecture armhf; \
RB24_PACKAGES=(rbfeeder:armhf); \
else \
RB24_PACKAGES=(rbfeeder); \
fi && \
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 1D043681 && \
bash -c "echo 'deb https://apt.rb24.com/ bullseye main' > /etc/apt/sources.list.d/rb24.list" && \
apt-get update && \
# download rbfeeder deb
pushd /tmp && \
apt-get download \
rbfeeder:armhf \
&& \
# extract rbfeeder deb
ls -lah && \
ar xv ./rbfeeder_*armhf.deb && \
tar xvf ./data.tar.xz -C /
apt-get update -q && \
apt-get install -q -o Dpkg::Options::="--force-confnew" -y --no-install-recommends --no-install-suggests \
"${RB24_PACKAGES[@]}"

FROM ghcr.io/sdr-enthusiasts/docker-baseimage:qemu

Expand All @@ -42,16 +41,17 @@ ENV BEASTHOST=readsb \
VERBOSE_LOGGING=false \
ENABLE_MLAT=true

ARG TARGETPLATFORM TARGETOS TARGETARCH

COPY rootfs/ /
COPY --from=downloader /usr/bin/rbfeeder /usr/bin/rbfeeder_armhf
COPY --from=downloader /usr/bin/rbfeeder /usr/bin/rbfeeder_arm
COPY --from=downloader /usr/bin/dump1090-rb /usr/bin/dump1090-rb
COPY --from=downloader /usr/share/doc/rbfeeder/changelog.gz /usr/share/doc/rbfeeder/changelog.gz
COPY --from=downloader /usr/share/doc/rbfeeder/ /usr/share/doc/rbfeeder/

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# hadolint ignore=DL3008,SC2086,SC2039,SC2068
RUN set -x && \
dpkg --add-architecture armhf && \
# define required packages
TEMP_PACKAGES=() && \
KEPT_PACKAGES=() && \
Expand All @@ -65,12 +65,22 @@ RUN set -x && \
TEMP_PACKAGES+=(libpython3-dev) && \
KEPT_PACKAGES+=(python3-setuptools) && \
# required to run rbfeeder
KEPT_PACKAGES+=(libc6:armhf) && \
KEPT_PACKAGES+=(libcurl4:armhf) && \
KEPT_PACKAGES+=(libglib2.0-0:armhf) && \
KEPT_PACKAGES+=(libjansson4:armhf) && \
KEPT_PACKAGES+=(libprotobuf-c1:armhf) && \
KEPT_PACKAGES+=(librtlsdr0:armhf) && \
if [ "${TARGETARCH:0:3}" != "arm" ]; then \
dpkg --add-architecture armhf; \
KEPT_PACKAGES+=(libc6:armhf) && \
KEPT_PACKAGES+=(libcurl4:armhf) && \
KEPT_PACKAGES+=(libglib2.0-0:armhf) && \
KEPT_PACKAGES+=(libjansson4:armhf) && \
KEPT_PACKAGES+=(libprotobuf-c1:armhf) && \
KEPT_PACKAGES+=(librtlsdr0:armhf); \
else \
KEPT_PACKAGES+=(libc6) && \
KEPT_PACKAGES+=(libcurl4) && \
KEPT_PACKAGES+=(libglib2.0-0) && \
KEPT_PACKAGES+=(libjansson4) && \
KEPT_PACKAGES+=(libprotobuf-c1) && \
KEPT_PACKAGES+=(librtlsdr0); \
fi && \
KEPT_PACKAGES+=(netbase) && \
# install packages
apt-get update && \
Expand Down
11 changes: 6 additions & 5 deletions rootfs/etc/s6-overlay/scripts/01-show-rbfeeder-changelog
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env bash
#shellcheck shell=bash disable=SC1091

white="\e[0;97m"
reset="\e[0m"
source /scripts/common
s6wrap=(s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args)

# Show latest changelog
echo -e "${white}"
zcat /usr/share/doc/rbfeeder/changelog.gz | grep -B9999 -m 1 " -- "
echo -e "${reset}"
if [[ -e /usr/share/doc/rbfeeder/changelog.gz ]]; then
"${s6wrap[@]}" zcat /usr/share/doc/rbfeeder/changelog.gz | grep -B9999 -m 1 " -- "
fi
37 changes: 25 additions & 12 deletions rootfs/etc/s6-overlay/scripts/02-rbfeeder
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
#!/command/with-contenv bash
# shellcheck shell=bash
#shellcheck shell=bash disable=SC1091,SC2015

source /scripts/common
s6wrap=(s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args)

# Check to make sure the correct command line arguments have been set
EXITCODE=0
if [ -z "${LAT}" ]; then
echo "ERROR: LAT environment variable not set"
"${s6wrap[@]}" echo "[ERROR] LAT environment variable not set"
EXITCODE=1
fi
if [ -z "${LONG}" ]; then
echo "ERROR: LONG environment variable not set"
"${s6wrap[@]}" echo "[ERROR] LONG environment variable not set"
EXITCODE=1
fi
if [ -z "${BEASTHOST}" ]; then
echo "ERROR: BEASTHOST environment variable not set"
"${s6wrap[@]}" echo "[ERROR] BEASTHOST environment variable not set"
EXITCODE=1
fi
if [ -z "${ALT}" ]; then
echo "ERROR: ALT environment variable not set"
"${s6wrap[@]}" echo "[ERROR] ALT environment variable not set"
EXITCODE=1
else
ALT="${ALT%%.*}"
Expand All @@ -27,9 +30,9 @@ fi

# Set up timezone
if [ -z "${TZ}" ]; then
echo "WARNING: TZ environment variable not set"
"${s6wrap[@]}" echo "[WARNING] TZ environment variable not set"
else
ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime && echo "$TZ" > /etc/timezone
ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime && echo "$TZ" > /etc/timezone || true
fi

# Generate /etc/rbfeeder.ini based on environment variables
Expand All @@ -42,11 +45,11 @@ debug_level=${DEBUG_LEVEL:-0}

if [ -z "${SHARING_KEY}" ]
then
echo ""
echo "WARNING: SHARING_KEY environment variable was not set!"
echo "Please make sure you note down the key generated."
echo "Pass the key as environment var SHARING_KEY on next launch!"
echo ""
"${s6wrap[@]}" echo ""
"${s6wrap[@]}" echo "[WARNING] SHARING_KEY environment variable was not set!"
"${s6wrap[@]}" echo " Please make sure you note down the key generated."
"${s6wrap[@]}" echo " Pass the key as environment var SHARING_KEY on next launch!"
"${s6wrap[@]}" echo ""
else
echo "key=$SHARING_KEY" >> /etc/rbfeeder.ini
fi
Expand Down Expand Up @@ -90,8 +93,18 @@ if [[ -n "$UAT_RECEIVER_HOST" ]]; then
} >> /etc/rbfeeder.ini
fi

if ! grep -qi "Serial\s*:" /proc/cpuinfo; then
# rbfeeder won't work without a serial number
"${s6wrap[@]}" echo ""
"${s6wrap[@]}" echo "[ERROR] Your machine doesn't have a serial number in /proc/cpuinfo"
"${s6wrap[@]}" echo " You must resolve this for the container to run. Instruction to fix it can be found here:"
"${s6wrap[@]}" echo " https://github.com/sdr-enthusiasts/docker-radarbox/blob/main/version_0.4.3_workarounds.md#workaround-for-cpu-serial"
sleep infinity & wait $!
fi

# Create log dirs
mkdir -p /var/log/rbfeeder
mkdir -p /run/shm
chown nobody:nogroup /var/log/rbfeeder
touch /var/log/rbfeeder.log
truncate --size=0 /var/log/rbfeeder.log
18 changes: 10 additions & 8 deletions rootfs/etc/s6-overlay/scripts/03-show-architecture
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/usr/bin/env bash

white="\e[0;97m"
reset="\e[0m"
#shellcheck shell=bash disable=SC1091

echo -e "${white}"
echo "Hardware information:"
echo "Machine: $(uname -m)"
echo "Processor: $(uname -p)"
echo "Platform: $(uname -i)"
echo -e "${reset}"
source /scripts/common
s6wrap=(s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args)

"${s6wrap[@]}" cat << EOM
Hardware information:
Machine: $(uname -m)
Processor: $(uname -p)
Platform: $(uname -i)
EOM
19 changes: 10 additions & 9 deletions rootfs/etc/s6-overlay/scripts/978json-splitter
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!/command/with-contenv bash
# shellcheck shell=bash
#shellcheck shell=bash disable=SC1091

source /scripts/common
s6wrap=(s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args)

set -eo pipefail

# Don't continue if UAT_RECEIVER_HOST isn't set
if [[ -z "$UAT_RECEIVER_HOST" ]]; then
sleep 86400
exit 0
sleep infinity & wait $!
else
# shellcheck disable=SC2016
"${s6wrap[@]}" socat -d -d TCP-LISTEN:30979,fork TCP:"$UAT_RECEIVER_HOST":"${UAT_RECEIVER_PORT:-30979}"
sleep 5
fi

# shellcheck disable=SC2016
socat -d -d TCP-LISTEN:30979,fork TCP:"$UAT_RECEIVER_HOST":"${UAT_RECEIVER_PORT:-30979}" \
2>&1 | awk '{print "[978json-splitter] " $0}'

sleep 5
18 changes: 8 additions & 10 deletions rootfs/etc/s6-overlay/scripts/rbfeeder
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/command/with-contenv bash
#shellcheck shell=bash
#shellcheck disable=SC2016
#shellcheck shell=bash disable=SC2016,SC1091

source /scripts/common
s6wrap=(s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args)

# Prevent writing of coredumps
# - Reason for coredumps: https://github.com/mikenye/docker-radarbox/issues/9#issuecomment-633068833
Expand All @@ -9,13 +11,9 @@ ulimit -c 0

# can be run natively
if [ "$VERBOSE_LOGGING" == "true" ]; then
/usr/bin/rbfeeder 2>&1 | \
stdbuf -oL awk '{print "[rbfeeder] " $0}'
"${s6wrap[@]}" /usr/bin/rbfeeder

else
/usr/bin/rbfeeder 2>&1 | \
stdbuf -oL awk '! / Statistics updated every 60 seconds /' | \
stdbuf -oL awk '! /Packets sent in the last 60 seconds: /' | \
stdbuf -oL awk '! / Data sent: /' | \
stdbuf -oL awk '! / Data received: /' | \
stdbuf -oL awk '{print "[rbfeeder] " $0}'
"${s6wrap[@]}" /usr/bin/rbfeeder | \
stdbuf -oL grep -v "Statistics updated every 60 seconds|\Packets sent in the last 60 seconds:|\Data sent:|\Data received:"
fi
8 changes: 5 additions & 3 deletions rootfs/etc/s6-overlay/scripts/stats
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/command/with-contenv bash
#shellcheck shell=bash
#shellcheck shell=bash disable=SC1091

source /scripts/common
s6wrap=(s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args)

sleep $((STATS_INTERVAL_MINUTES * 60))

Expand All @@ -13,8 +16,7 @@ while read -r L; do
done < "$RBFEEDER_LOG_FILE"

#shellcheck disable=SC2016
echo "Packets sent in past $STATS_INTERVAL_MINUTES minutes: $PACKETS_SINCE_LAST_UPDATE, total packets since container start: $TOTAL_PACKETS" \
| stdbuf -oL awk '{print "[rbfeeder-stats] " strftime("%Y/%m/%d %H:%M:%S", systime()) " " $0}'
"${s6wrap[@]}" echo "Packets sent in past $STATS_INTERVAL_MINUTES minutes: $PACKETS_SINCE_LAST_UPDATE, total packets since container start: $TOTAL_PACKETS"

# truncate the log file to 150 lines
#shellcheck disable=SC2005
Expand Down
17 changes: 10 additions & 7 deletions rootfs/usr/bin/rbfeeder_wrapper.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
#!/usr/bin/env bash
# shellcheck shell=bash disable=SC1091

# This wrapper file will determine how to run rbfeeder, either natively or via qemu-arm-static.
# All command line arguments passed to this script will be passed directly to rbfeeder_armhf.

source /scripts/common
s6wrap=(s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args)

# attempt to run natively
if /usr/bin/rbfeeder_armhf --no-start --version > /dev/null 2>&1; then
/usr/bin/rbfeeder_armhf "$@"
if /usr/bin/rbfeeder_arm --no-start --version >/dev/null 2>&1; then
/usr/bin/rbfeeder_arm "$@"

elif qemu-arm-static /usr/bin/rbfeeder_armhf --no-start --version > /dev/null 2>&1; then
qemu-arm-static /usr/bin/rbfeeder_armhf "$@"
elif qemu-arm-static /usr/bin/rbfeeder_arm --no-start --version >/dev/null 2>&1; then
qemu-arm-static /usr/bin/rbfeeder_arm "$@"

else
>&2 echo "ERROR: Could not run rbfeeder natively or via qemu"
sleep 3600

"${s6wrap[@]}" echo "[ERROR] Could not run rbfeeder natively or via qemu"
sleep infinity & wait $!
fi
6 changes: 5 additions & 1 deletion version_0.4.3_workarounds.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ For systems that don't have a CPU serial number in `/proc/cpuinfo`, we can "fudg

```bash
# make a directory to hold our fake data
mkdir -p /opt/adsb/data
mkdir -p -m 777 /opt/adsb/data

# generate a fake cpuinfo file
# start by taking our current cpuinfo file
cp /proc/cpuinfo /opt/adsb/data/fake_cpuinfo
chmod u+w /opt/adsb/data/fake_cpuinfo

# ... make sure we have hexdump installed
[[ ! which hexdump >/dev/null 2>&1 ]] && sudo apt install -y bsdmainutils

# ... and add a fake serial number to the end
echo -e "serial\t\t: $(hexdump -n 8 -e '4/4 "%08X" 1 "\n"' /dev/urandom | tr '[:upper:]' '[:lower:]')" >> /opt/adsb/data/fake_cpuinfo
Expand Down

0 comments on commit 2b99345

Please sign in to comment.