Skip to content

Commit

Permalink
Multiarch build
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
jari-hodju committed Sep 21, 2023
1 parent 8ec812b commit 865c8b9
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 28 deletions.
43 changes: 31 additions & 12 deletions .github/workflows/tii-microxrce-agent.yaml
Original file line number Diff line number Diff line change
@@ -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: |
Expand All @@ -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: |
Expand All @@ -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 }}
46 changes: 30 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 /

0 comments on commit 865c8b9

Please sign in to comment.