From 865c8b976d071d79fc909d6b97f5dbfad1d4906d Mon Sep 17 00:00:00 2001 From: Jari Hodju Date: Thu, 21 Sep 2023 11:59:13 +0300 Subject: [PATCH] Multiarch build - Re-branched from master (due to long list of merge conflicts) - Building using the Dockerfile and workflow action from feat-multiarch branch - Upgraded SDK and run-time images to latest - Upgraded action components --- .github/workflows/tii-microxrce-agent.yaml | 43 ++++++++++++++------ Dockerfile | 46 ++++++++++++++-------- 2 files changed, 61 insertions(+), 28 deletions(-) diff --git a/.github/workflows/tii-microxrce-agent.yaml b/.github/workflows/tii-microxrce-agent.yaml index 7e1b8d43..a5467497 100644 --- a/.github/workflows/tii-microxrce-agent.yaml +++ b/.github/workflows/tii-microxrce-agent.yaml @@ -1,21 +1,32 @@ -name: tii-microxrce-agent +name: Build on: + push: + paths-ignore: + - 'README.md' + - 'CHANGELOG.md' + pull_request: + branches: [ "main" ] repository_dispatch: types: [fog-ros-baseimage-update] - push: workflow_dispatch: +permissions: + contents: read + packages: write + jobs: build: + name: 🔨 runs-on: ubuntu-latest - permissions: - contents: read - packages: write steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: docker/setup-buildx-action@v1 + - name: Set short git commit SHA + id: vars + run: | + calculatedSha=$(git rev-parse --short ${{ github.sha }}) + echo "SHORT_GIT_SHA=$calculatedSha" >> $GITHUB_OUTPUT - name: Set image tag format without suffix run: | @@ -32,7 +43,7 @@ jobs: - name: Docker meta id: meta - uses: docker/metadata-action@v3 + uses: docker/metadata-action@v5 with: images: ghcr.io/tiiuae/tii-microxrce-agent tags: | @@ -43,17 +54,25 @@ jobs: type=raw,value=latest ${{ env.IMAGE_TAG_FORMAT }} + - name: Setup QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: riscv64,arm64 + + - uses: docker/setup-buildx-action@v3 + - name: Login to GitHub Container Registry - uses: docker/login-action@v1 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build container image and push - uses: docker/build-push-action@v2 + - name: Build image and push + uses: docker/build-push-action@v5 with: - context: . + context: ./ + platforms: linux/amd64,linux/riscv64,linux/arm64 push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 34d7d64c..9f085e7d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,31 +1,45 @@ -FROM ghcr.io/tiiuae/fog-ros-baseimage-builder:v2.1.0 AS builder +# Given dynamically from CI job. +FROM --platform=${BUILDPLATFORM:-linux/amd64} ghcr.io/tiiuae/fog-ros-sdk:sha-6d67ecf-${TARGETARCH:-amd64} AS builder -COPY . /main_ws/src/ +# Must be defined another time after "FROM" keyword. +ARG TARGETARCH -# this: -# 1) builds the application -# 2) packages the application as .deb in /main_ws/ +# SRC_DIR environment variable is defined in the fog-ros-sdk image. +# The same workspace path is used by all ROS2 components. +# See: https://github.com/tiiuae/fog-ros-baseimage/blob/main/Dockerfile.sdk_builder +COPY . $SRC_DIR/microxrcedds_agent -RUN /packaging/build.sh +RUN /packaging/build_colcon_sdk.sh ${TARGETARCH:-amd64} +# Even though it is possible to tar the install directory for retrieving it later in runtime image, +# the tar extraction in arm64 emulated on arm64 is still slow. So, we copy the install directory instead # ▲ runtime ──┐ # └── build ▼ -FROM ghcr.io/tiiuae/fog-ros-baseimage:v2.1.0 +FROM ghcr.io/tiiuae/fog-ros-baseimage:sha-6d67ecf + +ENTRYPOINT [ "/entrypoint.sh" ] HEALTHCHECK --interval=5s \ CMD fog-health check --metric=messages_from_flightcontroller_count --diff-gte=1.0 \ --metrics-from=http://localhost:${METRICS_PORT}/metrics --only-if-nonempty=${METRICS_PORT} -RUN apt-get update && apt-get install -y python3-pip && \ - pip3 install simplejson pystache +RUN apt update \ + && apt install -y \ + prometheus-cpp \ + civetweb-cpp \ + && rm -rf /var/lib/apt/lists/* \ + && pip3 install simplejson pystache + +RUN mkdir -p /usr/local/lib \ + && mkdir -p /usr/local/bin -ENTRYPOINT /entrypoint.sh -COPY entrypoint.sh /entrypoint.sh -COPY parse_agent_refs.py /parse_agent_refs.py -COPY agent.refs.mustache /agent.refs.mustache -COPY agent.refs /agent.refs +COPY --from=builder /main_ws/install/bin/MicroXRCEAgent /usr/local/bin +COPY --from=builder /main_ws/install/lib/libmicroxrcedds_agent.so.2.2.0 /usr/local/lib +RUN ln -s /usr/local/lib/libmicroxrcedds_agent.so.2.2.0 /usr/local/lib/libmicroxrcedds_agent.so.2.2 \ + && ln -s /usr/local/lib/libmicroxrcedds_agent.so.2.2 /usr/local/lib/libmicroxrcedds_agent.so -COPY --from=builder /main_ws/ros-*-microxrce-agent_*_amd64.deb /microxrce-agent.deb -RUN dpkg -i /microxrce-agent.deb && rm /microxrce-agent.deb +ENV PATH="/usr/local/bin:$PATH" \ + LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH" +COPY entrypoint.sh parse_agent_refs.py agent.refs.mustache agent.refs / \ No newline at end of file