mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-15 04:33:33 +08:00
container: px4-sitl image
Signed-off-by: Ramon Roche <mrpollo@gmail.com>
This commit is contained in:
@@ -0,0 +1,188 @@
|
||||
name: SITL Container
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'main'
|
||||
- 'stable'
|
||||
- 'beta'
|
||||
- 'release/**'
|
||||
tags:
|
||||
- 'v*'
|
||||
pull_request:
|
||||
branches:
|
||||
- '**'
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
px4_version:
|
||||
description: 'Container tag (e.g. v1.16.0)'
|
||||
required: true
|
||||
type: string
|
||||
deploy_to_registry:
|
||||
description: 'Whether to push built images to the registry'
|
||||
required: false
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
jobs:
|
||||
setup:
|
||||
name: Set Tags and Variables
|
||||
permissions:
|
||||
contents: read
|
||||
runs-on: [runs-on,"runner=1cpu-linux-x64","image=ubuntu24-full-x64","run-id=${{ github.run_id }}",spot=false,extras=s3-cache]
|
||||
outputs:
|
||||
px4_version: ${{ steps.px4_version.outputs.px4_version }}
|
||||
meta_tags: ${{ steps.meta.outputs.tags }}
|
||||
meta_labels: ${{ steps.meta.outputs.labels }}
|
||||
steps:
|
||||
- uses: runs-on/action@v1
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-tags: true
|
||||
submodules: false
|
||||
fetch-depth: 0
|
||||
|
||||
# If manual dispatch, take the user‐provided input
|
||||
- name: Set PX4 Tag Version
|
||||
id: px4_version
|
||||
run: |
|
||||
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
|
||||
echo "px4_version=${{ github.event.inputs.px4_version }}" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "px4_version=$(git describe --tags --match 'v[0-9]*')" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Extract metadata (tags, labels) for Docker
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: |
|
||||
ghcr.io/PX4/px4-sitl
|
||||
px4io/px4-sitl
|
||||
tags: |
|
||||
type=raw,enable=true,value=${{ steps.px4_version.outputs.px4_version }},priority=1000
|
||||
|
||||
build:
|
||||
name: Build (${{ matrix.arch }})
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
needs: setup
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- platform: linux/arm64
|
||||
arch: arm64
|
||||
runner: arm64
|
||||
- platform: linux/amd64
|
||||
arch: amd64
|
||||
runner: x64
|
||||
runs-on: [runs-on,"runner=8cpu-linux-${{ matrix.runner }}","image=ubuntu24-full-${{ matrix.runner }}","run-id=${{ github.run_id }}",spot=false,extras=s3-cache]
|
||||
steps:
|
||||
- uses: runs-on/action@v1
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-tags: true
|
||||
submodules: false
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install PX4 Dependencies
|
||||
run: ./Tools/setup/ubuntu.sh
|
||||
|
||||
- name: Build PX4 SITL
|
||||
run: make px4_sitl_default none
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
if: ${{ startsWith(github.ref, 'refs/tags/') || (github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_to_registry) }}
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
if: ${{ startsWith(github.ref, 'refs/tags/') || (github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_to_registry) }}
|
||||
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 Load Container Image
|
||||
uses: docker/build-push-action@v6
|
||||
id: docker
|
||||
with:
|
||||
context: Tools/sitl-container
|
||||
tags: |
|
||||
ghcr.io/px4/px4-sitl:${{ needs.setup.outputs.px4_version }}-${{ matrix.arch }}
|
||||
px4io/px4-sitl:${{ needs.setup.outputs.px4_version }}-${{ matrix.arch }}
|
||||
labels: ${{ needs.setup.outputs.meta_labels }}
|
||||
platforms: ${{ matrix.platform }}
|
||||
load: false
|
||||
push: ${{ startsWith(github.ref, 'refs/tags/') || (github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_to_registry) }}
|
||||
provenance: false
|
||||
cache-from: type=gha,version=1
|
||||
cache-to: type=gha,version=1,mode=max
|
||||
|
||||
deploy:
|
||||
name: Deploy To Registry
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
runs-on: [runs-on,"runner=8cpu-linux-x64","image=ubuntu24-full-x64","run-id=${{ github.run_id }}",spot=false,extras=s3-cache]
|
||||
needs: [build, setup]
|
||||
if: ${{ startsWith(github.ref, 'refs/tags/') || (github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_to_registry) }}
|
||||
steps:
|
||||
- uses: runs-on/action@v1
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-tags: true
|
||||
submodules: false
|
||||
fetch-depth: 0
|
||||
|
||||
- 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 Images Exist Before Creating Manifest
|
||||
run: |
|
||||
docker manifest inspect px4io/px4-sitl:${{ needs.setup.outputs.px4_version }}-arm64 || echo "⚠️ Warning: No ARM64 image found!"
|
||||
docker manifest inspect px4io/px4-sitl:${{ needs.setup.outputs.px4_version }}-amd64 || echo "⚠️ Warning: No AMD64 image found!"
|
||||
docker manifest inspect ghcr.io/px4/px4-sitl:${{ needs.setup.outputs.px4_version }}-arm64 || echo "⚠️ Warning: No ARM64 image found!"
|
||||
docker manifest inspect ghcr.io/px4/px4-sitl:${{ needs.setup.outputs.px4_version }}-amd64 || echo "⚠️ Warning: No AMD64 image found!"
|
||||
|
||||
- name: Create and Push Multi-Arch Manifest for Docker Hub
|
||||
run: |
|
||||
docker manifest create px4io/px4-sitl:${{ needs.setup.outputs.px4_version }} \
|
||||
--amend px4io/px4-sitl:${{ needs.setup.outputs.px4_version }}-arm64 \
|
||||
--amend px4io/px4-sitl:${{ needs.setup.outputs.px4_version }}-amd64
|
||||
|
||||
docker manifest annotate px4io/px4-sitl:${{ needs.setup.outputs.px4_version }} px4io/px4-sitl:${{ needs.setup.outputs.px4_version }}-arm64 --arch arm64
|
||||
docker manifest annotate px4io/px4-sitl:${{ needs.setup.outputs.px4_version }} px4io/px4-sitl:${{ needs.setup.outputs.px4_version }}-amd64 --arch amd64
|
||||
|
||||
docker manifest push px4io/px4-sitl:${{ needs.setup.outputs.px4_version }}
|
||||
|
||||
- name: Create and Push Multi-Arch Manifest for GHCR
|
||||
run: |
|
||||
docker manifest create ghcr.io/px4/px4-sitl:${{ needs.setup.outputs.px4_version }} \
|
||||
--amend ghcr.io/px4/px4-sitl:${{ needs.setup.outputs.px4_version }}-arm64 \
|
||||
--amend ghcr.io/px4/px4-sitl:${{ needs.setup.outputs.px4_version }}-amd64
|
||||
|
||||
docker manifest annotate ghcr.io/px4/px4-sitl:${{ needs.setup.outputs.px4_version }} ghcr.io/px4/px4-sitl:${{ needs.setup.outputs.px4_version }}-arm64 --arch arm64
|
||||
docker manifest annotate ghcr.io/px4/px4-sitl:${{ needs.setup.outputs.px4_version }} ghcr.io/px4/px4-sitl:${{ needs.setup.outputs.px4_version }}-amd64 --arch amd64
|
||||
|
||||
docker manifest push ghcr.io/px4/px4-sitl:${{ needs.setup.outputs.px4_version }}
|
||||
@@ -0,0 +1,55 @@
|
||||
FROM ubuntu:24.04
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
ca-certificates \
|
||||
curl \
|
||||
gnupg \
|
||||
lsb-release \
|
||||
libbsd0 \
|
||||
libcom-err2 \
|
||||
libc6 \
|
||||
libgcc-s1 \
|
||||
libgssapi-krb5-2 \
|
||||
libk5crypto3 \
|
||||
libkeyutils1 \
|
||||
libkrb5-3 \
|
||||
libkrb5support0 \
|
||||
libmd0 \
|
||||
libnorm1 \
|
||||
libpgm-5.3-0 \
|
||||
libprotobuf32 \
|
||||
libprotobuf-lite32t64 \
|
||||
libsodium23 \
|
||||
libstdc++6 \
|
||||
libuuid1 \
|
||||
libzmq5 \
|
||||
wget \
|
||||
zlib1g \
|
||||
&& rm -fr /var/lib/apt/lists/*
|
||||
|
||||
RUN curl -sSL https://packages.osrfoundation.org/gazebo.key \
|
||||
| gpg --dearmor -o /usr/share/keyrings/gazebo-archive-keyring.gpg \
|
||||
&& echo "deb [signed-by=/usr/share/keyrings/gazebo-archive-keyring.gpg] \
|
||||
http://packages.osrfoundation.org/gazebo/ubuntu-stable \
|
||||
$(lsb_release -cs) main" \
|
||||
> /etc/apt/sources.list.d/gazebo-stable.list \
|
||||
&& apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
libgz-msgs10 \
|
||||
libgz-transport13 \
|
||||
libgz-utils2 \
|
||||
&& rm -fr /var/lib/apt/lists/*
|
||||
|
||||
COPY build/px4_sitl_default/bin /opt/px4/bin
|
||||
COPY build/px4_sitl_default/etc /opt/px4/etc
|
||||
|
||||
WORKDIR /opt/px4
|
||||
|
||||
COPY Tools/sitl-container/entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||
RUN chmod +x /usr/local/bin/entrypoint.sh
|
||||
|
||||
EXPOSE 14540/udp 14550/udp 8888/udp
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
||||
CMD []
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
sudo docker run \
|
||||
--rm -it \
|
||||
--device /dev/fuse --cap-add SYS_ADMIN \
|
||||
-p 14540:14540/udp \
|
||||
-p 14550:14550/udp \
|
||||
-p 8888:8888/udp \
|
||||
px4-sitl:local
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
PX4_BIN=/opt/px4/bin/px4
|
||||
|
||||
# if no args passed, default to SITL none
|
||||
if [ $# -eq 0 ]; then
|
||||
exec "$PX4_BIN"
|
||||
else
|
||||
exec "$PX4_BIN" "$@"
|
||||
fi
|
||||
Reference in New Issue
Block a user