Skip to content

Commit

Permalink
adopt new template
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesknap committed Oct 18, 2023
1 parent e57b32e commit c5d04b6
Show file tree
Hide file tree
Showing 21 changed files with 142 additions and 679 deletions.
9 changes: 5 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# Look for updates to python and docker dependencies.

version: 2
updates:
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "daily"
103 changes: 28 additions & 75 deletions .github/workflows/build.sh
Original file line number Diff line number Diff line change
@@ -1,94 +1,47 @@
#!/bin/bash

# A script for building EPICS container images.
# A generic build script for epics-containers ioc repositories
#
# Note that this is implemented in bash to make it portable between
# CI frameworks. This approach uses the minimum of GitHub Actions.
# Also works locally for testing outside of CI (with podman-docker installed)
# Also works locally for testing outside of CI
#
# INPUTS:
# PUSH: if true, push the container image to the registry
# TAG: the tag to use for the container image
# REGISTRY: the container registry to push to
# REPOSITORY: the container repository to push to
# PLATFORM: the platform to build for (linux/amd64 or linux/arm64)
# CACHE: the directory to use for caching

ARCH=${ARCH:-linux}
PUSH=${PUSH:-false}
TAG=${TAG:-latest}
REGISTRY=${REGISTRY:-ghcr.io}
if [[ -z ${REPOSITORY} ]] ; then
# For local builds, infer the registry from git remote (assumes ghcr)
REPOSITORY=$(git remote -v | sed "s/.*@github.com:\(.*\)\.git.*/ghcr.io\/\1/" | tail -1)
echo "inferred registry ${REPOSITORY}"
fi
export EC_TAG="--tag ${TAG:-latest}"
export EC_PLATFORM="--platform ${PLATFORM:-linux/amd64}"
export EC_CACHE="${CACHE:-/tmp/ec-cache}"
export EC_DEBUG=true
if [[ "${PUSH}" == 'true' ]] ; then EC_PUSH='--push' ; fi

NEWCACHE=${CACHE}-new
THIS=$(dirname ${0})
set -xe
mkdir -p ${CACHE}

if ! docker -v 2> /dev/null; then
echo "switching to podman ..."
PODMAN=true
shopt -s expand_aliases
alias docker=podman
# get the current version of ec CLI
pip install -r ${THIS}/../../requirements.txt

# podman command line parameters (just use local cache)
cachefrom=""
cacheto=""
else
# setup a buildx driver for multi-arch / remote cached builds
docker buildx create --driver docker-container --use
# docker command line parameters
cachefrom=--cache-from=type=local,src=${CACHE}
cacheto=--cache-to=type=local,dest=${NEWCACHE},mode=max
fi
# add cache arguments - local file cache passed by github seems to be most reliable
export EC_CARGS="
--cache-from type=local,src=${EC_CACHE}
--cache-to type=local,dest=${EC_CACHE}
"

set -e
# add extra cross compilation platforms below if needed e.g.
# ec dev build --arch rtems ... for RTEMS cross compile

do_build() {
ARCHITECTURE=$1
TARGET=$2
shift 2
# build runtime and developer images
ec dev build --buildx ${EC_TAG} ${EC_PLATFORM} ${EC_PUSH} ${EC_CARGS}

image_name=${REGISTRY}/${REPOSITORY}-${ARCHITECTURE}-${TARGET}:${TAG}
# convert to lowercase - required for OCI URLs
image_name=${image_name,,}
args="
--build-arg TARGET_ARCHITECTURE=${ARCHITECTURE}
--target ${TARGET}
-t ${image_name}
"
# extract the ioc schema from the runtime image
ec dev launch-local ${EC_TAG} --execute \
'ibek ioc generate-schema /epics/links/ibek/*.ibek.support.yaml' > ibek.ioc.schema.json

if [[ ${PUSH} == "true" && ${PODMAN} != "true" ]] ; then
args="--push "${args}
fi
# run acceptance tests
shopt -s nullglob # expand to nothing if no tests are found
for t in "${THIS}/../../tests/*.sh"; do ${t}; done

echo "CONTAINER BUILD FOR ${image_name} with ARCHITECTURE=${ARCHITECTURE} ..."

(
set -x
docker buildx build ${args} ${*} .
)

if [[ ${PUSH} == "true" && ${PODMAN} == "true" ]] ; then
podman push ${image_name}
fi
}

# EDIT BELOW FOR YOUR BUILD MATRIX REQUIREMENTS
#
# All builds should use cachefrom and the last should use cacheto
# The last build should execute all stages for the cache to be fully useful.
#
# intermediate builds should use cachefrom but will also see the local cache
#
# If None of the builds use all stages in the Dockerfile then consider adding
# cache-to to more than one build. But note there is a tradeoff in performance
# as every layer will get uploaded to the cache even if it just came out of the
# cache.

do_build ${ARCH} developer ${cachefrom}
do_build ${ARCH} runtime ${cachefrom} ${cacheto}

# remove old cache to avoid indefinite growth
rm -rf ${CACHE}
mv ${NEWCACHE} ${CACHE}
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
.history
repos*
**/.ruff_cache/
**/.mypy_cache/

# build pulls the schema out of the container - ignore it
*ibek.ioc.schema.json
# while working on ibek with this project somethimes include it as subfolder
ibek

# The ioc source tree is created here from a template inside the generic ioc
# repo.
# Remove from .gitignore if you want to customize the template.
/ioc/

# dont save workspaces as other users will have differing folders
*workspace
21 changes: 11 additions & 10 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ build_linux_developer:
variables:
ARCH: linux
TARGET: developer
# build_rtems_runtime:
# extends: .build
# variables:
# ARCH: rtems
# TARGET: runtime

# build_rtems_developer:
# extends: .build
# variables:
# ARCH: rtems
# TARGET: developer
build_rtems_runtime:
extends: .build
variables:
ARCH: rtems
TARGET: runtime

build_rtems_developer:
extends: .build
variables:
ARCH: rtems
TARGET: developer
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "ibek-defs"]
path = ibek-defs
url = https://github.com/epics-containers/ibek-defs.git
[submodule "ibek-support"]
path = ibek-support
url = https://github.com/epics-containers/ibek-support.git
4 changes: 1 addition & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"cSpell.words": [
"SIGTERM"
]
"python.defaultInterpreterPath": "/venv/bin/python"
}
90 changes: 32 additions & 58 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,85 +1,59 @@
##### build stage ##############################################################

ARG TARGET_ARCHITECTURE
ARG BASE=23.3.1
ARG BASE=7.0.7ec2
ARG REGISTRY=ghcr.io/epics-containers

FROM ghcr.io/epics-containers/epics-base-${TARGET_ARCHITECTURE}-developer:${BASE} AS developer
##### build stage ##############################################################

# install additional build time dependencies
RUN apt-get update && apt-get upgrade -y && \
apt-get install -y --no-install-recommends \
libssh2-1-dev \
libboost-dev \
&& rm -rf /var/lib/apt/lists/*
FROM ${REGISTRY}/epics-base-${TARGET_ARCHITECTURE}-developer:${BASE} AS developer

# override of epics-base ctools and ibek may be practical but should be removed
# when epics-base is updated
COPY ctools /ctools/
RUN pip install ibek==0.9.5.b2 telnetlib3
# copy the global ibek files
COPY ibek-defs/_global /ctools/_global/
# Get latest ibek while in development. Will come from epics-base in future.
RUN pip install --upgrade ibek==1.4.0

# get and build depdency support modules, for each also copy associated ibek defs
# The devcontainer mounts the project root to /epics/ioc-adsimdetector. Using
# the same location here makes devcontainer/runtime differences transparent.
WORKDIR /epics/ioc-adsimdetector/ibek-support

COPY ibek-defs/asyn/ /ctools/asyn/
RUN python3 modules.py install ASYN R4-42 github.com/epics-modules/asyn.git --patch asyn/asyn.sh
RUN make -C ${SUPPORT}/asyn -j $(nproc)
# copy the global ibek files
COPY ibek-support/_global/ _global

COPY ibek-defs/autosave/ /ctools/autosave/
RUN python3 modules.py install AUTOSAVE R5-10-2 github.com/epics-modules/autosave.git --patch autosave/autosave.sh
RUN make -C ${SUPPORT}/autosave -j $(nproc)
COPY ibek-support/iocStats/ iocStats
RUN iocStats/install.sh 3.1.16

COPY ibek-defs/busy/ /ctools/busy/
RUN python3 modules.py install BUSY R1-7-3 github.com/epics-modules/busy.git
RUN make -C ${SUPPORT}/busy -j $(nproc)
COPY ibek-support/asyn/ asyn/
RUN asyn/install.sh R4-42

COPY ibek-defs/sscan/ /ctools/sscan/
RUN python3 modules.py install SSCAN R2-11-5 github.com/epics-modules/sscan.git
RUN make -C ${SUPPORT}/sscan -j $(nproc)
COPY ibek-support/autosave/ autosave/
RUN autosave/install.sh R5-10-2

COPY ibek-defs/calc/ /ctools/calc/
RUN python3 modules.py install CALC R3-7-4 github.com/epics-modules/calc.git --patch calc/calc.sh
RUN make -C ${SUPPORT}/calc -j $(nproc)
COPY ibek-support/busy/ busy/
RUN busy/install.sh R1-7-3

COPY ibek-defs/motor/ /ctools/motor/
RUN python3 modules.py install MOTOR R7-2-3b1 github.com/dls-controls/motor.git
RUN make -C ${SUPPORT}/motor -j $(nproc)
COPY ibek-support/ADCore/ ADCore/
RUN ADCore/install.sh R3-12-1

COPY ibek-defs/pmac/ /ctools/pmac/
RUN python3 modules.py install PMAC 2-6-0b2 github.com/dls-controls/pmac.git --patch pmac/pmac.sh
RUN make -C ${SUPPORT}/pmac -j $(nproc)
COPY ibek-support/ADSimDetector/ ADSimDetector/
RUN ADSimDetector/install.sh R2-10

# add the generic IOC source code. TODO: this will be generated by ibek in future
COPY ioc ${IOC}
# build generic IOC
RUN make -C ${IOC} && make clean -C ${IOC}
# Generate template IOC source tree / generate Makefile / compile
RUN ibek ioc build

##### runtime preparation stage ################################################

FROM developer AS runtime_prep

# get the products from the build stage and reduce to runtime assets only
WORKDIR /min_files
RUN bash /ctools/minimize.sh ${IOC} $(ls -d ${SUPPORT}/*/) /ctools
RUN ibek ioc extract-runtime-assets /assets

##### runtime stage ############################################################

FROM ghcr.io/epics-containers/epics-base-${TARGET_ARCHITECTURE}-runtime:${BASE} AS runtime

# these installs required for RTEMS only
RUN apt-get update && apt-get upgrade -y && \
apt-get install -y --no-install-recommends \
telnet netcat psmisc \
libssh2-1 \
&& rm -rf /var/lib/apt/lists/*
FROM ${REGISTRY}/epics-base-${TARGET_ARCHITECTURE}-runtime:${BASE} AS runtime

# add products from build stage
COPY --from=runtime_prep /min_files /
COPY --from=developer /venv /venv
# get runtime assets from the preparation stage
COPY --from=runtime_prep /assets /

# add ioc scripts
COPY ioc ${IOC}
# install runtime system dependencies, collected from install.sh scripts
RUN ibek support apt-install --runtime

ENV TARGET_ARCHITECTURE ${TARGET_ARCHITECTURE}

ENTRYPOINT ["/bin/bash", "-c", "${IOC}/start.sh"]
ENTRYPOINT ["/bin/bash", "-c", "${IOC}/start.sh"]
27 changes: 19 additions & 8 deletions build
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
#!/bin/bash

THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
################################################################################
# generic local build script for epics-containers ioc repositories #
################################################################################

# a script to locally build all targets containers for this IOC
# Note this requires the ec command form
# https://github.com/epics-containers/epics-containers-cli
# pass rtems as first argument to build RTEMS on cross-compiler
TARGET_ARCHITECTURE=${1:-linux}

cd ${THIS_DIR}
set -xe

cd $(dirname ${0})

# make sure new repos get their submodule ibek-support
git submodule update --init

# build runtime and developer images
ec dev build --arch ${TARGET_ARCHITECTURE}

# get the schema file from the developer container and save it locally
ec dev launch-local --execute \
'ibek ioc generate-schema /epics/links/ibek/*.ibek.support.yaml' \
> ibek.ioc.schema.json

ec dev build --arch linux
# Todo get rtems working for pmac
# ec dev build --arch rtems
15 changes: 0 additions & 15 deletions ctools/README.md

This file was deleted.

Loading

0 comments on commit c5d04b6

Please sign in to comment.