mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-19 02:23:58 +08:00
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:
@@ -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}
|
||||
Reference in New Issue
Block a user