build(packaging): add PX4 SITL .deb packages

Add cmake/cpack infrastructure for building .deb packages from
px4_sitl_sih and px4_sitl_default targets. Includes install rules,
package scripts, Gazebo wrapper, and CI workflow.

Signed-off-by: Ramon Roche <mrpollo@gmail.com>
This commit is contained in:
Ramon Roche
2026-04-02 13:13:38 -07:00
parent ebe0b727d8
commit 1079c57fd0
16 changed files with 940 additions and 41 deletions
+115
View File
@@ -0,0 +1,115 @@
name: Build PX4 .deb Package
description: Build PX4 SITL, run cpack, validate the .deb, and upload artifact
inputs:
target:
description: 'Build target: default or sih'
required: true
artifact-name:
description: Name for the uploaded artifact
required: true
ccache-key-prefix:
description: Prefix for ccache cache keys
default: deb-ccache
ccache-max-size:
description: Maximum ccache size
default: 400M
runs:
using: composite
steps:
- name: Restore ccache
id: ccache-restore
uses: actions/cache/restore@v4
with:
path: ~/.ccache
key: ${{ inputs.ccache-key-prefix }}-${{ github.ref_name }}-${{ github.sha }}
restore-keys: |
${{ inputs.ccache-key-prefix }}-${{ github.ref_name }}-
${{ inputs.ccache-key-prefix }}-${{ github.base_ref || 'main' }}-
${{ inputs.ccache-key-prefix }}-
- name: Configure ccache
shell: bash
run: |
mkdir -p ~/.ccache
echo "base_dir = ${GITHUB_WORKSPACE}" > ~/.ccache/ccache.conf
echo "compression = true" >> ~/.ccache/ccache.conf
echo "compression_level = 6" >> ~/.ccache/ccache.conf
echo "max_size = ${{ inputs.ccache-max-size }}" >> ~/.ccache/ccache.conf
echo "hash_dir = false" >> ~/.ccache/ccache.conf
echo "compiler_check = content" >> ~/.ccache/ccache.conf
ccache -s
ccache -z
- name: Build PX4 SITL
shell: bash
run: make px4_sitl_${{ inputs.target }}
- name: ccache stats
if: always()
shell: bash
run: ccache -s
- name: Save ccache
uses: actions/cache/save@v4
if: always()
with:
path: ~/.ccache
key: ${{ inputs.ccache-key-prefix }}-${{ github.ref_name }}-${{ github.sha }}
- name: Build .deb package
shell: bash
run: |
cd build/px4_sitl_${{ inputs.target }}
cpack -G DEB
- name: Print package info and contents
shell: bash
run: |
cd build/px4_sitl_${{ inputs.target }}
echo "--- Package info ---"
dpkg-deb -I *.deb
echo "--- Package contents ---"
dpkg-deb -c *.deb
- name: Validate sih package
if: inputs.target == 'sih'
shell: bash
run: |
cd build/px4_sitl_sih
echo "--- Verify NO Gazebo resources ---"
! dpkg-deb -c px4_*.deb | grep share/gz > /dev/null && echo "PASS: no Gazebo" || { echo "FAIL: Gazebo found"; exit 1; }
echo "--- Install test ---"
dpkg -i px4_*.deb
test -x /opt/px4/bin/px4 || { echo "FAIL: px4 binary not found"; exit 1; }
test -L /usr/bin/px4 || { echo "FAIL: symlink not created"; exit 1; }
test ! -d /opt/px4/share/gz || { echo "FAIL: Gazebo dir should not exist"; exit 1; }
echo "--- Smoke test ---"
/opt/px4/bin/px4 -h
echo "PASS: sih package validation successful"
- name: Validate gazebo package
if: inputs.target == 'default'
shell: bash
run: |
cd build/px4_sitl_default
echo "--- Verify Gazebo resources in package ---"
dpkg-deb -c px4-gazebo_*.deb | grep share/gz/models > /dev/null || { echo "FAIL: models missing"; exit 1; }
dpkg-deb -c px4-gazebo_*.deb | grep share/gz/worlds > /dev/null || { echo "FAIL: worlds missing"; exit 1; }
echo "--- Install test ---"
dpkg -i px4-gazebo_*.deb
test -x /opt/px4-gazebo/bin/px4 || { echo "FAIL: px4 binary not found"; exit 1; }
test -x /opt/px4-gazebo/bin/px4-gazebo || { echo "FAIL: wrapper not found"; exit 1; }
test -L /usr/bin/px4-gazebo || { echo "FAIL: symlink not created"; exit 1; }
test -d /opt/px4-gazebo/share/gz/models || { echo "FAIL: Gazebo models not installed"; exit 1; }
echo "--- Smoke test ---"
/opt/px4-gazebo/bin/px4 -h
echo "PASS: gazebo package validation successful"
- name: Upload .deb artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.artifact-name }}
path: build/px4_sitl_${{ inputs.target }}/*.deb
if-no-files-found: error
+252
View File
@@ -0,0 +1,252 @@
name: SITL Packages and Containers
on:
push:
tags: ['v*']
pull_request:
paths:
- 'cmake/package.cmake'
- 'platforms/posix/CMakeLists.txt'
- 'Tools/packaging/**'
- 'boards/px4/sitl/sih.px4board'
- '.github/workflows/build_deb_package.yml'
- '.github/actions/build-deb/**'
workflow_dispatch:
inputs:
deploy_containers:
description: 'Push container images to registry'
required: false
type: boolean
default: false
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
packages: write
env:
RUNS_IN_DOCKER: true
jobs:
# ---------------------------------------------------------------------------
# Setup: extract version and determine whether to push containers
# ---------------------------------------------------------------------------
setup:
name: Setup
runs-on: [runs-on,"runner=1cpu-linux-x64","image=ubuntu24-full-x64","run-id=${{ github.run_id }}",extras=s3-cache,spot=false]
outputs:
px4_version: ${{ steps.px4_version.outputs.px4_version }}
should_push: ${{ steps.push_check.outputs.should_push }}
steps:
- uses: runs-on/action@v2
- uses: actions/checkout@v4
with:
fetch-tags: true
submodules: false
fetch-depth: 0
- name: Set PX4 version
id: px4_version
run: echo "px4_version=$(git describe --tags --match 'v[0-9]*')" >> $GITHUB_OUTPUT
- name: Check if we should push containers
id: push_check
run: |
if [[ "${{ startsWith(github.ref, 'refs/tags/') }}" == "true" ]] || \
[[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ github.event.inputs.deploy_containers }}" == "true" ]]; then
echo "should_push=true" >> $GITHUB_OUTPUT
else
echo "should_push=false" >> $GITHUB_OUTPUT
fi
# ---------------------------------------------------------------------------
# Build .deb packages (all distros, arches, targets)
# ---------------------------------------------------------------------------
build-deb:
name: "Build .deb (${{ matrix.target }}/${{ matrix.codename }}/${{ matrix.arch }})"
needs: setup
runs-on: [runs-on,"runner=4cpu-linux-${{ matrix.runner }}","image=ubuntu24-full-${{ matrix.runner }}","run-id=${{ github.run_id }}",extras=s3-cache,spot=false]
container:
image: ${{ matrix.container }}
volumes:
- /github/workspace:/github/workspace
strategy:
fail-fast: false
matrix:
include:
# Gazebo builds
- { codename: noble, arch: amd64, runner: x64, container: "ubuntu:24.04", target: default, setup_flags: "" }
- { codename: noble, arch: arm64, runner: arm64, container: "ubuntu:24.04", target: default, setup_flags: "" }
- { codename: jammy, arch: amd64, runner: x64, container: "ubuntu:22.04", target: default, setup_flags: "" }
- { codename: jammy, arch: arm64, runner: arm64, container: "ubuntu:22.04", target: default, setup_flags: "" }
# SIH builds
- { codename: noble, arch: amd64, runner: x64, container: "ubuntu:24.04", target: sih, setup_flags: "--no-sim-tools" }
- { codename: noble, arch: arm64, runner: arm64, container: "ubuntu:24.04", target: sih, setup_flags: "--no-sim-tools" }
- { codename: jammy, arch: amd64, runner: x64, container: "ubuntu:22.04", target: sih, setup_flags: "--no-sim-tools" }
- { codename: jammy, arch: arm64, runner: arm64, container: "ubuntu:22.04", target: sih, setup_flags: "--no-sim-tools" }
steps:
- uses: runs-on/action@v2
- name: Fix git in container
run: |
apt-get update && apt-get install -y git
git config --global --add safe.directory $(realpath .)
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Cache apt packages
uses: actions/cache@v4
with:
path: /var/cache/apt/archives
key: apt-${{ matrix.target }}-${{ matrix.codename }}-${{ matrix.arch }}-${{ hashFiles('Tools/setup/ubuntu.sh') }}
restore-keys: apt-${{ matrix.target }}-${{ matrix.codename }}-${{ matrix.arch }}-
- name: Install dependencies
run: ./Tools/setup/ubuntu.sh --no-nuttx ${{ matrix.setup_flags }}
- name: Build and package .deb
uses: ./.github/actions/build-deb
with:
target: ${{ matrix.target }}
artifact-name: px4-sitl-debs-${{ matrix.target }}-${{ matrix.codename }}-${{ matrix.arch }}
ccache-key-prefix: deb-ccache-${{ matrix.target }}-${{ matrix.codename }}-${{ matrix.arch }}
# ---------------------------------------------------------------------------
# Build Docker images from Noble .debs
# ---------------------------------------------------------------------------
build-docker:
name: "Build Image (${{ matrix.image }}/${{ matrix.arch }})"
needs: [setup, build-deb]
runs-on: [runs-on,"runner=4cpu-linux-${{ matrix.runner }}","image=ubuntu24-full-${{ matrix.runner }}","run-id=${{ github.run_id }}",extras=s3-cache,spot=false]
strategy:
fail-fast: false
matrix:
include:
- { image: sih, target: sih, arch: amd64, runner: x64, platform: "linux/amd64", dockerfile: Dockerfile.sih }
- { image: sih, target: sih, arch: arm64, runner: arm64, platform: "linux/arm64", dockerfile: Dockerfile.sih }
- { image: gazebo, target: default, arch: amd64, runner: x64, platform: "linux/amd64", dockerfile: Dockerfile.gazebo }
- { image: gazebo, target: default, arch: arm64, runner: arm64, platform: "linux/arm64", dockerfile: Dockerfile.gazebo }
steps:
- uses: runs-on/action@v2
- uses: actions/checkout@v4
with:
submodules: false
fetch-depth: 1
- name: Download Noble .deb artifact
uses: actions/download-artifact@v4
with:
name: px4-sitl-debs-${{ matrix.target }}-noble-${{ matrix.arch }}
path: docker-context
- name: Prepare build context
run: |
cp Tools/packaging/px4-entrypoint.sh docker-context/
ls -lh docker-context/
- name: Login to Docker Hub
uses: docker/login-action@v3
if: needs.setup.outputs.should_push == 'true'
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
if: needs.setup.outputs.should_push == 'true'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver: docker-container
platforms: ${{ matrix.platform }}
- name: Build and push container image
uses: docker/build-push-action@v6
with:
context: docker-context
file: Tools/packaging/${{ matrix.dockerfile }}
tags: |
px4io/px4-sitl-${{ matrix.image }}:${{ needs.setup.outputs.px4_version }}-${{ matrix.arch }}
ghcr.io/px4/px4-sitl-${{ matrix.image }}:${{ needs.setup.outputs.px4_version }}-${{ matrix.arch }}
platforms: ${{ matrix.platform }}
load: false
push: ${{ needs.setup.outputs.should_push == 'true' }}
provenance: false
cache-from: type=gha,scope=sitl-${{ matrix.image }}-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=sitl-${{ matrix.image }}-${{ matrix.arch }}
# ---------------------------------------------------------------------------
# Deploy: create multi-arch manifests and push to registries
# ---------------------------------------------------------------------------
deploy:
name: "Deploy (${{ matrix.image }})"
needs: [setup, build-docker]
if: needs.setup.outputs.should_push == 'true'
runs-on: [runs-on,"runner=1cpu-linux-x64","image=ubuntu24-full-x64","run-id=${{ github.run_id }}",extras=s3-cache,spot=false]
strategy:
matrix:
image: [sih, gazebo]
steps:
- uses: runs-on/action@v2
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Verify per-arch images exist
run: |
for registry in px4io ghcr.io/px4; do
for arch in amd64 arm64; do
docker manifest inspect ${registry}/px4-sitl-${{ matrix.image }}:${{ needs.setup.outputs.px4_version }}-${arch} \
|| echo "Warning: ${registry}/px4-sitl-${{ matrix.image }}:${{ needs.setup.outputs.px4_version }}-${arch} not found"
done
done
- name: Create and push multi-arch manifest (Docker Hub)
run: |
VERSION="${{ needs.setup.outputs.px4_version }}"
IMAGE="px4io/px4-sitl-${{ matrix.image }}"
docker manifest create ${IMAGE}:${VERSION} \
--amend ${IMAGE}:${VERSION}-arm64 \
--amend ${IMAGE}:${VERSION}-amd64
docker manifest annotate ${IMAGE}:${VERSION} ${IMAGE}:${VERSION}-arm64 --arch arm64
docker manifest annotate ${IMAGE}:${VERSION} ${IMAGE}:${VERSION}-amd64 --arch amd64
docker manifest push ${IMAGE}:${VERSION}
- name: Create and push multi-arch manifest (GHCR)
run: |
VERSION="${{ needs.setup.outputs.px4_version }}"
IMAGE="ghcr.io/px4/px4-sitl-${{ matrix.image }}"
docker manifest create ${IMAGE}:${VERSION} \
--amend ${IMAGE}:${VERSION}-arm64 \
--amend ${IMAGE}:${VERSION}-amd64
docker manifest annotate ${IMAGE}:${VERSION} ${IMAGE}:${VERSION}-arm64 --arch arm64
docker manifest annotate ${IMAGE}:${VERSION} ${IMAGE}:${VERSION}-amd64 --arch amd64
docker manifest push ${IMAGE}:${VERSION}