name: ROS Development Container on: push: branches: [main] tags: ['v*'] pull_request: paths: - 'Tools/packaging/containers/**' - 'Tools/ros2/ros2.repos' - 'Tools/setup/ubuntu.sh' - 'Tools/setup/requirements.txt' - '.github/workflows/ros_dev_container.yml' workflow_dispatch: inputs: tag: description: 'Tag prefix for both distros (e.g. main or v1.18; no ROS suffix)' type: string default: main build_ref: description: 'Source ref; empty uses the workflow ref' type: string default: '' deploy_to_registry: description: 'Publish the development image' type: boolean default: false concurrency: group: ros2-dev-${{ github.ref }}-${{ inputs.tag || 'main' }} cancel-in-progress: true permissions: contents: read packages: write jobs: build: name: Build ROS Development Image (${{ matrix.ros_distro }}, ${{ matrix.arch }}, ${{ matrix.target }}) runs-on: [runs-on,"runner=8cpu-linux-${{ matrix.runner }}","image=ubuntu24-full-${{ matrix.runner }}","run-id=${{ github.run_id }}",extras=s3-cache,spot=false] strategy: fail-fast: false matrix: ros_distro: [humble, jazzy] arch: [amd64, arm64] target: [ros2-dev, ros2-gazebo-dev] include: - { arch: amd64, runner: x64 } - { arch: arm64, runner: arm64 } outputs: revision: ${{ steps.revision.outputs.sha }} steps: - uses: runs-on/action@v2 - uses: actions/checkout@v6 with: ref: ${{ inputs.build_ref || github.sha }} - name: Prepare development image context run: bash Tools/packaging/containers/prepare_context.sh - name: Resolve source revision id: revision env: TAG_PREFIX: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && github.ref_name || inputs.tag || 'main' }} run: | # Reserve seven characters of Docker's 128-character limit for -humble. if [[ ! "$TAG_PREFIX" =~ ^[a-zA-Z0-9_][a-zA-Z0-9_.-]{0,120}$ ]] || [[ "$TAG_PREFIX" == *-humble || "$TAG_PREFIX" == *-jazzy ]]; then echo "Use a tag prefix without a ROS suffix, e.g. main or v1.18" >&2 exit 1 fi echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" - name: Resolve image name id: image run: | if [[ "${{ matrix.target }}" == "ros2-gazebo-dev" ]]; then echo "name=px4-dev-ros2-gazebo" >> "$GITHUB_OUTPUT" else echo "name=px4-dev-ros2" >> "$GITHUB_OUTPUT" fi - uses: docker/login-action@v4 if: >- github.repository == 'PX4/PX4-Autopilot' && ((github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) || (github.event_name == 'workflow_dispatch' && inputs.deploy_to_registry == true)) with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - uses: docker/login-action@v4 if: >- github.repository == 'PX4/PX4-Autopilot' && ((github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) || (github.event_name == 'workflow_dispatch' && inputs.deploy_to_registry == true)) with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - uses: docker/setup-buildx-action@v4 with: # Gazebo/ROS SBOMs exceed the 40 MiB attestation limit in BuildKit 0.32. driver-opts: image=moby/buildkit:v0.33.0 platforms: linux/${{ matrix.arch }} - name: Build development image without firmware uses: docker/bake-action@v7 env: ARCH: ${{ matrix.arch }} ROS_DISTRO: ${{ matrix.ros_distro }} CACHE_GHA: "true" with: source: . files: Tools/packaging/containers/docker-bake.hcl targets: ${{ matrix.target }} push: >- ${{ github.repository == 'PX4/PX4-Autopilot' && ((github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) || (github.event_name == 'workflow_dispatch' && inputs.deploy_to_registry == true)) }} sbom: true provenance: false set: | ${{ matrix.target }}.tags=ghcr.io/px4/${{ steps.image.outputs.name }}:sha-${{ steps.revision.outputs.sha }}-${{ matrix.ros_distro }}-${{ matrix.arch }} ${{ matrix.target }}.tags=px4io/${{ steps.image.outputs.name }}:sha-${{ steps.revision.outputs.sha }}-${{ matrix.ros_distro }}-${{ matrix.arch }} ${{ matrix.target }}.labels.org.opencontainers.image.source=https://github.com/PX4/PX4-Autopilot ${{ matrix.target }}.labels.org.opencontainers.image.revision=${{ steps.revision.outputs.sha }} deploy: name: Publish Multi-Architecture ROS Development Image (${{ matrix.ros_distro }}, ${{ matrix.target }}) needs: build if: >- github.repository == 'PX4/PX4-Autopilot' && ((github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) || (github.event_name == 'workflow_dispatch' && inputs.deploy_to_registry == true)) strategy: fail-fast: false matrix: ros_distro: [humble, jazzy] target: [ros2-dev, ros2-gazebo-dev] runs-on: [runs-on,"runner=1cpu-linux-x64","image=ubuntu24-full-x64","run-id=${{ github.run_id }}",extras=s3-cache,spot=false] steps: - uses: runs-on/action@v2 - uses: docker/login-action@v4 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - uses: docker/login-action@v4 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - uses: docker/setup-buildx-action@v4 - name: Assemble image and SBOM indexes env: TAG_PREFIX: ${{ github.event_name == 'push' && github.ref_name || inputs.tag || 'main' }} ROS_DISTRO: ${{ matrix.ros_distro }} REVISION: ${{ needs.build.outputs.revision }} IMAGE_NAME: ${{ matrix.target == 'ros2-gazebo-dev' && 'px4-dev-ros2-gazebo' || 'px4-dev-ros2' }} run: | for REGISTRY in px4io ghcr.io/px4; do IMAGE="${REGISTRY}/${IMAGE_NAME}" docker buildx imagetools create \ --tag "${IMAGE}:${TAG_PREFIX}-${ROS_DISTRO}" --tag "${IMAGE}:sha-${REVISION}-${ROS_DISTRO}" \ "${IMAGE}:sha-${REVISION}-${ROS_DISTRO}-amd64" "${IMAGE}:sha-${REVISION}-${ROS_DISTRO}-arm64" done