1- name : Build .deb Packages
1+ name : SITL Packages and Containers
22
33on :
44 push :
1111 - ' boards/px4/sitl/sih.px4board'
1212 - ' .github/workflows/build_deb_package.yml'
1313 - ' .github/actions/build-deb/**'
14- workflow_dispatch : {}
14+ workflow_dispatch :
15+ inputs :
16+ deploy_containers :
17+ description : ' Push container images to registry'
18+ required : false
19+ type : boolean
20+ default : false
1521
1622concurrency :
1723 group : ${{ github.workflow }}-${{ github.ref }}
1824 cancel-in-progress : true
1925
2026permissions :
2127 contents : read
28+ packages : write
2229
2330env :
2431 RUNS_IN_DOCKER : true
2532
2633jobs :
34+
35+ # ---------------------------------------------------------------------------
36+ # Setup: extract version and determine whether to push containers
37+ # ---------------------------------------------------------------------------
38+ setup :
39+ name : Setup
40+ runs-on : [runs-on,"runner=1cpu-linux-x64","image=ubuntu24-full-x64","run-id=${{ github.run_id }}",extras=s3-cache,spot=false]
41+ outputs :
42+ px4_version : ${{ steps.px4_version.outputs.px4_version }}
43+ should_push : ${{ steps.push_check.outputs.should_push }}
44+ steps :
45+ - uses : runs-on/action@v2
46+ - uses : actions/checkout@v4
47+ with :
48+ fetch-tags : true
49+ submodules : false
50+ fetch-depth : 0
51+
52+ - name : Set PX4 version
53+ id : px4_version
54+ run : echo "px4_version=$(git describe --tags --match 'v[0-9]*')" >> $GITHUB_OUTPUT
55+
56+ - name : Check if we should push containers
57+ id : push_check
58+ run : |
59+ if [[ "${{ startsWith(github.ref, 'refs/tags/') }}" == "true" ]] || \
60+ [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ github.event.inputs.deploy_containers }}" == "true" ]]; then
61+ echo "should_push=true" >> $GITHUB_OUTPUT
62+ else
63+ echo "should_push=false" >> $GITHUB_OUTPUT
64+ fi
65+
66+ # ---------------------------------------------------------------------------
67+ # Build .deb packages (all distros, arches, targets)
68+ # ---------------------------------------------------------------------------
2769 build-deb :
2870 name : " Build .deb (${{ matrix.target }}/${{ matrix.codename }}/${{ matrix.arch }})"
29- runs-on : [runs-on,"runner=4cpu-linux-${{ matrix.runner }}","image=ubuntu24-full-${{ matrix.runner }}","run-id=${{ github.run_id }}",spot=false]
71+ needs : setup
72+ runs-on : [runs-on,"runner=4cpu-linux-${{ matrix.runner }}","image=ubuntu24-full-${{ matrix.runner }}","run-id=${{ github.run_id }}",extras=s3-cache,spot=false]
3073 container :
3174 image : ${{ matrix.container }}
3275 volumes :
@@ -35,28 +78,36 @@ jobs:
3578 fail-fast : false
3679 matrix :
3780 include :
38- # Default ( Gazebo) builds
81+ # Gazebo builds
3982 - { codename: noble, arch: amd64, runner: x64, container: "ubuntu:24.04", target: default, setup_flags: "" }
4083 - { codename: noble, arch: arm64, runner: arm64, container: "ubuntu:24.04", target: default, setup_flags: "" }
4184 - { codename: jammy, arch: amd64, runner: x64, container: "ubuntu:22.04", target: default, setup_flags: "" }
4285 - { codename: jammy, arch: arm64, runner: arm64, container: "ubuntu:22.04", target: default, setup_flags: "" }
43- # SIH (no Gazebo) builds
86+ # SIH builds
4487 - { codename: noble, arch: amd64, runner: x64, container: "ubuntu:24.04", target: sih, setup_flags: "--no-sim-tools" }
4588 - { codename: noble, arch: arm64, runner: arm64, container: "ubuntu:24.04", target: sih, setup_flags: "--no-sim-tools" }
4689 - { codename: jammy, arch: amd64, runner: x64, container: "ubuntu:22.04", target: sih, setup_flags: "--no-sim-tools" }
4790 - { codename: jammy, arch: arm64, runner: arm64, container: "ubuntu:22.04", target: sih, setup_flags: "--no-sim-tools" }
48-
4991 steps :
92+ - uses : runs-on/action@v2
93+
5094 - name : Fix git in container
5195 run : |
52- apt update && apt install git -y
96+ apt-get update && apt-get install -y git
5397 git config --global --add safe.directory $(realpath .)
5498
5599 - uses : actions/checkout@v4
56100 with :
57101 fetch-depth : 0
58102 fetch-tags : true
59103
104+ - name : Cache apt packages
105+ uses : actions/cache@v4
106+ with :
107+ path : /var/cache/apt/archives
108+ key : apt-${{ matrix.target }}-${{ matrix.codename }}-${{ matrix.arch }}-${{ hashFiles('Tools/setup/ubuntu.sh') }}
109+ restore-keys : apt-${{ matrix.target }}-${{ matrix.codename }}-${{ matrix.arch }}-
110+
60111 - name : Install dependencies
61112 run : ./Tools/setup/ubuntu.sh --no-nuttx ${{ matrix.setup_flags }}
62113
@@ -66,3 +117,136 @@ jobs:
66117 target : ${{ matrix.target }}
67118 artifact-name : px4-sitl-debs-${{ matrix.target }}-${{ matrix.codename }}-${{ matrix.arch }}
68119 ccache-key-prefix : deb-ccache-${{ matrix.target }}-${{ matrix.codename }}-${{ matrix.arch }}
120+
121+ # ---------------------------------------------------------------------------
122+ # Build Docker images from Noble .debs
123+ # ---------------------------------------------------------------------------
124+ build-docker :
125+ name : " Build Image (${{ matrix.image }}/${{ matrix.arch }})"
126+ needs : [setup, build-deb]
127+ runs-on : [runs-on,"runner=4cpu-linux-${{ matrix.runner }}","image=ubuntu24-full-${{ matrix.runner }}","run-id=${{ github.run_id }}",extras=s3-cache,spot=false]
128+ strategy :
129+ fail-fast : false
130+ matrix :
131+ include :
132+ - { image: sih, target: sih, arch: amd64, runner: x64, platform: "linux/amd64", dockerfile: Dockerfile.sih }
133+ - { image: sih, target: sih, arch: arm64, runner: arm64, platform: "linux/arm64", dockerfile: Dockerfile.sih }
134+ - { image: gazebo, target: default, arch: amd64, runner: x64, platform: "linux/amd64", dockerfile: Dockerfile.gazebo }
135+ - { image: gazebo, target: default, arch: arm64, runner: arm64, platform: "linux/arm64", dockerfile: Dockerfile.gazebo }
136+ steps :
137+ - uses : runs-on/action@v2
138+ - uses : actions/checkout@v4
139+ with :
140+ submodules : false
141+ fetch-depth : 1
142+
143+ - name : Download Noble .deb artifact
144+ uses : actions/download-artifact@v4
145+ with :
146+ name : px4-sitl-debs-${{ matrix.target }}-noble-${{ matrix.arch }}
147+ path : docker-context
148+
149+ - name : Prepare build context
150+ run : |
151+ cp Tools/packaging/px4-entrypoint.sh docker-context/
152+ ls -lh docker-context/
153+
154+ - name : Login to Docker Hub
155+ uses : docker/login-action@v3
156+ if : needs.setup.outputs.should_push == 'true'
157+ with :
158+ username : ${{ secrets.DOCKERHUB_USERNAME }}
159+ password : ${{ secrets.DOCKERHUB_TOKEN }}
160+
161+ - name : Login to GitHub Container Registry
162+ uses : docker/login-action@v3
163+ if : needs.setup.outputs.should_push == 'true'
164+ with :
165+ registry : ghcr.io
166+ username : ${{ github.actor }}
167+ password : ${{ secrets.GITHUB_TOKEN }}
168+
169+ - name : Set up Docker Buildx
170+ uses : docker/setup-buildx-action@v3
171+ with :
172+ driver : docker-container
173+ platforms : ${{ matrix.platform }}
174+
175+ - name : Build and push container image
176+ uses : docker/build-push-action@v6
177+ with :
178+ context : docker-context
179+ file : Tools/packaging/${{ matrix.dockerfile }}
180+ tags : |
181+ px4io/px4-sitl-${{ matrix.image }}:${{ needs.setup.outputs.px4_version }}-${{ matrix.arch }}
182+ ghcr.io/px4/px4-sitl-${{ matrix.image }}:${{ needs.setup.outputs.px4_version }}-${{ matrix.arch }}
183+ platforms : ${{ matrix.platform }}
184+ load : false
185+ push : ${{ needs.setup.outputs.should_push == 'true' }}
186+ provenance : false
187+ cache-from : type=gha,scope=sitl-${{ matrix.image }}-${{ matrix.arch }}
188+ cache-to : type=gha,mode=max,scope=sitl-${{ matrix.image }}-${{ matrix.arch }}
189+
190+ # ---------------------------------------------------------------------------
191+ # Deploy: create multi-arch manifests and push to registries
192+ # ---------------------------------------------------------------------------
193+ deploy :
194+ name : " Deploy (${{ matrix.image }})"
195+ needs : [setup, build-docker]
196+ if : needs.setup.outputs.should_push == 'true'
197+ runs-on : [runs-on,"runner=1cpu-linux-x64","image=ubuntu24-full-x64","run-id=${{ github.run_id }}",extras=s3-cache,spot=false]
198+ strategy :
199+ matrix :
200+ image : [sih, gazebo]
201+ steps :
202+ - uses : runs-on/action@v2
203+
204+ - name : Login to Docker Hub
205+ uses : docker/login-action@v3
206+ with :
207+ username : ${{ secrets.DOCKERHUB_USERNAME }}
208+ password : ${{ secrets.DOCKERHUB_TOKEN }}
209+
210+ - name : Login to GitHub Container Registry
211+ uses : docker/login-action@v3
212+ with :
213+ registry : ghcr.io
214+ username : ${{ github.actor }}
215+ password : ${{ secrets.GITHUB_TOKEN }}
216+
217+ - name : Verify per-arch images exist
218+ run : |
219+ for registry in px4io ghcr.io/px4; do
220+ for arch in amd64 arm64; do
221+ docker manifest inspect ${registry}/px4-sitl-${{ matrix.image }}:${{ needs.setup.outputs.px4_version }}-${arch} \
222+ || echo "Warning: ${registry}/px4-sitl-${{ matrix.image }}:${{ needs.setup.outputs.px4_version }}-${arch} not found"
223+ done
224+ done
225+
226+ - name : Create and push multi-arch manifest (Docker Hub)
227+ run : |
228+ VERSION="${{ needs.setup.outputs.px4_version }}"
229+ IMAGE="px4io/px4-sitl-${{ matrix.image }}"
230+
231+ docker manifest create ${IMAGE}:${VERSION} \
232+ --amend ${IMAGE}:${VERSION}-arm64 \
233+ --amend ${IMAGE}:${VERSION}-amd64
234+
235+ docker manifest annotate ${IMAGE}:${VERSION} ${IMAGE}:${VERSION}-arm64 --arch arm64
236+ docker manifest annotate ${IMAGE}:${VERSION} ${IMAGE}:${VERSION}-amd64 --arch amd64
237+
238+ docker manifest push ${IMAGE}:${VERSION}
239+
240+ - name : Create and push multi-arch manifest (GHCR)
241+ run : |
242+ VERSION="${{ needs.setup.outputs.px4_version }}"
243+ IMAGE="ghcr.io/px4/px4-sitl-${{ matrix.image }}"
244+
245+ docker manifest create ${IMAGE}:${VERSION} \
246+ --amend ${IMAGE}:${VERSION}-arm64 \
247+ --amend ${IMAGE}:${VERSION}-amd64
248+
249+ docker manifest annotate ${IMAGE}:${VERSION} ${IMAGE}:${VERSION}-arm64 --arch arm64
250+ docker manifest annotate ${IMAGE}:${VERSION} ${IMAGE}:${VERSION}-amd64 --arch amd64
251+
252+ docker manifest push ${IMAGE}:${VERSION}
0 commit comments