fix: Replace Termux Docker images with Alpine-based cross-compilation for better reliability

This commit is contained in:
Abolfazl
2026-05-13 01:32:02 +03:30
parent 34a62cef13
commit 7aed8661b0
+42 -21
View File
@@ -167,6 +167,11 @@ jobs:
- name: Set up QEMU for cross-arch containers - name: Set up QEMU for cross-arch containers
uses: docker/setup-qemu-action@v3 uses: docker/setup-qemu-action@v3
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Build Termux binaries (arm64 + armv7) - name: Build Termux binaries (arm64 + armv7)
shell: bash shell: bash
run: | run: |
@@ -183,48 +188,59 @@ jobs:
mkdir -p release-assets termux-dist mkdir -p release-assets termux-dist
# Build using Alpine Linux with QEMU for cross-compilation
# This is more reliable than depending on Termux Docker images
build_termux_arch () { build_termux_arch () {
arch="$1" local arch="$1"
platform="$2" local platform="$2"
image="$3" local qemu_arch="$3"
echo "Building for Termux ${arch}..."
rm -rf dist build *.spec || true rm -rf dist build *.spec || true
# Use Alpine with QEMU for reliable cross-platform builds
docker run --rm --platform "$platform" \ docker run --rm --platform "$platform" \
-v "$PWD:/work" \ -v "$PWD:/work" \
-w /work \ -w /work \
"$image" \ alpine:latest \
bash -lc ' sh -c '
set -euo pipefail set -euo pipefail
echo "Building Termux binary for ${arch}" echo "Installing build dependencies..."
pkg update -y apk add --no-cache python3 py3-pip make gcc musl-dev openssl-dev libffi-dev rust cargo
pkg install -y python clang make pkg-config libffi openssl rust binutils echo "Installing Python packages..."
python -m pip install --upgrade pip python3 -m pip install --upgrade pip pyinstaller
pip install pyinstaller
pip install -r requirements.txt pip install -r requirements.txt
echo "Building binary for '"'"'${arch}'"'"'..."
pyinstaller --noconfirm --clean --onefile --name MasterHttpRelayVPN --paths src main.py pyinstaller --noconfirm --clean --onefile --name MasterHttpRelayVPN --paths src main.py
' '
if [ ! -f dist/MasterHttpRelayVPN ]; then if [ ! -f dist/MasterHttpRelayVPN ]; then
echo "Missing Termux binary output for ${arch}" >&2 echo "ERROR: Missing binary output for ${arch}" >&2
exit 1 exit 1
fi fi
cp dist/MasterHttpRelayVPN "termux-dist/MasterHttpRelayVPN-${arch}" cp dist/MasterHttpRelayVPN "termux-dist/MasterHttpRelayVPN-${arch}"
chmod +x "termux-dist/MasterHttpRelayVPN-${arch}" chmod +x "termux-dist/MasterHttpRelayVPN-${arch}"
echo "✓ Successfully built for ${arch}"
} }
build_termux_arch "arm64" "linux/arm64" "termux/termux-docker:aarch64" # Build both ARM architectures
build_termux_arch "armv7" "linux/arm/v7" "termux/termux-docker:arm" build_termux_arch "arm64" "linux/arm64" "aarch64"
build_termux_arch "armv7" "linux/arm/v7" "arm"
echo ""
echo "Packaging releases..."
for arch in arm64 armv7; do for arch in arm64 armv7; do
staging="termux-staging-${arch}" staging="termux-staging-${arch}"
rm -rf "$staging" rm -rf "$staging"
mkdir -p "$staging" mkdir -p "$staging"
cp "termux-dist/MasterHttpRelayVPN-${arch}" "$staging/MasterHttpRelayVPN" cp "termux-dist/MasterHttpRelayVPN-${arch}" "$staging/MasterHttpRelayVPN"
chmod +x "$staging/MasterHttpRelayVPN"
[ -f config.example.json ] && cp config.example.json "$staging/" [ -f config.example.json ] && cp config.example.json "$staging/"
[ -f README.md ] && cp README.md "$staging/" [ -f README.md ] && cp README.md "$staging/"
[ -f README_FA.md ] && cp README_FA.md "$staging/" [ -f README_FA.md ] && cp README_FA.md "$staging/"
# Create Termux launch script for native Termux environment
printf '%s\n' \ printf '%s\n' \
'#!/data/data/com.termux/files/usr/bin/bash' \ '#!/data/data/com.termux/files/usr/bin/bash' \
'set -euo pipefail' \ 'set -euo pipefail' \
@@ -236,18 +252,23 @@ jobs:
archive="MasterHttpRelayVPN-${version}-termux-${arch}.zip" archive="MasterHttpRelayVPN-${version}-termux-${arch}.zip"
(cd "$staging" && zip -qr "../release-assets/${archive}" .) (cd "$staging" && zip -qr "../release-assets/${archive}" .)
python - <<PY # Generate checksum
import hashlib python3 - <<PY
from pathlib import Path import hashlib
archive = Path("release-assets") / "${archive}" from pathlib import Path
digest = hashlib.sha256(archive.read_bytes()).hexdigest() archive = Path("release-assets") / "${archive}"
(archive.parent / f"{archive.name}.sha256").write_text( digest = hashlib.sha256(archive.read_bytes()).hexdigest()
(archive.parent / f"{archive.name}.sha256").write_text(
f"{digest} {archive.name}\\n", f"{digest} {archive.name}\\n",
encoding="utf-8", encoding="utf-8",
) )
PY PY
echo "✓ Packaged: $archive"
done done
echo ""
ls -lah release-assets/
- name: Upload build artifacts - name: Upload build artifacts
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with: