Skip to content

Modular logistics and supply chain operating system (LSOS)

Fix Fleetbase binary build scripts

Ronald A. Richardson29d596454dd5
diff --git a/builds/linux/build-linux.sh b/builds/linux/build-linux.sh
old mode 100644
new mode 100755
index 3a67c8d2..018494dd
--- a/builds/linux/build-linux.sh
+++ b/builds/linux/build-linux.sh
@@ -1,6 +1,7 @@
#!/bin/bash
set -e
+set -o pipefail
# Resolve the directory the script is located in
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -13,6 +14,37 @@ DIST_DIR="$ROOT_DIR/builds/dist"
BINARY_NAME="fleetbase-linux-x86_64"
DOCKERFILE="$ROOT_DIR/builds/linux/static-build.Dockerfile"
+require_command() {
+ if ! command -v "$1" >/dev/null 2>&1; then
+ echo "❌ Required command not found: $1" >&2
+ exit 1
+ fi
+}
+
+cleanup_container() {
+ if docker container inspect "$CONTAINER_NAME" >/dev/null 2>&1; then
+ echo "🧹 Removing existing build container: $CONTAINER_NAME"
+ docker rm -f "$CONTAINER_NAME" >/dev/null
+ fi
+}
+
+require_command curl
+require_command docker
+
+if ! docker info >/dev/null 2>&1; then
+ echo "❌ Docker is not running or the daemon is not reachable." >&2
+ exit 1
+fi
+
+mkdir -p "$DIST_DIR"
+if [[ ! -w "$DIST_DIR" ]]; then
+ echo "❌ Dist directory is not writable: $DIST_DIR" >&2
+ exit 1
+fi
+
+cleanup_container
+trap cleanup_container EXIT
+
# Ensure pkg-config archive is available
SPC_DOWNLOADS_DIR="$SCRIPT_DIR/spc/downloads"
PKG_TAR="pkg-config-0.29.2.tar.gz"
@@ -28,20 +60,17 @@ fi
# Build the image
echo "πŸ“¦ Building static Linux binary for ${APP_NAME}..."
-docker build -f "$DOCKERFILE" -t "$IMAGE_NAME" .
+docker build -f "$DOCKERFILE" -t "$IMAGE_NAME" "$ROOT_DIR"
# Create a container from the built image
echo "πŸ“¦ Creating container to extract binary..."
docker create --name "$CONTAINER_NAME" "$IMAGE_NAME"
-# Make sure dist folder exist
-mkdir -p "$DIST_DIR"
-
# Copy binary from container to local dist folder
echo "πŸ“‚ Extracting binary..."
docker cp "$CONTAINER_NAME:/go/src/app/dist/frankenphp-linux-x86_64" "$DIST_DIR/$BINARY_NAME"
# Cleanup the temp container
-docker rm "$CONTAINER_NAME"
+cleanup_container
-echo "βœ… Build complete! Binary is located at: $DIST_DIR/$BINARY_NAME"
\ No newline at end of file
+echo "βœ… Build complete! Binary is located at: $DIST_DIR/$BINARY_NAME"
diff --git a/builds/linux/static-build.Dockerfile b/builds/linux/static-build.Dockerfile
index 446eda3c..cd52d59b 100644
--- a/builds/linux/static-build.Dockerfile
+++ b/builds/linux/static-build.Dockerfile
@@ -1,10 +1,11 @@
-# FROM --platform=linux/amd64 dunglas/frankenphp:static-builder
-FROM --platform=linux/amd64 docker.io/dunglas/frankenphp:static-builder@sha256:821526b776a26502735d83890cc0a0d579348c510ba6c777df0762cb1c50d967
+# FROM --platform=${FLEETBASE_BUILD_PLATFORM} dunglas/frankenphp:static-builder
+ARG FLEETBASE_BUILD_PLATFORM=linux/amd64
+FROM --platform=${FLEETBASE_BUILD_PLATFORM} docker.io/dunglas/frankenphp:static-builder@sha256:821526b776a26502735d83890cc0a0d579348c510ba6c777df0762cb1c50d967
WORKDIR /go/src/app
# Copy Fleetbase app
-COPY ../../api ./dist/app
+COPY api ./dist/app
# Set working directory to the embedded Fleetbase app
WORKDIR /go/src/app/dist/app
@@ -25,8 +26,8 @@ RUN chmod +x ./deploy.sh
# Move back to main app directory before running build-static.sh
WORKDIR /go/src/app
-# Install geos lib
-RUN apk add --no-cache geos geos-dev
+# Install native libraries and headers required by SPC doctor/build.
+RUN apk add --no-cache geos geos-dev gettext-dev
# Inject the libgeos library handlers
COPY ./builds/linux/spc/libgeos-linux.php ./dist/static-php-cli/src/SPC/builder/linux/library/libgeos.php
@@ -88,6 +89,27 @@ RUN apk add --no-cache build-base && \
# Do not run git pull
RUN sed -i 's/^[ \t]*git pull/# git pull/' ./build-static.sh
-
-# Build the FrankenPHP static binary
-RUN EMBED=dist/app ./build-static.sh
\ No newline at end of file
+RUN sed -i 's/[[:space:]]--prefer-pre-built//g' ./build-static.sh
+
+# Stabilize SPC/curl downloads on networks where HTTP/2 streams are reset.
+RUN printf '%s\n' \
+ 'http1.1' \
+ 'retry = 5' \
+ 'retry-delay = 5' \
+ 'retry-all-errors' \
+ 'connect-timeout = 30' \
+ 'max-time = 300' \
+ 'speed-limit = 1024' \
+ 'speed-time = 60' \
+ > /root/.curlrc
+
+# Build the FrankenPHP static binary. SPC downloads can fail transiently, so
+# retry the final build step without hiding the eventual failure.
+RUN for attempt in 1 2 3 4 5; do \
+ rm -f dist/cache_key; \
+ EMBED=dist/app ./build-static.sh && exit 0; \
+ echo "FrankenPHP static build attempt ${attempt} failed." >&2; \
+ rm -f dist/cache_key; \
+ if [ "$attempt" -lt 5 ]; then sleep "$((attempt * 15))"; fi; \
+ done; \
+ exit 1
diff --git a/builds/linux/static-build.Dockerfile.dockerignore b/builds/linux/static-build.Dockerfile.dockerignore
new file mode 100644
index 00000000..8f6ef588
--- /dev/null
+++ b/builds/linux/static-build.Dockerfile.dockerignore
@@ -0,0 +1,7 @@
+**
+!api/
+!api/**
+!builds/
+!builds/linux/
+!builds/linux/spc/
+!builds/linux/spc/**
diff --git a/builds/osx/build-osx.sh b/builds/osx/build-osx.sh
index e334c264..e06dfd6c 100755
--- a/builds/osx/build-osx.sh
+++ b/builds/osx/build-osx.sh
@@ -1,6 +1,7 @@
#!/bin/bash
set -e
+set -o pipefail
log() {
echo -e "\033[1;34m[πŸ”§ $1]\033[0m"
@@ -26,6 +27,9 @@ OSX_DIR="$ROOT_DIR/builds/osx"
DIST_DIR="$ROOT_DIR/builds/dist"
APP_DIR="$ROOT_DIR/api"
BREW_PREFIX="/opt/homebrew"
+STATIC_PHP_CLI_VERSION="2.5.2"
+TARGET_PHP_VERSION="8.2"
+TOOLING_PHP_VERSION="8.4.0"
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
ARCH="$(uname -m)"
@@ -33,26 +37,47 @@ BINARY_NAME="fleetbase-$OS-$ARCH"
log "Binary will be: $BINARY_NAME"
+require_command() {
+ if ! command -v "$1" >/dev/null 2>&1; then
+ log_error "Required command not found: $1"
+ exit 1
+ fi
+}
+
+require_file() {
+ if [ ! -f "$1" ]; then
+ log_error "Required file missing: $1"
+ exit 1
+ fi
+}
+
+require_dir() {
+ if [ ! -d "$1" ]; then
+ log_error "Required directory missing: $1"
+ exit 1
+ fi
+}
+
+require_command php
+require_command git
+require_command jq
+require_command curl
+require_command brew
+
+if [[ "$ARCH" != "arm64" ]]; then
+ log_warn "This script is tuned for Apple Silicon builds; detected architecture: $ARCH"
+fi
+
+mkdir -p "$DIST_DIR"
+if [[ ! -w "$DIST_DIR" ]]; then
+ log_error "Dist directory is not writable: $DIST_DIR"
+ exit 1
+fi
+
# Setup PHP 8.4
log "Detecting current PHP version..."
ORIGINAL_PHP_PATH="$(which php)"
ORIGINAL_PHP_VERSION="$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION.".".PHP_RELEASE_VERSION;' 2>/dev/null)"
-IS_ASDF_MANAGED=false
-
-if [[ "$ORIGINAL_PHP_PATH" == *".asdf"* ]]; then
- IS_ASDF_MANAGED=true
-fi
-
-# πŸ” Trap to restore PHP when script exits
-trap 'if [ "$IS_ASDF_MANAGED" = true ]; then
- log "Restoring asdf-managed PHP version: $ORIGINAL_PHP_VERSION"
- asdf set php "$ORIGINAL_PHP_VERSION" || true
- log "Reverted to PHP $(php -v | head -n 1)"
- else
- log "Unsetting asdf set to restore system PHP"
- asdf set php system || true
- log "Reverted to PHP $(php -v | head -n 1)"
- fi' EXIT
log "Detected PHP version: $ORIGINAL_PHP_VERSION"
log "Detected PHP binary: $ORIGINAL_PHP_PATH"
@@ -64,8 +89,9 @@ if [[ "$ORIGINAL_PHP_PATH" == "$BREW_PREFIX/bin/php" && "$ORIGINAL_PHP_VERSION"
log "Homebrew PHP $ORIGINAL_PHP_VERSION detected at $ORIGINAL_PHP_PATH β€” skipping asdf build/install."
else
# Only install under asdf if we don’t already have 8.4.0 installed
- log "No Homebrew PHP 8.4 detected (found $ORIGINAL_PHP_PATH $ORIGINAL_PHP_VERSION), using asdf to build/install."
- if ! asdf list php | grep -q "8.4.0"; then
+ require_command asdf
+ log "No Homebrew PHP 8.4 detected (found $ORIGINAL_PHP_PATH $ORIGINAL_PHP_VERSION), using asdf shell-local PHP $TOOLING_PHP_VERSION."
+ if ! asdf list php | grep -q "$TOOLING_PHP_VERSION"; then
# Use brew to install required dependencies for asdf php management
log "Checking and installing Homebrew packages required for PHP 8.4 build..."
@@ -84,14 +110,15 @@ else
export PKG_CONFIG_PATH="$BREW_PREFIX/opt/openssl/lib/pkgconfig:$BREW_PREFIX/opt/oniguruma/lib/pkgconfig:$BREW_PREFIX/opt/libsodium/lib/pkgconfig:$BREW_PREFIX/opt/libzip/lib/pkgconfig:$BREW_PREFIX/opt/gd/lib/pkgconfig:$BREW_PREFIX/opt/zlib/lib/pkgconfig:$BREW_PREFIX/opt/openssl@3/lib/pkgconfig:$BREW_PREFIX/opt/libxml2/lib/pkgconfig:$BREW_PREFIX/opt/curl/lib/pkgconfig:$BREW_PREFIX/opt/sqlite3/lib/pkgconfig:$BREW_PREFIX/opt/freetype/lib/pkgconfig:$BREW_PREFIX/opt/jpeg/lib/pkgconfig:$BREW_PREFIX/opt/libpng/lib/pkgconfig"
export PHP_CONFIGURE_OPTIONS="--with-openssl=$(brew --prefix openssl) --with-iconv=$(brew --prefix libiconv)"
- log "Installing PHP 8.4.0 with asdf..."
- asdf install php 8.4.0 --verbose
+ log "Installing PHP $TOOLING_PHP_VERSION with asdf..."
+ asdf install php "$TOOLING_PHP_VERSION" --verbose
else
- log "asdf already has PHP 8.4.0 installed, skipping"
+ log "asdf already has PHP $TOOLING_PHP_VERSION installed, skipping"
fi
- log "Switching to PHP 8.4.0 with asdf set..."
- asdf set php 8.4.0 --home
+ log "Activating PHP $TOOLING_PHP_VERSION for this shell only..."
+ export ASDF_PHP_VERSION="$TOOLING_PHP_VERSION"
+ log "Build tooling PHP is now: $(php -r 'echo PHP_VERSION;' 2>/dev/null)"
fi
# Clone FrankenPHP
@@ -103,6 +130,7 @@ else
fi
cd "$OSX_DIR/frankenphp"
+require_file "$OSX_DIR/frankenphp/build-static.sh"
# Patch build script
log "Patching build-static.sh to skip git pull..."
@@ -110,7 +138,7 @@ sed -i '' 's/^[ \t]*git pull/# git pull/' ./build-static.sh
# Set environment variables
log "Exporting build environment variables..."
-export PHP_VERSION=8.2
+export PHP_VERSION="$TARGET_PHP_VERSION"
export PHP_EXTENSIONS="pdo_mysql,gd,bcmath,redis,intl,zip,gmp,apcu,opcache,imagick,sockets,pcntl,geos,iconv,mbstring,fileinfo,ctype,tokenizer,simplexml,dom,filter,session"
export PHP_EXTENSION_LIBS="libgeos,libzip,bzip2,libxml2,openssl,zlib"
export SPC_REL_TYPE=source
@@ -121,14 +149,24 @@ export CMAKE_OSX_ARCHITECTURES=arm64
# Clone and prepare static-php-cli in dist/
STATIC_PHP_CLI_DIR="$OSX_DIR/frankenphp/dist/static-php-cli"
if [ ! -d "$STATIC_PHP_CLI_DIR" ]; then
- log "Cloning static-php-cli into dist/..."
- git clone --depth 1 --branch 2.5.2 https://github.com/crazywhalecc/static-php-cli.git "$STATIC_PHP_CLI_DIR"
+ log "Cloning static-php-cli $STATIC_PHP_CLI_VERSION into dist/..."
+ git clone --depth 1 --branch "$STATIC_PHP_CLI_VERSION" https://github.com/crazywhalecc/static-php-cli.git "$STATIC_PHP_CLI_DIR"
else
log_warn "static-php-cli already exists in dist/. Skipping clone."
fi
+require_dir "$STATIC_PHP_CLI_DIR/src/SPC/builder/unix/library"
+require_dir "$STATIC_PHP_CLI_DIR/src/SPC/builder/macos/library"
+require_file "$STATIC_PHP_CLI_DIR/src/SPC/builder/unix/UnixBuilderBase.php"
+require_file "$STATIC_PHP_CLI_DIR/config/source.json"
+require_file "$STATIC_PHP_CLI_DIR/config/ext.json"
+require_file "$STATIC_PHP_CLI_DIR/config/lib.json"
+require_file "$ROOT_DIR/builds/osx/spc/libgeos-unix.php"
+require_file "$ROOT_DIR/builds/osx/spc/libgeos-macos.php"
+require_file "$ROOT_DIR/builds/osx/spc/UnixBuilderBase-macos.php"
+
# Inject libgeos support
-log "Injecting libgeos patch files..."
+log "Injecting libgeos patch files for pinned static-php-cli $STATIC_PHP_CLI_VERSION..."
cp "$ROOT_DIR/builds/osx/spc/libgeos-unix.php" "$STATIC_PHP_CLI_DIR/src/SPC/builder/unix/library/libgeos.php"
cp "$ROOT_DIR/builds/osx/spc/libgeos-macos.php" "$STATIC_PHP_CLI_DIR/src/SPC/builder/macos/library/libgeos.php"
cp "$ROOT_DIR/builds/osx/spc/UnixBuilderBase-macos.php" "$STATIC_PHP_CLI_DIR/src/SPC/builder/unix/UnixBuilderBase.php"
@@ -163,7 +201,12 @@ log "Patching build-static.sh to skip git pull and composer install..."
sed -i '' 's/^[[:space:]]*git pull/# git pull/' "$OSX_DIR/frankenphp/build-static.sh"
# Patch add CoreServices framework for Caddy build on OSX
-sed -i '' 's/-framework CoreFoundation -framework SystemConfiguration/& -framework CoreServices/' "$OSX_DIR/frankenphp/build-static.sh"
+if grep -q -- '-framework CoreFoundation -framework SystemConfiguration' "$OSX_DIR/frankenphp/build-static.sh"; then
+ sed -i '' 's/-framework CoreFoundation -framework SystemConfiguration/& -framework CoreServices/' "$OSX_DIR/frankenphp/build-static.sh"
+else
+ log_error "Unable to patch CoreServices framework: expected Caddy linker flags were not found."
+ exit 1
+fi
# ── work around 403 on GH macOS runners ────────────────────────────────────────
log "Patching curl to use a browser-like User-Agent (to avoid 403s)…"
@@ -185,4 +228,4 @@ log_success "βœ… macOS binary built at: $DIST_DIR/$BINARY_NAME"
# Clean up frankenphp build and app embed folder
log "🧹 Cleaning temporary app directory..."
-rm -rf "$OSX_DIR/frankenphp"
\ No newline at end of file
+rm -rf "$OSX_DIR/frankenphp"