From e6f3c7d0c6372982d8612d8390aad229895030c5 Mon Sep 17 00:00:00 2001 From: Giles Knap Date: Wed, 6 Mar 2024 13:39:05 +0000 Subject: [PATCH] restructure for crosscompilation --- .dockerignore | 1 + .github/workflows/build.yml | 41 ++++++++++++++----- Dockerfile | 80 +++++++++---------------------------- epics/scripts/get-base.sh | 14 +++++++ requirements.txt | 2 +- 5 files changed, 65 insertions(+), 73 deletions(-) create mode 100644 epics/scripts/get-base.sh diff --git a/.dockerignore b/.dockerignore index 164ac63..1c9e50a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -6,3 +6,4 @@ LICENSE .github .vscode .devcontainer.json +Dockerfile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9a5278f..78c0d92 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,14 +15,30 @@ jobs: fail-fast: false matrix: target: [developer, runtime] - architecture: [linux, rtems] + base_image: [ubuntu:22.04] include: - - os: ubuntu-latest - platforms: linux/amd64 + - epics-target: RTEMS-beatnik + epics-host: linux-x86_64 + image_name: rtems-beatnik + base_image: ghcr.io/epics-containers/rtems6-powerpc-linux-runtime:6.2rc1ec1 + os: ubuntu-latest + platform: linux/amd64 + + - epics-target: linux-x86_64 + epics-host: linux-x86_64 + image_name: linux + os: ubuntu-latest + platform: linux/amd64 + + - epics-target: linux-arm + epics-host: linux-arm + image_name: linux + os: macos-latest-x1 + platform: linux/arm64 runs-on: ${{ matrix.os }} env: - TAG: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}-${{ matrix.architecture }}-${{ matrix.target }}:${{ github.ref_name }} + TAG: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}-${{ matrix.image_name }}-${{ matrix.target }}:${{ github.ref_name }} steps: - name: Checkout uses: actions/checkout@v3 @@ -43,24 +59,27 @@ jobs: uses: docker/build-push-action@v5 with: context: . - platforms: ${{ matrix.platforms }} + platform: ${{ matrix.platform }} target: ${{ matrix.target }} - build-args: TARGET_ARCHITECTURE=${{ matrix.architecture }} + build-args: | + TARGET_ARCHITECTURE=${{ matrix.epics-target }} + EPICS_HOST_ARCH=${{ matrix.epics-host }} + BASE_IMAGE=${{ matrix.base_image }} tags: ${{ env.TAG }} cache-from: type=gha cache-to: type=gha,mode=max load: true - - name: Test image - run: echo "no tests yet" - - name: Push image if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }} uses: docker/build-push-action@v5 with: context: . - platforms: ${{ matrix.platforms }} + platform: ${{ matrix.platform }} target: ${{ matrix.target }} - build-args: TARGET_ARCHITECTURE=${{ matrix.architecture }} + build-args: | + TARGET_ARCHITECTURE=${{ matrix.epics-target }} + EPICS_HOST_ARCH=${{ matrix.epics-host }} + BASE_IMAGE=${{ matrix.base_image }} tags: ${{ env.TAG }} push: true diff --git a/Dockerfile b/Dockerfile index 2cd5ebb..f805324 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,49 +1,34 @@ # EPICS 7 Base Dockerfile -##### shared environment stage ################################################# - -# mandatory build args -# TARGET_ARCHITECTURE: the epics cross compile target platform: rtems or linux -# TARGETARCH: the buildx platform: amd64 or arm64 - -ARG TARGET_ARCHITECTURE - -FROM ubuntu:22.04 AS base +# build args +# TARGET_ARCHITECTURE: the epics cross compile target platform +# note that linux-x86_64 is shortened to linux and is the default +# EPICS_HOST_ARCH: the epics host architecture name +# BASE_IMAGE: can be used to bring in cross compilation tools -##### architecture stages ###################################################### - -# use buildx target platform to determine the base image architecture -FROM base AS environment-amd64 -ENV EPICS_HOST_ARCH=linux-x86_64 - -FROM base AS environment-arm64 -ENV EPICS_HOST_ARCH=linux-arm - -ENV TARGETARCH=${TARGETARCH} +ARG BASE_IMAGE=ubuntu:22.04 ##### shared environment stage ################################################# +FROM ${BASE_IMAGE} AS environment -FROM environment-${TARGETARCH} AS environment - -ARG TARGET_ARCHITECTURE +ARG TARGET_ARCHITECTURE=linux-x86_64 +ARG EPICS_HOST_ARCH=linux-x86_64 ENV TARGET_ARCHITECTURE=${TARGET_ARCHITECTURE} +ENV EPICS_HOST_ARCH=${EPICS_HOST_ARCH} ENV EPICS_ROOT=/epics ENV EPICS_BASE=${EPICS_ROOT}/epics-base +ENV SUPPORT ${EPICS_ROOT}/support +ENV IOC ${EPICS_ROOT}/ioc ENV LD_LIBRARY_PATH=${EPICS_BASE}/lib/${EPICS_HOST_ARCH} + ENV VIRTUALENV /venv ENV PATH=${VIRTUALENV}/bin:${EPICS_BASE}/bin/${EPICS_HOST_ARCH}:${PATH} -ENV SUPPORT ${EPICS_ROOT}/support -ENV IOC ${EPICS_ROOT}/ioc -ENV EPICS_BASE_SRC=https://github.com/epics-base/epics-base ENV EPICS_VERSION=R7.0.8 -ENV GIT_OPTS="--branch ${EPICS_VERSION} --recursive" - - -##### developer / build stage ################################################## -FROM environment AS devtools +##### developer stage ########################################################## +FROM environment AS developer # install build tools and utilities RUN apt-get update -y && apt-get upgrade -y && \ @@ -64,37 +49,12 @@ RUN apt-get update -y && apt-get upgrade -y && \ && rm -rf /var/lib/apt/lists/* \ && busybox --install -##### unique developer setup for linux soft iocs ############################### - -FROM devtools AS developer-linux - -# nothing additional to do for linux - -##### unique developer setup for rtems iocs #################################### - -FROM devtools AS developer-rtems - -ENV RTEMS_VERSION=6.1-rc2 -ENV RTEMS_TOP_FOLDER=/rtems${RTEMS_VERSION}-beatnik-legacy -ENV RTEMS_BASE=${RTEMS_TOP_FOLDER}/rtems/${RTEMS_VERSION}/ - -# clone from a fork while this while EPICS rtems 6 is still under development -ENV EPICS_BASE_SRC=https://github.com/kiwichris/epics-base.git -ENV GIT_OPTS="--branch rtems-legacy-net-support --recursive" - -# pull in RTEMS BSP from the GHCR -COPY --from=ghcr.io/epics-containers/rtems6-powerpc-linux-runtime:6.2rc1ec1 \ - ${RTEMS_BASE} ${RTEMS_BASE} - -##### shared build stage ####################################################### - -FROM developer-${TARGET_ARCHITECTURE} AS developer - -# copy initial epics folder structure -COPY epics /epics +# TODO THIS WILL COME FROM THE RTEMS BASE IMAGE +ENV RTEMS_BASE=rtems6.1-rc2-beatnik-legacy/rtems/6.1-rc2 # get and build EPICS base -RUN git clone ${EPICS_BASE_SRC} -q ${GIT_OPTS} ${EPICS_BASE} && \ +COPY epics /epics +RUN bash epics/scripts/get-base.sh && \ bash /epics/scripts/patch-epics-base.sh RUN make -C ${EPICS_BASE} -j $(nproc); make -C ${EPICS_BASE} clean @@ -102,14 +62,12 @@ COPY requirements.txt /requirements.txt RUN python3 -m venv ${VIRTUALENV} && pip install -r /requirements.txt ##### runtime preparation stage ################################################ - FROM developer AS runtime_prep # get the products from the build stage and reduce to runtime assets only RUN ibek ioc extract-runtime-assets /assets --no-defaults /venv ##### runtime stage ############################################################ - FROM environment as runtime # add runtime system dependencies diff --git a/epics/scripts/get-base.sh b/epics/scripts/get-base.sh new file mode 100644 index 0000000..74f92a3 --- /dev/null +++ b/epics/scripts/get-base.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# get the version of epics-base indicated by the environment unless we +# are building for RTEMS6 which is temporarily in a forked version + +if [[ ${TARGET_ARCHITECTURE} == "RTEMS-beatnik" ]] ; then + git clone https://github.com/kiwichris/epics-base.git \ + --branch rtems-legacy-net-support -q \ + --recursive ${EPICS_BASE} +else + git clone https://github.com/epics-base/epics-base \ + --branch ${EPICS_VERSION} -q \ + --recursive ${EPICS_BASE} +fi \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index bad3117..8cc9393 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -ibek==1.7.0 +ibek==1.7.1