Skip to content

Commit

Permalink
restructure for crosscompilation
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesknap committed Mar 6, 2024
1 parent 14d8485 commit e6f3c7d
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 73 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ LICENSE
.github
.vscode
.devcontainer.json
Dockerfile
41 changes: 30 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
80 changes: 19 additions & 61 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 && \
Expand All @@ -64,52 +49,25 @@ 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

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
Expand Down
14 changes: 14 additions & 0 deletions epics/scripts/get-base.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ibek==1.7.0
ibek==1.7.1

0 comments on commit e6f3c7d

Please sign in to comment.