From 05c9e5d43d83d16efef4fe3a4f291b5241ccc31e Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 26 Sep 2026 19:56:57 +0000 Subject: [PATCH] Packages from every CI platform, Docker builds for local packaging scripts/package.sh turns release builds into the packages CI uploads and the Docker builds produce: Linux .tar.gz and .deb (dependencies from dpkg-shlibdeps), Windows .zip and NSIS installer, renamed Android APKs, each with a SHA256SUMS file. CI (ci.yml): package-linux, package-windows (installer now required), package-flatpak (bundle from packaging/flatpak, cargo sources generated in the job), package-gateway-image (docker save of tsgw) and the Android job (debug APKs for arm64-v8a and x86_64, a signed release APK when the signing secrets exist) each upload an artifact. A v* tag also attaches everything to a draft GitHub release. docker/{linux,windows,android}.Dockerfile with scripts/docker-build.sh build the same packages locally into dist//: Ubuntu 24.04, a mingw-w64 cross build with a static libvpx pinned by commit, and the Android SDK/NDK/cargo-ndk CI uses. Proxy settings and an optional CA certificate are passed through. docker.yml runs them weekly and when they change. docs/building.md describes both ways. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G --- .dockerignore | 15 +++ .github/workflows/ci.yml | 203 +++++++++++++++++++++++++++-------- .github/workflows/docker.yml | 56 ++++++++++ .gitignore | 1 + README.md | 4 + docker/android.Dockerfile | 100 +++++++++++++++++ docker/linux.Dockerfile | 46 ++++++++ docker/windows.Dockerfile | 68 ++++++++++++ docs/building.md | 102 ++++++++++++++++++ docs/release.md | 20 ++-- packaging/windows/README.md | 8 +- scripts/docker-build.sh | 44 ++++++++ scripts/package.sh | 163 ++++++++++++++++++++++++++++ 13 files changed, 773 insertions(+), 57 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/docker.yml create mode 100644 docker/android.Dockerfile create mode 100644 docker/linux.Dockerfile create mode 100644 docker/windows.Dockerfile create mode 100644 docs/building.md create mode 100755 scripts/docker-build.sh create mode 100755 scripts/package.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a77b85d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,15 @@ +# Build context for docker/*.Dockerfile and crates/tsc-gateway/Dockerfile: +# the sources only. Builds keep target/ in cache mounts, never in the context. +.git +.claude +target +dist +fuzz/target +fuzz/corpus +fuzz/artifacts +dev/.state +android/.gradle +android/build +android/app/build +android/local.properties +**/node_modules diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f7a4991..aa1b858 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,6 +3,8 @@ name: CI on: push: branches: [main, master] + # A version tag also publishes the packages as a draft release (release job). + tags: ["v*"] pull_request: workflow_dispatch: @@ -58,17 +60,11 @@ jobs: if: runner.os != 'Linux' run: cargo test --workspace --locked - release-build: - name: release build (${{ matrix.os }}) - strategy: - fail-fast: false - matrix: - include: - - os: ubuntu-24.04 - artifact: tsc-desktop-linux-x86_64 - - os: windows-2025 - artifact: tsc-desktop-windows-x86_64 - runs-on: ${{ matrix.os }} + # Packages for every platform (docs/building.md), made by scripts/package.sh + # like the Docker builds in docker/; each job uploads them as an artifact. + package-linux: + name: package (Linux) + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 - uses: ./.github/actions/system-deps @@ -77,45 +73,114 @@ jobs: - uses: Swatinem/rust-cache@v2 with: key: release - - name: Build tsc-desktop - run: cargo build --release --locked -p tsc-ui - - name: Stage (Linux) - if: runner.os == 'Linux' + - name: Build + run: cargo build --release --locked -p tsc-ui -p tsctl -p tsc-gateway + # dpkg-shlibdeps works out the .deb's dependencies. + - name: Package (.tar.gz, .deb) run: | - mkdir -p dist - cp target/release/tsc-desktop dist/ - cp packaging/linux/* THIRD_PARTY_NOTICES.md dist/ - # The installer is built when NSIS is on the runner; unsigned. - - name: Stage (Windows) - if: runner.os == 'Windows' - shell: pwsh - run: | - New-Item -ItemType Directory -Force dist | Out-Null - Copy-Item target\release\tsc-desktop.exe, THIRD_PARTY_NOTICES.md dist\ - $makensis = (Get-Command makensis -ErrorAction SilentlyContinue).Source - if (-not $makensis) { - $makensis = "${env:ProgramFiles(x86)}\NSIS\makensis.exe" - } - if (Test-Path $makensis) { - $version = (cargo metadata --no-deps --format-version 1 | ConvertFrom-Json).packages | - Where-Object name -eq 'tsc-ui' | Select-Object -ExpandProperty version - & $makensis "/DVERSION=$version" "/DOUTDIR=$PWD\dist" packaging\windows\installer.nsi - if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } - } else { - Write-Host "::notice::NSIS not found, uploading the executable only" - } + sudo apt-get install -y --no-install-recommends dpkg-dev + scripts/package.sh linux dist - uses: actions/upload-artifact@v4 with: - name: ${{ matrix.artifact }} + name: tsc-linux-x86_64 path: dist/ if-no-files-found: error - # The Android app (docs/android.md): clippy on the Android-only code and a - # debug APK for arm64. Nothing runs on a device here. - android: - name: android (arm64 APK) + package-windows: + name: package (Windows) + runs-on: windows-2025 + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/system-deps + - name: Install toolchain (rust-toolchain.toml) + run: rustup toolchain install + - uses: Swatinem/rust-cache@v2 + with: + key: release + - name: Build + run: cargo build --release --locked -p tsc-ui -p tsctl -p tsc-gateway + # The installer is required here: install NSIS when the image lacks it. + - name: NSIS + shell: pwsh + run: | + $makensis = (Get-Command makensis -ErrorAction SilentlyContinue).Source + if (-not $makensis) { $makensis = "${env:ProgramFiles(x86)}\NSIS\makensis.exe" } + if (-not (Test-Path $makensis)) { + choco install nsis -y --no-progress + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + } + "MAKENSIS=$($makensis.Replace('\', '/'))" >> $env:GITHUB_ENV + - name: Package (.zip, installer) + shell: bash + run: scripts/package.sh windows dist + - uses: actions/upload-artifact@v4 + with: + name: tsc-windows-x86_64 + path: dist/ + if-no-files-found: error + + # Flatpak bundle from packaging/flatpak (install with + # `flatpak install --user tsc-desktop.flatpak`). flatpak-builder builds + # offline, from the crates that flatpak-cargo-generator lists. + package-flatpak: + name: package (Flatpak) runs-on: ubuntu-24.04 - timeout-minutes: 60 + timeout-minutes: 90 + container: + image: ghcr.io/flathub-infra/flatpak-github-actions:freedesktop-25.08 + options: --privileged + env: + # flatpak-builder-tools, pinned. + FBT_COMMIT: 41c20aa10819cdb2a4f3ca171758a96d1955c018 + steps: + - uses: actions/checkout@v4 + - name: Cargo sources + run: | + curl -sSfL -o /tmp/flatpak-cargo-generator.py \ + "https://raw.githubusercontent.com/flatpak/flatpak-builder-tools/$FBT_COMMIT/cargo/flatpak-cargo-generator.py" + python3 -m venv /tmp/venv + /tmp/venv/bin/pip install --quiet "aiohttp>=3.9.5,<4" "tomlkit>=0.13.3,<1" "PyYAML>=6.0.2,<7" + /tmp/venv/bin/python /tmp/flatpak-cargo-generator.py Cargo.lock -o packaging/flatpak/cargo-sources.json + - uses: flatpak/flatpak-github-actions/flatpak-builder@v6 + with: + bundle: tsc-desktop.flatpak + manifest-path: packaging/flatpak/io.github.faumaray.TsClient.yml + cache-key: flatpak-builder-${{ hashFiles('Cargo.lock') }} + upload-artifact: false + - uses: actions/upload-artifact@v4 + with: + name: tsc-flatpak-x86_64 + path: tsc-desktop.flatpak + if-no-files-found: error + + # The gateway's container image (crates/tsc-gateway/Dockerfile), saved as a + # file: `docker load -i tsgw-image.tar.gz`. + package-gateway-image: + name: package (gateway image) + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + - name: Build and save + run: | + version=$(sed -n 's/^version = "\(.*\)"$/\1/p' crates/tsc-gateway/Cargo.toml | head -n 1) + docker build -f crates/tsc-gateway/Dockerfile -t "tsgw:$version" -t tsgw:latest . + mkdir -p dist + docker save "tsgw:$version" tsgw:latest | gzip > dist/tsgw-image.tar.gz + (cd dist && sha256sum tsgw-image.tar.gz > SHA256SUMS-gateway) + - uses: actions/upload-artifact@v4 + with: + name: tsgw-image + path: dist/ + if-no-files-found: error + + # The Android app (docs/android.md): clippy on the Android-only code, a + # debug APK for arm64-v8a and x86_64 (emulators), and a signed release APK + # when the signing secrets are set (docs/release.md). Nothing runs on a + # device here. + android: + name: android (APKs) + runs-on: ubuntu-24.04 + timeout-minutes: 90 env: NDK_VERSION: 27.3.13750724 steps: @@ -123,7 +188,7 @@ jobs: - name: Install toolchain (rust-toolchain.toml) run: | rustup toolchain install - rustup target add aarch64-linux-android + rustup target add aarch64-linux-android x86_64-linux-android - uses: Swatinem/rust-cache@v2 with: key: android @@ -148,13 +213,57 @@ jobs: cargo ndk -t arm64-v8a --platform 29 clippy --locked -p tsc-media --no-default-features --no-deps -- -D warnings - name: Debug APK working-directory: android - run: ./gradlew --no-daemon assembleDebug -Ptsc.abis=arm64-v8a + run: ./gradlew --no-daemon assembleDebug -Ptsc.abis=arm64-v8a,x86_64 + # Only with the signing secrets; an unsigned release APK is not installable. + - name: Release APK (signed) + working-directory: android + env: + KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }} + TSC_SIGNING_STORE_PASSWORD: ${{ secrets.TSC_SIGNING_STORE_PASSWORD }} + TSC_SIGNING_KEY_ALIAS: ${{ secrets.TSC_SIGNING_KEY_ALIAS }} + TSC_SIGNING_KEY_PASSWORD: ${{ secrets.TSC_SIGNING_KEY_PASSWORD }} + run: | + if [ -z "$KEYSTORE_BASE64" ]; then + echo "::notice::No ANDROID_KEYSTORE_BASE64 secret: skipping the release APK" + exit 0 + fi + export TSC_SIGNING_STORE_FILE="$RUNNER_TEMP/release.jks" + echo "$KEYSTORE_BASE64" | base64 -d > "$TSC_SIGNING_STORE_FILE" + ./gradlew --no-daemon assembleRelease -Ptsc.abis=arm64-v8a,x86_64 + rm -f "$TSC_SIGNING_STORE_FILE" + - name: Package + run: scripts/package.sh android dist - uses: actions/upload-artifact@v4 with: - name: tsc-android-debug-arm64 - path: android/app/build/outputs/apk/debug/*.apk + name: tsc-android + path: dist/ if-no-files-found: error + # A v* tag: every package, attached to a draft GitHub release to review and + # publish by hand. + release: + name: draft release + if: startsWith(github.ref, 'refs/tags/v') + needs: [lint, test, deny, notices, smoke, package-linux, package-windows, package-flatpak, package-gateway-image, android] + runs-on: ubuntu-24.04 + permissions: + contents: write + steps: + - uses: actions/download-artifact@v4 + with: + path: dist + merge-multiple: true + - name: Checksums + run: | + cd dist + rm -f SHA256SUMS-* + sha256sum -- * > SHA256SUMS + - uses: softprops/action-gh-release@v2 + with: + draft: true + generate_release_notes: true + files: dist/* + # Licenses, bans, sources and RustSec advisories (the `cargo audit` # database); audit.yml repeats the advisories check daily. deny: diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..1259547 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,56 @@ +name: Docker builds + +# The local builds in docker/ (docs/building.md), run here so they keep +# working: weekly, by hand, and when they or the packaging change. Each build +# uploads what it made, the same kinds of packages as CI's package jobs +# (the Windows one cross-compiled with mingw-w64). + +on: + schedule: + - cron: "17 3 * * 1" + workflow_dispatch: + push: + branches: [main, master] + paths: + - docker/** + - scripts/package.sh + - scripts/docker-build.sh + - .dockerignore + - packaging/** + - .github/workflows/docker.yml + pull_request: + paths: + - docker/** + - scripts/package.sh + - scripts/docker-build.sh + - .dockerignore + - packaging/** + - .github/workflows/docker.yml + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + name: docker (${{ matrix.platform }}) + strategy: + fail-fast: false + matrix: + platform: [linux, windows, android] + runs-on: ubuntu-24.04 + timeout-minutes: 120 + steps: + - uses: actions/checkout@v4 + # The Android build needs more room than the runner leaves free. + - name: Free disk space + run: | + sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc /usr/local/.ghcup + df -h / + - name: Build + run: scripts/docker-build.sh ${{ matrix.platform }} --progress=plain + - uses: actions/upload-artifact@v4 + with: + name: docker-${{ matrix.platform }} + path: dist/${{ matrix.platform }}/ + if-no-files-found: error diff --git a/.gitignore b/.gitignore index ec81357..e586912 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target/ /dev/.state/ +/dist/ diff --git a/README.md b/README.md index bbf2ab0..d8423f9 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,10 @@ Development switches of the desktop app (environment variables): `TSC_DATA_DIR` `TSC_DEMO_STREAM=1` (a local test stream in the viewer, no server needed), `TSC_OPEN=share|settings[:]|about|client`, `TSC_AUTOWATCH=1`, `TSC_AUTOSHARE=test-pattern`. +Ready-made packages (Linux `.tar.gz`/`.deb`/Flatpak, Windows zip and installer, Android APK) +come from every CI run, and `scripts/docker-build.sh` builds the same ones locally in Docker: +see [docs/building.md](docs/building.md). + Building on Linux needs the ALSA headers (`libasound2-dev`), fontconfig and xkbcommon headers for the UI (`libfontconfig1-dev libxkbcommon-dev`), plus CMake and a C compiler for the bundled libopus; for streams also libvpx and PipeWire (see [docs/media.md](docs/media.md#build-requirements)). diff --git a/docker/android.Dockerfile b/docker/android.Dockerfile new file mode 100644 index 0000000..55f4473 --- /dev/null +++ b/docker/android.Dockerfile @@ -0,0 +1,100 @@ +# syntax=docker/dockerfile:1 +# +# Android APKs (docs/building.md, docs/android.md): a debug APK, installable +# as is, for arm64-v8a and x86_64 (emulators). +# +# docker build -f docker/android.Dockerfile -o dist/android . +# docker build -f docker/android.Dockerfile --build-arg ABIS=arm64-v8a -o dist/android . +# +# or scripts/docker-build.sh android. A signed release APK needs your keystore +# (docs/release.md), passed as build secrets: +# +# docker build -f docker/android.Dockerfile --build-arg APK=release \ +# --secret id=keystore,src=release.jks --secret id=signing,src=signing.env \ +# -o dist/android . +# +# signing.env holds TSC_SIGNING_STORE_PASSWORD, TSC_SIGNING_KEY_ALIAS and +# TSC_SIGNING_KEY_PASSWORD lines (NAME=value). Without them a release APK is +# unsigned. + +FROM ubuntu:24.04 AS toolchain +ARG DEBIAN_FRONTEND=noninteractive +# JDK 17 (Gradle, the Android Gradle plugin), CMake + Ninja (the bundled libopus). +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential ca-certificates cmake curl ninja-build openjdk-17-jdk-headless \ + pkg-config python3 unzip \ + && rm -rf /var/lib/apt/lists/* + +# Extra CA certificates (PEM, one or more), for building behind a +# TLS-inspecting proxy; scripts/docker-build.sh passes $BUILD_CA_CERT as this +# secret. One file per certificate, so the Java truststore gets each one too. +RUN --mount=type=secret,id=ca,required=false \ + if [ -s /run/secrets/ca ]; then \ + awk '/-----BEGIN CERTIFICATE-----/ { n++ } n { print > ("/usr/local/share/ca-certificates/build-ca-" n ".crt") }' \ + /run/secrets/ca \ + && update-ca-certificates; \ + fi +# Java tools do not read HTTPS_PROXY: turn it into JVM properties for +# sdkmanager and Gradle when it is set (GRADLE_OPTS for the wrapper's JVM, +# -D arguments for the build JVM). +COPY <<-'EOF' /usr/local/bin/java-proxy-opts + #!/bin/sh + p=${HTTPS_PROXY:-${https_proxy:-}} + [ -n "$p" ] || exit 0 + hp=${p#*://}; hp=${hp%%/*}; hp=${hp##*@} + echo "-Dhttps.proxyHost=${hp%:*} -Dhttps.proxyPort=${hp##*:} -Dhttp.proxyHost=${hp%:*} -Dhttp.proxyPort=${hp##*:}" +EOF +RUN chmod +x /usr/local/bin/java-proxy-opts + +# The SDK packages CI installs (.github/workflows/ci.yml, android job). +ENV ANDROID_HOME=/opt/android-sdk +ARG CMDLINE_TOOLS=commandlinetools-linux-16111833_latest.zip +ARG CMDLINE_TOOLS_SHA1=e025545c62a8e64c7559119566a569fb1dec5f60 +ARG NDK_VERSION=27.3.13750724 +RUN curl -sSfL -o /tmp/tools.zip "https://dl.google.com/android/repository/$CMDLINE_TOOLS" \ + && echo "$CMDLINE_TOOLS_SHA1 /tmp/tools.zip" | sha1sum -c - \ + && mkdir -p "$ANDROID_HOME/cmdline-tools" \ + && unzip -q /tmp/tools.zip -d "$ANDROID_HOME/cmdline-tools" \ + && mv "$ANDROID_HOME/cmdline-tools/cmdline-tools" "$ANDROID_HOME/cmdline-tools/latest" \ + && rm /tmp/tools.zip \ + && export JAVA_OPTS="$(java-proxy-opts)" \ + && yes | "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" --licenses >/dev/null \ + && "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" \ + "ndk;$NDK_VERSION" "platforms;android-36" "build-tools;36.0.0" >/dev/null +ENV ANDROID_NDK_HOME=$ANDROID_HOME/ndk/$NDK_VERSION ANDROID_NDK_ROOT=$ANDROID_HOME/ndk/$NDK_VERSION + +ENV RUSTUP_HOME=/usr/local/rustup CARGO_HOME=/usr/local/cargo PATH=/usr/local/cargo/bin:$PATH +COPY rust-toolchain.toml /tmp/toolchain/ +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \ + | sh -s -- -y --no-modify-path --profile minimal --default-toolchain none \ + && cd /tmp/toolchain && rustup toolchain install \ + && rustup target add --toolchain "$(sed -n 's/^channel = "\(.*\)"/\1/p' rust-toolchain.toml)" \ + aarch64-linux-android x86_64-linux-android armv7-linux-androideabi \ + && cargo install --locked cargo-ndk --version 4.1.2 \ + && rm -rf "$CARGO_HOME/registry" + +FROM toolchain AS build +# Comma-separated Android ABIs: arm64-v8a, x86_64, armeabi-v7a. +ARG ABIS=arm64-v8a,x86_64 +# debug (installable as is) or release (signed with the build secrets). +ARG APK=debug +WORKDIR /src +COPY . . +RUN --mount=type=cache,id=tsc-cargo-registry,target=/usr/local/cargo/registry \ + --mount=type=cache,id=tsc-target-android,target=/src/target \ + --mount=type=cache,id=tsc-gradle,target=/root/.gradle \ + --mount=type=secret,id=keystore,required=false \ + --mount=type=secret,id=signing,required=false \ + set -e; \ + if [ "$APK" = release ] && [ -f /run/secrets/keystore ]; then \ + export TSC_SIGNING_STORE_FILE=/run/secrets/keystore; \ + set -a; . /run/secrets/signing; set +a; \ + fi; \ + proxy="$(java-proxy-opts)"; \ + export GRADLE_OPTS="$proxy"; \ + task="assemble$(echo "$APK" | sed 's/./\U&/')"; \ + (cd android && ./gradlew --no-daemon $proxy "$task" -Ptsc.abis="$ABIS") \ + && scripts/package.sh android /out + +FROM scratch AS artifacts +COPY --from=build /out / diff --git a/docker/linux.Dockerfile b/docker/linux.Dockerfile new file mode 100644 index 0000000..5ad0221 --- /dev/null +++ b/docker/linux.Dockerfile @@ -0,0 +1,46 @@ +# syntax=docker/dockerfile:1 +# +# Linux packages (docs/building.md): tsc--linux-x86_64.tar.gz with +# tsc-desktop, tsctl and tsgw, and tsc-desktop__amd64.deb for +# Ubuntu 24.04 and newer. +# +# docker build -f docker/linux.Dockerfile -o dist/linux . +# +# or scripts/docker-build.sh linux. The cargo registry and target directory +# live in cache mounts, so rebuilds are incremental. + +FROM ubuntu:24.04 AS toolchain +ARG DEBIAN_FRONTEND=noninteractive +# The same libraries as CI (.github/actions/system-deps), plus dpkg-dev for +# the .deb's dependencies. +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential ca-certificates cmake curl dpkg-dev pkg-config \ + libasound2-dev libfontconfig1-dev libxkbcommon-dev \ + libvpx-dev libdav1d-dev libpipewire-0.3-dev libspa-0.2-dev libclang-dev \ + && rm -rf /var/lib/apt/lists/* +# Extra CA certificates (PEM, one or more), for building behind a +# TLS-inspecting proxy; scripts/docker-build.sh passes $BUILD_CA_CERT as this +# secret. One file per certificate, so the Java truststore gets each one too. +RUN --mount=type=secret,id=ca,required=false \ + if [ -s /run/secrets/ca ]; then \ + awk '/-----BEGIN CERTIFICATE-----/ { n++ } n { print > ("/usr/local/share/ca-certificates/build-ca-" n ".crt") }' \ + /run/secrets/ca \ + && update-ca-certificates; \ + fi +ENV RUSTUP_HOME=/usr/local/rustup CARGO_HOME=/usr/local/cargo PATH=/usr/local/cargo/bin:$PATH +# The toolchain rust-toolchain.toml asks for. +COPY rust-toolchain.toml /tmp/toolchain/ +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \ + | sh -s -- -y --no-modify-path --profile minimal --default-toolchain none \ + && cd /tmp/toolchain && rustup toolchain install + +FROM toolchain AS build +WORKDIR /src +COPY . . +RUN --mount=type=cache,id=tsc-cargo-registry,target=/usr/local/cargo/registry \ + --mount=type=cache,id=tsc-target-linux,target=/src/target \ + cargo build --release --locked -p tsc-ui -p tsctl -p tsc-gateway \ + && scripts/package.sh linux /out + +FROM scratch AS artifacts +COPY --from=build /out / diff --git a/docker/windows.Dockerfile b/docker/windows.Dockerfile new file mode 100644 index 0000000..9e6fca9 --- /dev/null +++ b/docker/windows.Dockerfile @@ -0,0 +1,68 @@ +# syntax=docker/dockerfile:1 +# +# Windows packages, cross-compiled on Linux (docs/building.md): +# tsc--windows-x86_64.zip with tsc-desktop.exe, tsctl.exe and +# tsgw.exe, and the NSIS installer tsc-desktop--setup.exe. +# +# docker build -f docker/windows.Dockerfile -o dist/windows . +# +# or scripts/docker-build.sh windows. This builds for x86_64-pc-windows-gnu +# with mingw-w64; CI's Windows jobs build the MSVC target on Windows. Both run +# on Windows 10 and 11. Unsigned, like CI's (signing: docs/release.md). + +FROM ubuntu:24.04 AS toolchain +ARG DEBIAN_FRONTEND=noninteractive +# mingw-w64 (C compiler and linker), NASM (aws-lc and libvpx assembly), CMake +# (the bundled libopus, aws-lc), NSIS (the installer), zip. +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential ca-certificates cmake curl git mingw-w64 nasm nsis perl pkg-config zip \ + && rm -rf /var/lib/apt/lists/* \ + && update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix \ + && update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix +# Extra CA certificates (PEM, one or more), for building behind a +# TLS-inspecting proxy; scripts/docker-build.sh passes $BUILD_CA_CERT as this +# secret. One file per certificate, so the Java truststore gets each one too. +RUN --mount=type=secret,id=ca,required=false \ + if [ -s /run/secrets/ca ]; then \ + awk '/-----BEGIN CERTIFICATE-----/ { n++ } n { print > ("/usr/local/share/ca-certificates/build-ca-" n ".crt") }' \ + /run/secrets/ca \ + && update-ca-certificates; \ + fi +ENV RUSTUP_HOME=/usr/local/rustup CARGO_HOME=/usr/local/cargo PATH=/usr/local/cargo/bin:$PATH +COPY rust-toolchain.toml /tmp/toolchain/ +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \ + | sh -s -- -y --no-modify-path --profile minimal --default-toolchain none \ + && cd /tmp/toolchain && rustup toolchain install \ + && rustup target add --toolchain "$(sed -n 's/^channel = "\(.*\)"/\1/p' rust-toolchain.toml)" \ + x86_64-pc-windows-gnu + +# libvpx as a static mingw library (CI's Windows jobs take it from vcpkg), +# from upstream's git at a pinned commit. +FROM toolchain AS libvpx +ARG LIBVPX_VERSION=1.15.2 +ARG LIBVPX_COMMIT=d168454ecd099805c675d4a98c66f4891373302a +RUN git clone --quiet --depth 1 --branch "v$LIBVPX_VERSION" \ + https://chromium.googlesource.com/webm/libvpx /tmp/libvpx \ + && test "$(git -C /tmp/libvpx rev-parse HEAD)" = "$LIBVPX_COMMIT" \ + && cd /tmp/libvpx \ + && CROSS=x86_64-w64-mingw32- ./configure --target=x86_64-win64-gcc --prefix=/opt/libvpx \ + --as=nasm --enable-static --disable-shared --enable-pic \ + --disable-examples --disable-tools --disable-docs --disable-unit-tests \ + && make -j"$(nproc)" && make install \ + && rm -rf /tmp/libvpx + +FROM toolchain AS build +COPY --from=libvpx /opt/libvpx /opt/libvpx +ARG LIBVPX_VERSION=1.15.2 +# libvpx-native-sys: the library above, linked statically. +ENV VPX_LIB_DIR=/opt/libvpx/lib VPX_INCLUDE_DIR=/opt/libvpx/include \ + VPX_VERSION=$LIBVPX_VERSION VPX_STATIC=1 +WORKDIR /src +COPY . . +RUN --mount=type=cache,id=tsc-cargo-registry,target=/usr/local/cargo/registry \ + --mount=type=cache,id=tsc-target-windows,target=/src/target \ + cargo build --release --locked --target x86_64-pc-windows-gnu -p tsc-ui -p tsctl -p tsc-gateway \ + && WINDOWS_TARGET=x86_64-pc-windows-gnu scripts/package.sh windows /out + +FROM scratch AS artifacts +COPY --from=build /out / diff --git a/docs/building.md b/docs/building.md new file mode 100644 index 0000000..3be6850 --- /dev/null +++ b/docs/building.md @@ -0,0 +1,102 @@ +# Packages: from CI and built locally + +Every platform has installable packages. CI builds them on each run, and the +Dockerfiles in `docker/` build the same kinds of packages on any machine with +Docker. Both use `scripts/package.sh`, so file names and contents match. + +| Platform | Files | Install | +|---|---|---| +| Linux x86_64 | `tsc--linux-x86_64.tar.gz` | unpack; `bin/` has `tsc-desktop`, `tsctl`, `tsgw` (prefix layout: `tar -xzf … --strip-components=1 -C ~/.local`) | +| | `tsc-desktop__amd64.deb` | `sudo apt install ./tsc-desktop__amd64.deb` (Ubuntu 24.04+, Debian 13+) | +| | `tsc-desktop.flatpak` (CI only) | `flatpak install --user tsc-desktop.flatpak` | +| Windows x86_64 | `tsc--windows-x86_64.zip` | unpack; `tsc-desktop.exe`, `tsctl.exe`, `tsgw.exe` | +| | `tsc-desktop--setup.exe` | run it (per-machine install, uninstaller in Settings → Apps) | +| Android | `tsc--android-debug.apk` | `adb install …` or open it on the phone (arm64-v8a and x86_64) | +| | `tsc--android-release.apk` | only with signing configured ([release.md](release.md#android-apk-signing)) | + +Each package run also writes `SHA256SUMS-`. Nothing is code-signed +yet: Windows SmartScreen warns about the installer, and the debug APK is +signed with a debug key (fine for testing, not for the Play Store). + +The gateway also runs as a container ([gateway-admin.md](gateway-admin.md)): +CI uploads the image as `tsgw-image.tar.gz` (`docker load -i tsgw-image.tar.gz`, +then `docker run … tsgw:`), or build it with +`docker build -f crates/tsc-gateway/Dockerfile -t tsgw .`. + +## From CI + +`.github/workflows/ci.yml` uploads one artifact per platform on every run: +`tsc-linux-x86_64`, `tsc-windows-x86_64`, `tsc-flatpak-x86_64`, +`tsc-android` and `tsgw-image`. Download them from the run's page (Actions → the run → +Artifacts), or with the GitHub CLI: + +```sh +gh run list --workflow ci.yml --limit 5 +gh run download --dir dist +``` + +GitHub keeps artifacts for 90 days. For builds that stay, push a version tag: +`git tag -s v0.2.0 && git push origin v0.2.0` runs the whole workflow and, if +everything passes, the `release` job attaches all packages and a `SHA256SUMS` +to a **draft** GitHub release, which you review and publish by hand +([release.md](release.md#checklist)). + +The Windows packages from CI use the MSVC toolchain and libvpx from vcpkg. +The Android job builds a signed release APK only when the repository has the +signing secrets (`ANDROID_KEYSTORE_BASE64`, `TSC_SIGNING_STORE_PASSWORD`, +`TSC_SIGNING_KEY_ALIAS`, `TSC_SIGNING_KEY_PASSWORD`). + +`.github/workflows/docker.yml` builds the Docker files below weekly, by hand +(Actions → Docker builds → Run workflow) and when they change, and uploads +their output as `docker-linux`, `docker-windows` and `docker-android`. + +## Locally with Docker + +Needs Docker 23+ (BuildKit) or Docker Desktop, and about 15 GB of free disk +per platform (toolchains plus the build cache). From the repository root: + +```sh +scripts/docker-build.sh linux # → dist/linux/ +scripts/docker-build.sh windows # → dist/windows/ +scripts/docker-build.sh android # → dist/android/ +scripts/docker-build.sh # all three +``` + +The same with plain Docker, e.g. `docker build -f docker/linux.Dockerfile -o dist/linux .` +Rebuilds are incremental: the cargo registry, `target/` and Gradle live in +BuildKit cache mounts (`docker builder prune` frees them). + +| Dockerfile | Builds | Notes | +|---|---|---| +| `docker/linux.Dockerfile` | `.tar.gz` and `.deb` on Ubuntu 24.04 | the binaries need glibc 2.39+ and the libraries the `.deb` lists | +| `docker/windows.Dockerfile` | `.zip` and the NSIS installer | cross-compiled for `x86_64-pc-windows-gnu` with mingw-w64 and a static libvpx; works on Windows 10 and 11 | +| `docker/android.Dockerfile` | debug APK | SDK, NDK and cargo-ndk as in CI; `--build-arg ABIS=arm64-v8a,x86_64,armeabi-v7a` picks the ABIs | + +Options go after the platform, straight to `docker build`: + +```sh +scripts/docker-build.sh android --build-arg ABIS=arm64-v8a +scripts/docker-build.sh android --build-arg APK=release \ + --secret id=keystore,src=release.jks --secret id=signing,src=signing.env +``` + +For the signed release APK, `signing.env` holds `TSC_SIGNING_STORE_PASSWORD=…`, +`TSC_SIGNING_KEY_ALIAS=…` and `TSC_SIGNING_KEY_PASSWORD=…`. Secrets are not +stored in the image or the build cache. + +**Behind a proxy:** `scripts/docker-build.sh` passes `HTTPS_PROXY`, +`HTTP_PROXY` and `NO_PROXY` on to the build and uses host networking when +the proxy is on localhost. If the proxy inspects TLS, set +`BUILD_CA_CERT=/path/to/proxy-ca.pem` so the builds trust it. + +## Locally without Docker + +- **Linux:** the packages from the table above need + `sudo apt install libasound2-dev libfontconfig1-dev libxkbcommon-dev libvpx-dev libdav1d-dev libpipewire-0.3-dev libspa-0.2-dev libclang-dev cmake dpkg-dev`, + then `cargo build --release --locked -p tsc-ui -p tsctl -p tsc-gateway` + and `scripts/package.sh linux`. +- **Windows:** [packaging/windows/README.md](../packaging/windows/README.md) + (MSVC, vcpkg libvpx, NSIS), then `bash scripts/package.sh windows` from Git Bash. +- **Android:** [android.md](android.md) (SDK, NDK, cargo-ndk), then + `cd android && ./gradlew assembleDebug` and `scripts/package.sh android`. +- **Flatpak:** [packaging/README.md](../packaging/README.md#flatpak). diff --git a/docs/release.md b/docs/release.md index 6765448..37b9119 100644 --- a/docs/release.md +++ b/docs/release.md @@ -138,8 +138,11 @@ repository; losing it means existing installs can no longer be updated. `TSC_SIGNING_STORE_PASSWORD`, `TSC_SIGNING_KEY_ALIAS`, `TSC_SIGNING_KEY_PASSWORD` ([android.md](android.md)). Without them it builds unsigned or debug-signed artifacts only. -- CI: the keystore as a base64 secret, decoded to `$RUNNER_TEMP`, removed - afterwards. Check with `apksigner verify --print-certs app-release.apk`. +- CI: the `android` job signs a release APK when the repository has the + secrets `ANDROID_KEYSTORE_BASE64` (`base64 -w0 tsc-release.jks`), + `TSC_SIGNING_STORE_PASSWORD`, `TSC_SIGNING_KEY_ALIAS` and + `TSC_SIGNING_KEY_PASSWORD`; the keystore is decoded to `$RUNNER_TEMP` and + removed afterwards. Check with `apksigner verify --print-certs app-release.apk`. - Google Play: use Play App Signing; our keystore is then the upload key (it can be reset through Play support if lost). F-Droid builds and signs itself unless reproducible builds are set up. @@ -167,14 +170,17 @@ Before tagging: Release: 7. Tag `v` (signed) on the release commit and push it. -8. Build the artifacts from the tag: Windows executable and installer - (signed), Linux tarball, Flatpak bundle, Android APK / AAB (signed); the - gateway container image if it changed. +8. The tag's CI run builds every package ([building.md](building.md)): Linux + tarball and `.deb`, Flatpak bundle, Windows zip and installer, Android APKs + (signed when the secrets are set), the gateway image; its `release` job + attaches them with a `SHA256SUMS` to a draft GitHub release. Sign the + Windows executable and installer, and an AAB for Google Play, by hand + until CI has the certificates. 9. Verify: signatures (`signtool verify`, `apksigner verify`), the installer and the Flatpak on a clean machine (matrix rows IN1-IN3), the version in the About page. -10. `SHA256SUMS` (signed), a draft GitHub release with the changelog section, - known issues and the tested server versions; publish it. +10. Sign `SHA256SUMS`; write the changelog section, known issues and the + tested server versions into the draft release; publish it. 11. Update the Flathub manifest (tag, commit, `cargo-sources.json`), Google Play / F-Droid. diff --git a/packaging/windows/README.md b/packaging/windows/README.md index f3a3113..29f8276 100644 --- a/packaging/windows/README.md +++ b/packaging/windows/README.md @@ -1,8 +1,10 @@ # Windows build and installer -CI (`release-build` in `.github/workflows/ci.yml`) builds `tsc-desktop.exe` on -`windows-2025` and uploads it as an artifact, with the installer when NSIS is on -the runner. Nothing is signed there. +CI (`package-windows` in `.github/workflows/ci.yml`) builds `tsc-desktop.exe`, +`tsctl.exe` and `tsgw.exe` on `windows-2025` and uploads the zip and the +installer as the `tsc-windows-x86_64` artifact. Nothing is signed there. +`docker/windows.Dockerfile` cross-compiles the same packages on Linux +([docs/building.md](../../docs/building.md)). ## Build diff --git a/scripts/docker-build.sh b/scripts/docker-build.sh new file mode 100755 index 0000000..c1dc76b --- /dev/null +++ b/scripts/docker-build.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# Build the packages in Docker, the same ones CI uploads (docs/building.md). +# +# scripts/docker-build.sh [linux|windows|android|all] [docker build args…] +# +# Output goes to dist//. Needs Docker with BuildKit (Docker 23+, or +# docker buildx). Extra arguments go to `docker build`, e.g. +# scripts/docker-build.sh android --build-arg ABIS=arm64-v8a +# +# Behind an HTTPS proxy, HTTPS_PROXY/HTTP_PROXY/NO_PROXY are passed on to the +# build; a proxy on this machine's loopback is reached with host networking. +# If the proxy inspects TLS, point BUILD_CA_CERT at its CA certificate (PEM): +# the builds then trust it. +set -euo pipefail + +cd "$(dirname "$0")/.." + +platform=${1:-all} +shift || true +case "$platform" in + linux | windows | android) platforms=("$platform") ;; + all) platforms=(linux windows android) ;; + *) echo "usage: $0 [linux|windows|android|all] [docker build args…]" >&2; exit 2 ;; +esac + +args=() +for var in HTTPS_PROXY https_proxy HTTP_PROXY http_proxy NO_PROXY no_proxy; do + if [[ -n ${!var:-} ]]; then + args+=(--build-arg "$var=${!var}") + case "${!var}" in + *://127.* | *://localhost*) args+=(--network host) ;; + esac + fi +done + +if [[ -n ${BUILD_CA_CERT:-} ]]; then + args+=(--secret "id=ca,src=$BUILD_CA_CERT") +fi + +for p in "${platforms[@]}"; do + echo "== $p → dist/$p" + DOCKER_BUILDKIT=1 docker build -f "docker/$p.Dockerfile" -o "dist/$p" "${args[@]}" "$@" . + ls -l "dist/$p" +done diff --git a/scripts/package.sh b/scripts/package.sh new file mode 100755 index 0000000..3d04da0 --- /dev/null +++ b/scripts/package.sh @@ -0,0 +1,163 @@ +#!/usr/bin/env bash +# Package release builds into the files CI uploads and the Docker builds +# produce (docs/building.md). Build first, then: +# +# scripts/package.sh linux [out-dir] tsc--linux-.tar.gz and +# tsc-desktop__.deb +# from target/release +# scripts/package.sh windows [out-dir] tsc--windows-x86_64.zip and +# tsc-desktop--setup.exe (NSIS) +# scripts/package.sh android [out-dir] the APKs Gradle built, renamed +# +# out-dir defaults to dist/. Each run also writes SHA256SUMS- there. +# +# Environment: +# CARGO_TARGET_DIR cargo's target directory (default: target) +# WINDOWS_TARGET the target triple the .exe files were built for, e.g. +# x86_64-pc-windows-gnu (default: none, target/release) +# MAKENSIS the NSIS compiler (default: makensis on PATH, then the +# default install location on Windows) +set -euo pipefail + +cd "$(dirname "$0")/.." + +kind=${1:-} +case "$kind" in + linux | windows | android) ;; + *) echo "usage: $0 linux|windows|android [out-dir]" >&2; exit 2 ;; +esac +mkdir -p "${2:-dist}" +out=$(cd "${2:-dist}" && pwd) +target_dir=${CARGO_TARGET_DIR:-target} + +# The version of a crate, from its manifest. +crate_version() { + sed -n 's/^version = "\(.*\)"$/\1/p' "$1/Cargo.toml" | head -n 1 +} +version=$(crate_version crates/tsc-ui) +[[ -n $version ]] || { echo "no version in crates/tsc-ui/Cargo.toml" >&2; exit 1; } + +app_id=io.github.faumaray.TsClient +bins=(tsc-desktop tsctl tsgw) +tmp=$(mktemp -d) +trap 'rm -rf "$tmp"' EXIT +files=() + +package_linux() { + local bin=$target_dir/release arch name stage pkg deb_arch depends + arch=$(uname -m) + name=tsc-$version-linux-$arch + + # Archive: a prefix layout, e.g. `tar -xzf … --strip-components=1 -C ~/.local`. + stage=$tmp/$name + for b in "${bins[@]}"; do + install -Dm755 "$bin/$b" -t "$stage/bin" + done + install -Dm644 packaging/linux/$app_id.desktop -t "$stage/share/applications" + install -Dm644 packaging/linux/$app_id.metainfo.xml -t "$stage/share/metainfo" + install -Dm644 packaging/linux/$app_id.svg -t "$stage/share/icons/hicolor/scalable/apps" + install -Dm644 THIRD_PARTY_NOTICES.md crates/tsc-gateway/tsgw.example.toml -t "$stage/share/doc/tsc" + tar -C "$tmp" -czf "$out/$name.tar.gz" "$name" + files+=("$name.tar.gz") + + # Debian package, with dependencies from the binaries' shared libraries. + command -v dpkg-deb >/dev/null || { echo "dpkg-deb not found: skipping the .deb" >&2; return; } + pkg=$tmp/debian/tsc-desktop + for b in "${bins[@]}"; do + install -Dm755 "$bin/$b" -t "$pkg/usr/bin" + done + install -Dm644 packaging/linux/$app_id.desktop -t "$pkg/usr/share/applications" + install -Dm644 packaging/linux/$app_id.metainfo.xml -t "$pkg/usr/share/metainfo" + install -Dm644 packaging/linux/$app_id.svg -t "$pkg/usr/share/icons/hicolor/scalable/apps" + install -Dm644 THIRD_PARTY_NOTICES.md -t "$pkg/usr/share/doc/tsc-desktop" + install -Dm644 crates/tsc-gateway/tsgw.example.toml -t "$pkg/usr/share/doc/tsc-desktop/examples" + cat >"$pkg/usr/share/doc/tsc-desktop/copyright" <<-EOF + Upstream: https://github.com/Faumaray/teamspeak_client_rs + License: MIT OR Apache-2.0 + Third-party licenses: /usr/share/doc/tsc-desktop/THIRD_PARTY_NOTICES.md + EOF + deb_arch=$(dpkg --print-architecture) + mkdir -p "$tmp/debian" + printf 'Source: tsc-desktop\n\nPackage: tsc-desktop\nArchitecture: any\n' >"$tmp/debian/control" + depends=$(cd "$tmp" && dpkg-shlibdeps -O "${bins[@]/#/debian/tsc-desktop/usr/bin/}" | + sed -n 's/^shlibs:Depends=//p') + # Loaded at run time (dlopen), so dpkg-shlibdeps cannot see them: the + # keyboard, then Wayland or X11 and EGL for the window. + depends=${depends:+$depends, }libxkbcommon0 + mkdir -p "$pkg/DEBIAN" + cat >"$pkg/DEBIAN/control" <<-EOF + Package: tsc-desktop + Version: $version + Architecture: $deb_arch + Maintainer: Faumaray <23194470+Faumaray@users.noreply.github.com> + Section: net + Priority: optional + Homepage: https://github.com/Faumaray/teamspeak_client_rs + Depends: $depends + Recommends: libwayland-client0, libwayland-cursor0, libxkbcommon-x11-0, libx11-xcb1, libxcursor1, libxi6, libxrandr2, libegl1 + Description: TeamSpeak 3 and 6 client + Desktop client for TeamSpeak 3 and TeamSpeak 6 servers (tsc-desktop), with + the tsctl command line client and the tsgw companion gateway. + EOF + dpkg-deb --root-owner-group --build "$pkg" "$out/tsc-desktop_${version}_$deb_arch.deb" >/dev/null + files+=("tsc-desktop_${version}_$deb_arch.deb") +} + +# A path makensis.exe understands when running on Windows (Git Bash). +native_path() { + if command -v cygpath >/dev/null; then cygpath -m "$1"; else printf '%s\n' "$1"; fi +} + +package_windows() { + local bin=$target_dir/${WINDOWS_TARGET:+$WINDOWS_TARGET/}release name stage makensis + name=tsc-$version-windows-x86_64 + stage=$tmp/$name + mkdir -p "$stage" + for b in "${bins[@]}"; do + cp "$bin/$b.exe" "$stage/" + done + cp THIRD_PARTY_NOTICES.md crates/tsc-gateway/tsgw.example.toml "$stage/" + if command -v zip >/dev/null; then + (cd "$tmp" && zip -qr "$out/$name.zip" "$name") + elif command -v 7z >/dev/null; then + (cd "$tmp" && 7z a -tzip -bso0 "$(native_path "$out/$name.zip")" "$name") + else + powershell -NoProfile -Command \ + "Compress-Archive -Path '$(native_path "$stage")' -DestinationPath '$(native_path "$out/$name.zip")'" + fi + files+=("$name.zip") + + makensis=${MAKENSIS:-$(command -v makensis || true)} + if [[ -z $makensis && -x "/c/Program Files (x86)/NSIS/makensis.exe" ]]; then + makensis="/c/Program Files (x86)/NSIS/makensis.exe" + fi + if [[ -z $makensis ]]; then + echo "makensis not found: skipping the installer" >&2 + return + fi + # Absolute paths: makensis changes into the script's directory. + "$makensis" -V2 -DVERSION="$version" -DOUTDIR="$(native_path "$out")" \ + -DBINARY="$(native_path "$(cd "$bin" && pwd)/tsc-desktop.exe")" packaging/windows/installer.nsi + files+=("tsc-desktop-$version-setup.exe") +} + +package_android() { + local apk android_version found=0 + android_version=$(crate_version crates/tsc-android) + for apk in android/app/build/outputs/apk/*/*.apk; do + [[ -e $apk ]] || continue + # app-debug.apk, app-release.apk, app-release-unsigned.apk + local variant + variant=$(basename "$apk" .apk) + variant=${variant#app-} + cp "$apk" "$out/tsc-$android_version-android-$variant.apk" + files+=("tsc-$android_version-android-$variant.apk") + found=1 + done + ((found)) || { echo "no APKs in android/app/build/outputs/apk: build with Gradle first" >&2; exit 1; } +} + +"package_$kind" + +(cd "$out" && sha256sum "${files[@]}" >"SHA256SUMS-$kind") +printf '%s\n' "${files[@]/#/$out/}"