Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable multiarch build, publish debs as container #22

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
################################################################################
# Repo

.circleci/
.github/
.vscode/
.dockerignore
.gitignore
**Dockerfile
**.Dockerfile
Dockerfile.**
Dockerfile
bin
build_deb.sh
build.sh
3 changes: 3 additions & 0 deletions .github/buildkitd.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# .github/buildkitd.toml
[worker.oci]
max-parallelism = 1
146 changes: 94 additions & 52 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,65 +5,107 @@ on:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

permissions:
contents: read
packages: write


jobs:
tii-px4-msgs-deb:
build-and-push:
runs-on: ubuntu-latest

outputs:
short_git_sha: ${{ steps.vars.outputs.SHORT_GIT_SHA }}
short_git_version_string: ${{ steps.vars.outputs.SHORT_GIT_VERSION_STRING }}
steps:
- name: Checkout PX4-msgs
uses: actions/checkout@v2
with:
path: PX4-msgs
- name: Run px4-msgs docker build
- name: Checkout code
uses: actions/checkout@v4

- name: Set short git commit SHA
id: vars
run: |
set -eux
mkdir bin
pushd PX4-msgs
./build.sh ../bin/
popd
- name: Upload build
uses: actions/upload-artifact@v2
calculatedSha=$(git rev-parse --short ${{ github.sha }})
calculatedGitVersionString=$(git log --date=format:%Y%m%d --pretty=~git%cd.%h -n 1)
echo "SHORT_GIT_SHA=$calculatedSha" >> $GITHUB_OUTPUT
echo "SHORT_GIT_VERSION_STRING=$calculatedGitVersionString" >> $GITHUB_OUTPUT

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
name: px4_msgs
path: bin/*.deb
retention-days: 1
platforms: amd64,arm64

artifactory:
runs-on: ubuntu-latest
needs: tii-px4-msgs-deb
if: github.event_name == 'push'
steps:
- name: Download builds
uses: actions/download-artifact@v2
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
with:
config: .github/buildkitd.toml

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
name: px4_msgs
path: bin
- uses: jfrog/setup-jfrog-cli@v2
env:
JF_ARTIFACTORY_1: ${{ secrets.JFROG_EU_SAAS_TOKEN }}
- name: Upload to Artifactory
env:
ARTIFACTORY_REPO: ssrc-deb-public-local
DISTRIBUTION: jammy
COMPONENT: fog-sw
ARCHITECTURE: amd64
BUILD_NAME: px4-msgs
CI: true
if: github.event_name == 'push'
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Container metadata for tii-px4-msgs
id: meta # referenced from later step
uses: docker/metadata-action@v5
with:
images: ghcr.io/tiiuae/tii-px4-msgs
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{raw}}
type=sha
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}

- name: Build and push debian package container
uses: docker/build-push-action@v5
with:
push: true
context: .
file: ./Dockerfile
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
build-args: |
PACKAGE_NAME=px4-msgs
GIT_RUN_NUMBER=${{ github.run_number }}
GIT_COMMIT_HASH=${{ github.sha }}
GIT_VERSION_STRING=${{ steps.vars.outputs.SHORT_GIT_VERSION_STRING }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# Needed because we have to create a manifest list in the next job.
provenance: mode=min

- name: Create container and copy deb packages
run: |
set -exu
jfrog rt ping
for pkg in bin/*.deb
do
pkg_name=$(basename $pkg)
jfrog rt u --deb "$DISTRIBUTION/$COMPONENT/$ARCHITECTURE" \
--target-props COMMIT="$GITHUB_SHA" \
--build-name "$BUILD_NAME" \
--build-number "$GITHUB_SHA" \
"$pkg" \
"$ARTIFACTORY_REPO/$pkg_name"
platforms=("amd64" "arm64")
for platform in "${platforms[@]}"; do
docker create -ti --name "px4-msgs-build-temp-$platform" --platform=linux/$platform $(echo "${{ steps.meta.outputs.tags }}" | head -1) bash
docker cp "px4-msgs-build-temp-$platform:/artifacts/." ./output_dir
docker rm "px4-msgs-build-temp-$platform"
done
jfrog rt build-publish "$BUILD_NAME" "$GITHUB_SHA"
jfrog rt bpr "$BUILD_NAME" "$GITHUB_SHA" "$ARTIFACTORY_REPO" \
--status dev \
--comment "development build"

- name: Upload .deb packages as artifact
uses: actions/upload-artifact@v4
with:
name: deb-packages
path: ./output_dir/*.deb

# upload-to-digitalocean:
# runs-on: ubuntu-latest
# needs: build-and-push
# # if: github.event_name == 'push' && github.ref_name == github.event.repository.default_branch
# steps:
# - name: Download .deb package artifact
# uses: actions/download-artifact@v4
# with:
# name: deb-packages

# - name: Upload to digitalocean
# run: |
# echo "Placeholder"
# ls -R
23 changes: 19 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
FROM ghcr.io/tiiuae/fog-ros-baseimage-builder:v2.1.0
FROM ros:humble-ros-base as builder

ARG GIT_RUN_NUMBER
ARG GIT_COMMIT_HASH
ARG GIT_VERSION_STRING

RUN echo $GIT_RUN_NUMBER
RUN echo $GIT_COMMIT_HASH
RUN echo $GIT_VERSION_STRING
ARG BUILD_NUMBER=0
RUN apt-get update -y && apt-get install -y --no-install-recommends \
curl \
python3-bloom \
dh-make \
libboost-dev

COPY . /main_ws/src/

# this:
# 1) builds the application
# 2) packages the application as .deb in /main_ws/
WORKDIR /main_ws/src
RUN /main_ws/src/package.sh -b $GIT_RUN_NUMBER -g $GIT_COMMIT_HASH -v $GIT_VERSION_STRING

RUN /packaging/build.sh -b ${BUILD_NUMBER}
RUN mkdir -p /output_dir && cp /main_ws/*.deb /output_dir/

RUN mkdir -p /output_dir
RUN cp /main_ws/ros-*-px4-msgs_*_amd64.deb /output_dir/
FROM alpine:edge
COPY --from=builder /output_dir/*.deb /artifacts/
CMD ["sh"]
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@

This package contains the ROS2 message definitions of the [PX4 Pro ecosystem](https://px4.io/). Building this package generates all the required interfaces to interface ROS2 nodes with the PX4 autopilot internals, which use the [uORB messaging API](https://dev.px4.io/en/middleware/uorb.html). Currently the messages of this package represent a dependency to [`px4_ros_com` package](https://github.com/PX4/px4_ros_com).


### Copy the deb packages to your local directory
```bash
docker create --name px4-msgs-artifacts ghcr.io/tiiuae/tiiuae/tii-px4-msgs:main
mkdir -p /tmp/px4_msgs_debs/bin
docker cp px4-msgs-artifacts:/artifacts/. /tmp/px4_msgs_debs/bin/
docker rm px4-msgs-artifacts
ls -la /tmp/px4_msgs_debs/bin
```

### Copy and install deb packages in Dockerfile
Modify the tag name accordingly. The baseimage is given as an example, could be used any that has the ros2 installed. If the ROS2 installation is done later, install the deb packages after the ROS2 installation.
```Dockerfile
FROM ros:humble-ros-base

RUN mkdir -p /tmp/px4_msgs_debs
COPY --from=ghcr.io/tiiuae/tii-px4-msgs:main /artifacts/*.deb /tmp/px4_msgs_debs/
RUN dpkg -i /tmp/px4_msgs_debs/*.deb && rm -rf /tmp/px4_msgs_debs
```

## uORB message definitions

The uORB message definitions, which represent the counter-part of the ROS2 messages found in this package, can be found on the [PX4 Firmware repository](https://github.com/PX4/Firmware).
Expand Down
43 changes: 37 additions & 6 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,46 @@
set -euxo pipefail

output_dir=$1

git_commit_hash=${2:-$(git rev-parse HEAD)}

git_version_string=${3:-$(git log --date=format:%Y%m%d --pretty=~git%cd.%h -n 1)}

build_number=${GITHUB_RUN_NUMBER:=0}

ros_distro=${ROS_DISTRO:=humble}

iname=${PACKAGE_NAME:=px4-msgs}

iversion=${PACKAGE_VERSION:=latest}

target_platforms=${PLATFORMS:=linux/amd64,linux/arm64}

docker build \
--build-arg BUILD_NUMBER=${build_number} \
--output type=docker \
-t "tii-px4-msgs:px4-msgs" .
--build-arg UID=$(id -u) \
--build-arg GID=$(id -g) \
--build-arg ROS_DISTRO=${ros_distro} \
--build-arg PACKAGE_NAME=${iname} \
--build-arg GIT_RUN_NUMBER=${build_number} \
--build-arg GIT_COMMIT_HASH=${git_commit_hash} \
--build-arg GIT_VERSION_STRING=${git_version_string} \
--build-arg TARGET_ARCHITECTURE=amd64 \
--platform=${target_platforms} \
--progress=plain \
--output=type=registry \
--pull \
-f Dockerfile -t "localhost:5000/${iname}-build:${iversion}" .

mkdir -p ${output_dir}

IFS=',' read -ra platforms <<< "$target_platforms"
for platform in "${platforms[@]}"; do
docker create -ti --name ${iname}-build-temp-${platform//\//-} localhost:5000/${iname}-build:latest bash
docker cp ${iname}-build-temp-${platform//\//-}:/output_dir/. ${output_dir}
docker rm -f ${iname}-build-temp-${platform//\//-}
done


container_id=$(docker create tii-px4-msgs:px4-msgs)
docker cp ${container_id}:/output_dir/. ${output_dir}
docker rm -v ${container_id}
echo "Build completed successfully. Extracted deb package name $(ls ${output_dir}/*.deb)"

exit 0
Loading
Loading