Skip to content

Commit

Permalink
Multi-arch build (#42)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
jari-hodju and mehmetkillioglu authored Oct 10, 2023
1 parent 794862a commit c943d39
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 39 deletions.
47 changes: 25 additions & 22 deletions .github/workflows/tii-mocap-pose.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
34 changes: 18 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit c943d39

Please sign in to comment.