From c943d3970b0bfa55ad96680d66c394c5609aa58d Mon Sep 17 00:00:00 2001 From: Jari Hodju <81552680+jari-hodju@users.noreply.github.com> Date: Tue, 10 Oct 2023 13:29:06 +0300 Subject: [PATCH] Multi-arch build (#42) * Multi-arch build - re-branched from main due to long list of merge conflicts - additions and changes from feat-multiarch - sdk and base image upgrades - github actions upgrades - for general info on multi-arch builds, see https://github.com/tiiuae/fog-ros-baseimage/blob/main/docs/Multiarchitecture_builds.md * Update baseimage version to v3.0.0 release * Upgrade baseimage version to v3.0.1 --------- Co-authored-by: Mehmet Killioglu --- .github/workflows/tii-mocap-pose.yaml | 47 ++++++++++++++------------- Dockerfile | 34 ++++++++++--------- entrypoint.sh | 2 +- 3 files changed, 44 insertions(+), 39 deletions(-) diff --git a/.github/workflows/tii-mocap-pose.yaml b/.github/workflows/tii-mocap-pose.yaml index d16568f..2e4832a 100644 --- a/.github/workflows/tii-mocap-pose.yaml +++ b/.github/workflows/tii-mocap-pose.yaml @@ -1,56 +1,59 @@ name: tii-mocap-pose on: + push: + paths-ignore: + - 'README.md' + - 'CHANGELOG.rst' + pull_request: repository_dispatch: types: [fog-ros-baseimage-update] - push: workflow_dispatch: jobs: build: + name: Build & push runs-on: ubuntu-latest + permissions: + contents: read + packages: write steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: recursive - - uses: docker/setup-buildx-action@v2 - - - name: Set image tag format without suffix - run: | - echo "IMAGE_TAG_FORMAT=type=sha" >> $GITHUB_ENV - if: github.event_name == 'push' + - name: Setup QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: amd64,riscv64,arm64 - - name: Set image tag format with suffix - # it is possible that run_number should be used instead run_attempt - # run_attempt is unique number on every run and run_attempt resets to 1 if re-build is not used - # content of image_sha_tag_suffix is defined in fog-ros-baseimage dispatcher workflow. - run: | - echo "IMAGE_TAG_FORMAT=type=sha,suffix=-${{ github.event.client_payload.image_sha_tag_suffix }}" >> $GITHUB_ENV - if: github.event_name == 'repository_dispatch' + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - name: Docker meta id: meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@v5 with: images: ghcr.io/tiiuae/tii-mocap-pose tags: | type=ref,event=branch + type=ref,event=pr type=semver,pattern={{version}} - type=raw,value=latest - ${{ env.IMAGE_TAG_FORMAT }} + type=sha + type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }} - name: Login to GitHub Container Registry - uses: docker/login-action@v2 + 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@v4 + - name: Build image and push + uses: docker/build-push-action@v5 with: context: . + platforms: linux/amd64,linux/riscv64,linux/arm64 push: true tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index a372bea..242cb51 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,28 @@ -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:v3.0.1-${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/mocap_pose -RUN /packaging/build.sh +# Tar directories so they are easier to handle when doing installation. +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 - -HEALTHCHECK --interval=5s \ - CMD fog-health check --metric=location_update_count --diff-gte=5.0 \ - --metrics-from=http://localhost:${METRICS_PORT}/metrics --only-if-nonempty=${METRICS_PORT} +FROM ghcr.io/tiiuae/fog-ros-baseimage:v3.0.1 ENTRYPOINT [ "/entrypoint.sh" ] COPY entrypoint.sh /entrypoint.sh -COPY --from=builder /main_ws/ros-*-mocap-pose_*_amd64.deb /mocap-pose.deb +# WORKSPACE_DIR environment variable is defined in the fog-ros-baseimage. +# The same installation directory is used by all ROS2 components. +# See: https://github.com/tiiuae/fog-ros-baseimage/blob/main/Dockerfile +WORKDIR $WORKSPACE_DIR -RUN dpkg -i /mocap-pose.deb && rm /mocap-pose.deb +COPY --from=builder $WORKSPACE_DIR/install install diff --git a/entrypoint.sh b/entrypoint.sh index ebdca2b..d187dfd 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -4,7 +4,7 @@ _term() { # FILL UP PROCESS SEARCH PATTERN HERE TO FIND PROPER PROCESS FOR SIGINT: pattern="mocap_pose/mocap_pose_node" - pid_value="$(ps -ax | grep $pattern | grep -v grep | awk '{ print $1 }')" + pid_value="$(ps -e | grep $pattern | grep -v grep | awk '{ print $1 }')" if [ "$pid_value" != "" ]; then pid=$pid_value echo "Send SIGINT to pid $pid"