From 1d34bead4d596ce3068f5934c9947aa251709dbe Mon Sep 17 00:00:00 2001 From: Dogan Ulus Date: Wed, 5 Feb 2025 12:10:33 +0300 Subject: [PATCH] Add Asam OSI container --- .github/workflows/buildah-build-asam-osi.yml | 125 ++++++++++++++++++ .../buildah-build-openscenegraph.yml | 6 +- containers/Makefile | 14 ++ containers/esmini-asam-osi/Dockerfile | 43 ++++++ .../scripts/asam-osi-install.sh | 32 +++++ .../scripts/protobuf-install.sh | 41 ++++++ 6 files changed, 258 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/buildah-build-asam-osi.yml create mode 100644 containers/esmini-asam-osi/Dockerfile create mode 100644 containers/esmini-asam-osi/scripts/asam-osi-install.sh create mode 100644 containers/esmini-asam-osi/scripts/protobuf-install.sh diff --git a/.github/workflows/buildah-build-asam-osi.yml b/.github/workflows/buildah-build-asam-osi.yml new file mode 100644 index 0000000..cb3cf34 --- /dev/null +++ b/.github/workflows/buildah-build-asam-osi.yml @@ -0,0 +1,125 @@ +name: buildah-build-asam-osi +on: + workflow_dispatch: + push: + paths: + - containers/esmini-asam-osi/** + - .github/workflows/buildah-build-asam-osi.yml # Self-trigger + +env: + REGISTRY: ghcr.io/bounverif + IMAGE_NAME: esmini + PODMAN_ARCH: amd64 + PLATFORM: linux-amd64 + ESMINI_BUILD_OSI_VERSION: 3.5.0 + ESMINI_BUILD_OSI_VERSION_LATEST: 3.7.0 + ESMINI_BUILD_PROTOBUF_VERSION: 3.15.8 + ESMINI_BUILD_PROTOBUF_VERSION_LATEST: 5.29.0 + +permissions: + contents: read + packages: write + +jobs: + buildah-build: + name: Build container images + strategy: + fail-fast: false + matrix: + os: [ubuntu-24.04, ubuntu-24.04-arm] + runs-on: ${{ matrix.os }} + concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os }} + cancel-in-progress: true + + steps: + - name: Install container tools + run: sudo apt-get install podman buildah jq + + - name: Prepare environment variables + run: | + echo "PODMAN_ARCH=$(podman info --format='{{.Host.Arch}}')" >> $GITHUB_ENV + echo "PLATFORM=$(podman info --format='{{.Version.OsArch}}' | sed 's/\//-/g')" >> $GITHUB_ENV + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the GitHub Container registry + uses: redhat-actions/podman-login@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build OpenSimulationInterface container image + id: build-asam-osi + uses: redhat-actions/buildah-build@v2 + with: + context: ./containers/esmini-asam-osi + image: ${{ env.IMAGE_NAME }} + tags: ${{ env.ESMINI_BUILD_OSI_VERSION }}-asam-osi ${{ env.ESMINI_BUILD_OSI_VERSION }}-asam-osi-${{ env.PODMAN_ARCH }} + layers: true + oci: true + build-args: | + ESMINI_IMAGE_NAME=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + ESMINI_BUILD_OSI_VERSION=${{ env.ESMINI_BUILD_OSI_VERSION }} + ESMINI_BUILD_PROTOBUF_VERSION=${{ env.ESMINI_BUILD_PROTOBUF_VERSION }} + extra-args: | + --target esmini-asam-osi + containerfiles: | + ./containers/esmini-saosi/Dockerfile + + - name: Push to GitHub Container Repository + if: github.ref == 'refs/heads/main' + id: push-asam-osi-ghcr + uses: redhat-actions/push-to-registry@v2 + with: + registry: ${{ env.REGISTRY }} + image: ${{ steps.build-asam-osi.outputs.image }} + tags: ${{ env.ESMINI_BUILD_OSI_VERSION }}-asam-osi-${{ env.PODMAN_ARCH }} + digestfile: ${{ runner.temp }}/digest-esmini-asam-osi-${{ env.PLATFORM }} + + - name: Upload digests + if: github.ref == 'refs/heads/main' + uses: actions/upload-artifact@v4 + with: + name: digest-esmini-${{ env.ESMINI_BUILD_OSI_VERSION }}-${{ env.PLATFORM }} + path: ${{ runner.temp }}/digest-* + if-no-files-found: error + retention-days: 1 + compression-level: 0 # no compression + + buildah-merge: + name: Merge container images + runs-on: ubuntu-24.04 + needs: buildah-build + if: github.ref == 'refs/heads/main' && always() + steps: + # - run: mkdir -p $TMPDIR + - name: Download digests + uses: actions/download-artifact@v4 + with: + path: ${{ runner.temp }}/digests + pattern: digest-* + merge-multiple: true + + - name: Log in to the GitHub Container registry + uses: redhat-actions/podman-login@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Create and push manifest list for osi + run: | + MANIFEST=esmini-asam-osi + FULL_IMAGE_NAME=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + buildah manifest create $MANIFEST + for digest in ${{ runner.temp }}/digests/digest-esmini-*; do + echo "Adding $(cat $digest)" + buildah manifest add $MANIFEST $FULL_IMAGE_NAME@$(cat $digest) + done + buildah manifest push --all $MANIFEST docker://$FULL_IMAGE_NAME:${{ env.ESMINI_BUILD_OSI_VERSION }}-asam-osi + if [ "${{ env.ESMINI_BUILD_OSI_VERSION }}" == "${{ env.ESMINI_BUILD_OSI_VERSION_LATEST }}" ]; then + buildah manifest push --all $MANIFEST docker://$FULL_IMAGE_NAME:latest-asam-osi + fi diff --git a/.github/workflows/buildah-build-openscenegraph.yml b/.github/workflows/buildah-build-openscenegraph.yml index 2a55e9a..9c54fbe 100644 --- a/.github/workflows/buildah-build-openscenegraph.yml +++ b/.github/workflows/buildah-build-openscenegraph.yml @@ -3,8 +3,8 @@ on: workflow_dispatch: push: paths: + - containers/esmini-openscenegraph/** - .github/workflows/buildah-build-openscenegraph.yml # Self-trigger - - containers/esmini-openscenegraph/Dockerfile env: REGISTRY: ghcr.io/bounverif @@ -12,7 +12,7 @@ env: PODMAN_ARCH: amd64 PLATFORM: linux-amd64 ESMINI_BUILD_OSG_VERSION: 3.6.5 - ESMINI_BUILD_OSG_LATEST_VERSION: 3.6.5 + ESMINI_BUILD_OSG_VERSION_LATEST: 3.6.5 permissions: contents: read @@ -117,6 +117,6 @@ jobs: buildah manifest add $MANIFEST $FULL_IMAGE_NAME@$(cat $digest) done buildah manifest push --all $MANIFEST docker://$FULL_IMAGE_NAME:${{ env.ESMINI_BUILD_OSG_VERSION }}-openscenegraph - if [ "${{ env.ESMINI_BUILD_OSG_VERSION }}" == "${{ env.ESMINI_BUILD_OSG_LATEST_VERSION }}" ]; then + if [ "${{ env.ESMINI_BUILD_OSG_VERSION }}" == "${{ env.ESMINI_BUILD_OSG_VERSION_LATEST }}" ]; then buildah manifest push --all $MANIFEST docker://$FULL_IMAGE_NAME:latest-openscenegraph fi diff --git a/containers/Makefile b/containers/Makefile index 547f843..a919b3f 100644 --- a/containers/Makefile +++ b/containers/Makefile @@ -4,6 +4,9 @@ ESMINI_CURRENT_VERSION := $(if $(filter latest,$(ESMINI_VERSION)),$(shell curl - CONTAINER_BUILD_CONTEXT ?= . CONTAINER_CACHE_TTL=24h +ESMINI_BUILD_ASAM_OSI_VERSION ?= 3.5.0 +ESMINI_BUILD_PROTOBUF_VERSION ?= 3.15.8 + info: @echo "esmini version: ${ESMINI_VERSION}" @echo "esmini current version: ${ESMINI_CURRENT_VERSION}" @@ -19,6 +22,17 @@ openscenegraph: --tag ${ESMINI_IMAGE_NAME}:latest-openscenegraph \ ${CONTAINER_BUILD_CONTEXT}/esmini-openscenegraph +asam-osi: + buildah build \ + -f esmini-asam-osi/Dockerfile \ + --build-arg ESMINI_BUILD_ASAM_OSI_VERSION=${ESMINI_BUILD_ASAM_OSI_VERSION} \ + --format oci \ + --layers=true \ + --target esmini-asam-osi \ + --tag ${ESMINI_IMAGE_NAME}:${ESMINI_BUILD_ASAM_OSI_VERSION}-asam-osi \ + --tag ${ESMINI_IMAGE_NAME}:latest-asam-osi \ + ${CONTAINER_BUILD_CONTEXT}/esmini-asam-osi + builder: buildah build \ -f esmini-builder/Dockerfile \ diff --git a/containers/esmini-asam-osi/Dockerfile b/containers/esmini-asam-osi/Dockerfile new file mode 100644 index 0000000..8f07fbf --- /dev/null +++ b/containers/esmini-asam-osi/Dockerfile @@ -0,0 +1,43 @@ +ARG ESMINI_BASE_IMAGE=docker.io/library/ubuntu +ARG ESMINI_BASE_IMAGE_VERSION=24.04 +ARG ESMINI_BUILD_PROTOBUF_VERSION=3.15.8 +ARG ESMINI_BUILD_ASAM_OSI_VERSION=3.5.0 + +FROM ${ESMINI_BASE_IMAGE}:${ESMINI_BASE_IMAGE_VERSION} AS esmini-asam-osi +ARG TARGETARCH TARGETOS TARGETPLATFORM TARGETVARIANT + +# Install predependencies +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=${TARGETPLATFORM}/var/cache/apt \ + export DEBIAN_FRONTEND=noninteractive && \ + apt-get update -qq && \ + apt-get install -qy --no-install-recommends \ + sudo \ + curl \ + wget \ + git \ + jq \ + gnupg2 \ + ca-certificates \ + build-essential \ + cmake \ + python3-minimal \ + python3-pip \ + pipx \ + python-is-python3 \ + && \ + apt-get autoremove -y && rm -rf /var/lib/apt/lists/* && \ + printf "ubuntu ALL= NOPASSWD: ALL\\n" > /etc/sudoers.d/ubuntu + +# Install some python utilities +RUN python3 -m pip config set global.break-system-packages true && \ + PIPX_HOME=/opt/pipx PIPX_BIN_DIR=/usr/local/bin pipx install semver + +ARG ESMINI_BUILD_PROTOBUF_VERSION +ENV ESMINI_BUILD_PROTOBUF_VERSION=${ESMINI_BUILD_PROTOBUF_VERSION} +COPY --chmod=755 scripts/protobuf-install.sh /usr/local/bin/protobuf-install.sh +RUN /usr/local/bin/protobuf-install.sh + +ARG ESMINI_BUILD_ASAM_OSI_VERSION +ENV ESMINI_BUILD_ASAM_OSI_VERSION=${ESMINI_BUILD_ASAM_OSI_VERSION} +COPY --chmod=755 scripts/asam-osi-install.sh /usr/local/bin/asam-osi-install.sh +RUN /usr/local/bin/asam-osi-install.sh diff --git a/containers/esmini-asam-osi/scripts/asam-osi-install.sh b/containers/esmini-asam-osi/scripts/asam-osi-install.sh new file mode 100644 index 0000000..051272c --- /dev/null +++ b/containers/esmini-asam-osi/scripts/asam-osi-install.sh @@ -0,0 +1,32 @@ +#!/bin/sh -e +# +# Example Usage: +# ESMINI_BUILD_INSTALL_PREFIX=~/pb ESMINI_BUILD_ASAM_OSI_VERSION=3.15.2 protobuf-install.sh + +ESMINI_INSTALL_PREFIX=${ESMINI_INSTALL_PREFIX:-/usr/local} +ESMINI_BUILD_INSTALL_PREFIX=${ESMINI_BUILD_INSTALL_PREFIX:-${ESMINI_INSTALL_PREFIX}} +ESMINI_BUILD_OSI_SOURCE_DIR="/tmp/osi3" +ESMINI_BUILD_OSI_BUILD_DIR=${ESMINI_BUILD_OSI_SOURCE_DIR}/build + +ESMINI_BUILD_OSI_SOURCE_REPOSITORY_URL="https://github.com/OpenSimulationInterface/open-simulation-interface" +ESMINI_BUILD_ASAM_OSI_VERSION=${ESMINI_BUILD_ASAM_OSI_VERSION:-3.7.0} + +git clone "${ESMINI_BUILD_OSI_SOURCE_REPOSITORY_URL}" ${ESMINI_BUILD_OSI_SOURCE_DIR} \ + --depth 1 \ + --branch "v${ESMINI_BUILD_ASAM_OSI_VERSION}" \ + --recurse-submodules +cmake \ + -S ${ESMINI_BUILD_OSI_SOURCE_DIR} \ + -B ${ESMINI_BUILD_OSI_BUILD_DIR} \ + -DBUILD_SHARED_LIBS="${ESMINI_BUILD_OSI_BUILD_SHARED_LIBS}" \ + -DOSI_BUILD_FLATBUFFER=OFF \ + -DOSI_BUILD_DOCUMENTATION=OFF \ + -DOSI_INSTALL_LIB_DIR="${ESMINI_BUILD_INSTALL_PREFIX}\lib" \ + -DOSI_INSTALL_INCLUDE_DIR="${ESMINI_BUILD_INSTALL_PREFIX}\include" \ + -DCMAKE_INSTALL_PREFIX="${ESMINI_BUILD_INSTALL_PREFIX}" + +mkdir -p "${ESMINI_BUILD_INSTALL_PREFIX}" +cmake --build ${ESMINI_BUILD_OSI_BUILD_DIR} --target install + +# Cleanup +rm -rf ${ESMINI_BUILD_OSI_SOURCE_DIR} ${ESMINI_BUILD_OSI_BUILD_DIR} \ No newline at end of file diff --git a/containers/esmini-asam-osi/scripts/protobuf-install.sh b/containers/esmini-asam-osi/scripts/protobuf-install.sh new file mode 100644 index 0000000..52c6557 --- /dev/null +++ b/containers/esmini-asam-osi/scripts/protobuf-install.sh @@ -0,0 +1,41 @@ +#!/bin/sh -e +# +# Example Usage: +# ESMINI_BUILD_INSTALL_PREFIX=~/pb ESMINI_BUILD_PROTOBUF_VERSION=3.15.2 protobuf-install.sh + +ESMINI_INSTALL_PREFIX=${ESMINI_INSTALL_PREFIX:-/usr/local} +ESMINI_BUILD_INSTALL_PREFIX=${ESMINI_BUILD_INSTALL_PREFIX:-${ESMINI_INSTALL_PREFIX}} +ESMINI_BUILD_PROTOBUF_VERSION=${ESMINI_BUILD_PROTOBUF_VERSION:-3.21.12} +ESMINI_BUILD_PROTOBUF_SOURCE_DIR="/tmp/protobuf" +ESMINI_BUILD_PROTOBUF_BUILD_DIR="/tmp/build/protobuf" +ESMINI_BUILD_PROTOBUF_BUILD_SHARED_LIBS="OFF" +ESMINI_BUILD_PROTOBUF_WITH_ZLIB="ON" +ESMINI_BUILD_PROTOBUF_INSTALL="ON" + +ESMINI_BUILD_PROTOBUF_SOURCE_REPOSITORY_URL="https://github.com/protocolbuffers/protobuf" + +# CMakeLists.txt moved from the cmake directory to the top-level in v3.21 +_PROTOBUF_SOURCE_CMAKELISTS_DIR="" +if dpkg --compare-versions "${ESMINI_BUILD_PROTOBUF_VERSION}" "lt" "3.21"; then + _PROTOBUF_SOURCE_CMAKELISTS_DIR="cmake" +fi + +git clone "${ESMINI_BUILD_PROTOBUF_SOURCE_REPOSITORY_URL}" ${ESMINI_BUILD_PROTOBUF_SOURCE_DIR} \ + --depth 1 \ + --branch "v${ESMINI_BUILD_PROTOBUF_VERSION}" \ + --recurse-submodules +cmake \ + -S ${ESMINI_BUILD_PROTOBUF_SOURCE_DIR}/${_PROTOBUF_SOURCE_CMAKELISTS_DIR} \ + -B ${ESMINI_BUILD_PROTOBUF_BUILD_DIR} \ + -DBUILD_SHARED_LIBS="${ESMINI_BUILD_PROTOBUF_BUILD_SHARED_LIBS}" \ + -Dprotobuf_WITH_ZLIB="${ESMINI_BUILD_PROTOBUF_WITH_ZLIB}" \ + -Dprotobuf_BUILD_TESTS=OFF \ + -Dprotobuf_BUILD_EXAMPLES=OFF \ + -Dprotobuf_INSTALL="${ESMINI_BUILD_PROTOBUF_INSTALL}" \ + -DCMAKE_INSTALL_PREFIX="${ESMINI_BUILD_INSTALL_PREFIX}" \ + -DCMAKE_POSITION_INDEPENDENT_CODE=ON +mkdir -p "${ESMINI_BUILD_INSTALL_PREFIX}" +cmake --build ${ESMINI_BUILD_PROTOBUF_BUILD_DIR} --target install + +# Cleanup +rm -rf ${ESMINI_BUILD_PROTOBUF_SOURCE_DIR} ${ESMINI_BUILD_PROTOBUF_BUILD_DIR} \ No newline at end of file