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

Multi-arch build #42

Merged
merged 3 commits into from
Oct 10, 2023
Merged
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
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 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Health checks were removed with this commit.

I noticed from Marita's shared logs:

🟨 $hypervisor.mocap-pose | no health check specified

http://100.117.239.56/logs/2023-10-23_10_46-back-12m0s-ghaf/health.txt

I guess this is an accidental regression and not on purpose.

--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
Loading