From d15cc62826f072f0b4fd412cc6f560faaeb260df Mon Sep 17 00:00:00 2001 From: Giles Knap Date: Thu, 28 Sep 2023 05:57:44 +0000 Subject: [PATCH] make start.sh work with new framework --- .github/workflows/build.sh | 28 ++++++++--------- .vscode/settings.json | 6 ++-- Dockerfile | 10 +++++- build | 18 ++++++++++- example/ioc.yaml | 62 ++++++++++++++++++++++++++++++++++++++ ibek-support | 2 +- ioc/start.sh | 56 ++++++++++++---------------------- 7 files changed, 123 insertions(+), 59 deletions(-) create mode 100644 example/ioc.yaml diff --git a/.github/workflows/build.sh b/.github/workflows/build.sh index 8ce5f1a..e37f787 100755 --- a/.github/workflows/build.sh +++ b/.github/workflows/build.sh @@ -13,29 +13,24 @@ # REPOSITORY: the container repository to push to # CACHE: the directory to use for caching +DOCKER=${DOCKER:-docker} 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:\(.*\) \(.*\)*/\1/" | tail -1) - echo "inferred registry ${REPOSITORY}" + echo ERROR: REPOSITORY not set + exit 1 fi NEWCACHE=${CACHE}-new -if ! docker -v 2> /dev/null; then - echo "switching to podman ..." - docker=podman - shopt -s expand_aliases - alias docker=podman +if [[ ${DOCKER} == podman ]] ; then # podman command line parameters (just use local cache) cachefrom="" cacheto="" else - docker=docker # setup a buildx driver for multi-arch / remote cached builds docker buildx create --driver docker-container --use # docker command line parameters @@ -60,7 +55,7 @@ do_build() { -t ${image_name} " - if [[ $docker != "podman" ]] ; then + if [[ $DOCKER != "podman" ]] ; then if [[ ${PUSH} == "true" ]] ; then args="--push "${args} else @@ -72,10 +67,10 @@ do_build() { ( set -x - $docker buildx build ${args} ${*} . + $DOCKER buildx build ${args} ${*} . ) - if [[ ${PUSH} == "true" && $docker == "podman" ]] ; then + if [[ ${PUSH} == "true" && $DOCKER == "podman" ]] ; then podman push ${image_name} fi } @@ -96,17 +91,18 @@ do_build ${ARCH} developer ${cachefrom} # get the schema file from the developer container echo "Getting schema file from developer container ..." -id=$($docker create ${image_name}) +id=$($DOCKER create ${image_name}) + # convention for schema name is module.ibek.ioc.schema.json # we get this my removing the ioc- prefix from the module name SCHEMA=$(basename ${REPOSITORY} | sed 's/^ioc-//').ibek.ioc.schema.json -$docker cp $id:/epics/ioc/${SCHEMA} . -$docker rm -v $id +$DOCKER cp $id:/epics/ioc/${SCHEMA} . +$DOCKER rm -v $id echo "schema file(s): $(ls *.ibek.ioc.schema.json)" do_build ${ARCH} runtime ${cachefrom} ${cacheto} -if [[ $docker != "podman" ]] ; then +if [[ -d ${NEWCACHE} ]] ; then # remove old cache to avoid indefinite growth rm -rf ${CACHE} mv ${NEWCACHE} ${CACHE} diff --git a/.vscode/settings.json b/.vscode/settings.json index 5637c50..90b62e7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,8 +3,8 @@ "editor.defaultFormatter": "ms-python.black-formatter" }, "workbench.colorCustomizations": { - "activityBar.background": "#729a0421", - "titleBar.activeBackground": "#729a0421", - "titleBar.activeForeground": "#ffffff" + "activityBar.background": "#5F0A0C", + "titleBar.activeBackground": "#850E11", + "titleBar.activeForeground": "#FFFBFB" } } \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 9ef5b3c..e64f3f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,9 @@ FROM ${REGISTRY}/epics-base-${TARGET_ARCHITECTURE}-developer:${BASE} AS develop # In a devcontainer this folder is mounted on the host's clone of ioc-adsimdetector WORKDIR /workspaces/ioc-adsimdetector/ibek-support +# During Development get latest ibek - TODO stable version will be in epics-base +RUN pip install --upgrade ibek + # copy the global ibek files COPY ibek-support/_global/ _global @@ -30,6 +33,9 @@ RUN ADCore/install.sh R3-12-1 COPY ibek-support/ADAravis/ ADAravis/ RUN ADAravis/install.sh R2-3 +# add startup scripts +COPY ioc ${IOC} + # Make the IOC RUN ibek ioc generate-makefile RUN ibek ioc compile @@ -55,11 +61,13 @@ COPY --from=developer /venv /venv COPY --from=runtime_prep /min_files / # get the Aravis library we built COPY --from=developer /usr/local/lib/x86_64-linux-gnu/libaravis-0.8.so.0 /usr/local/lib/x86_64-linux-gnu/ +# get the ibek-support folders for accessing the SUPPORT YAML files +COPY --from=developer /workspaces /workspaces # install runtime system dependencies, collected from install.sh scripts RUN ibek support apt-install --runtime -# add ioc sample startup scripts +# add startup scripts COPY ioc ${IOC} ENV TARGET_ARCHITECTURE ${TARGET_ARCHITECTURE} diff --git a/build b/build index 5d7e19b..9979a90 100755 --- a/build +++ b/build @@ -1,9 +1,25 @@ #!/bin/bash +# set up the environment and run the CI build script locally +# to test changes before pushing to github + set -xe -THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +THIS_DIR=$(dirname ${0}) + +# this function inferrs the repository from the git remote +function get_repository() { + REPOSITORY=$(git remote -v | tail -1) + + echo ' +import re +repo_only = re.sub(r".*github.com[:/](.*)[.]git.*", r"\1", "'${REPOSITORY}'") +print(repo_only) + ' | python3 +} +export REPOSITORY=$(get_repository) export TAG=${TAG:-local} +export DOCKER=podman ./.github/workflows/build.sh diff --git a/example/ioc.yaml b/example/ioc.yaml new file mode 100644 index 0000000..faff493 --- /dev/null +++ b/example/ioc.yaml @@ -0,0 +1,62 @@ +# yaml-language-server: $schema=https://github.com/epics-containers/ioc-adaravis/releases/download/23.9.1/adaravis.ibek.ioc.schema.json + +ioc_name: bl45p-ea-ioc-01 +description: Sample and overview cameras IOC for BL45P +generic_ioc_image: ghcr.io/epics-containers/ioc-adaravis-linux-runtime:23.9.1 + +entities: + - type: epics.EpicsCaMaxArrayBytes + max_bytes: 6000000 + + - type: ADAravis.aravisCamera + CLASS: AVT_Mako_G234B + PORT: DET.DET + P: BL45P-EA-MAP-01 + R: ":DET:" + ID: 172.23.59.11 + PV_ALIAS: "0" # TODO this ARG should have default + + - type: ADCore.NDPvaPlugin + PORT: DET.PVA + PVNAME: BL45P-EA-MAP-01:PVA:OUTPUT + P: BL45P-EA-MAP-01 + R: ":PVA:" + NDARRAY_PORT: DET.DET + BLOCK: 1 # TODO remaining ARGS should have defaults + PRIORITY: 0 + STACKSIZE: 0 + NDARRAY_ADDR: 0 + + - type: ADCore.NDFileHDF5 + PORT: DET.HDF5 + P: BL45P-EA-MAP-01 + R: ":HDF5:" + NDARRAY_PORT: DET.DET + BLOCK: 1 + NDARRAY_ADDR: 0 + + - type: ADAravis.aravisCamera + CLASS: AVT_Mako_G234B + PORT: DIFF.DET + P: BL45P-EA-DIFF-01 + R: ":DET:" + ID: 172.23.59.12 + PV_ALIAS: "0" + - type: ADCore.NDPvaPlugin + PORT: DIFF.PVA + PVNAME: BL45P-EA-DIFF-01:PVA:OUTPUT + P: BL45P-EA-DIFF-01 + R: ":PVA:" + NDARRAY_PORT: DIFF.DET + BLOCK: 1 + PRIORITY: 0 + STACKSIZE: 0 + NDARRAY_ADDR: 0 + + - type: ADCore.NDFileHDF5 + PORT: DIFF.HDF5 + P: BL45P-EA-DIFF-01 + R: ":HDF5:" + NDARRAY_PORT: DIFF.DET + BLOCK: 1 + NDARRAY_ADDR: 0 diff --git a/ibek-support b/ibek-support index 017926d..ee3653f 160000 --- a/ibek-support +++ b/ibek-support @@ -1 +1 @@ -Subproject commit 017926dffb1688b7f962146dc95f302f44b1dcfb +Subproject commit ee3653f0351e03d6f7fde78e394740007b51410d diff --git a/ioc/start.sh b/ioc/start.sh index 9ba261a..c22f0fb 100755 --- a/ioc/start.sh +++ b/ioc/start.sh @@ -32,9 +32,8 @@ # be generated in /tmp/ioc.db # # 4. empty config folder ******************************************************* -# If the config folder is not mounted then the IOC will launch the example in -# ./config folder. Mounting a config folder overrides the example contents -# in this repo's ./config/ . +# If the config folder is empty then this IOC will launch the example in +# ./example folder # # RTEMS IOCS - RTEMS IOC startup files can be generated using 2,3,4 above. For # RTEMS we do not execute the ioc inside of the pod. Instead we: @@ -47,10 +46,9 @@ set -x -e # environment setup ************************************************************ -TOP=/epics/ioc +export TOP=$(realpath $(dirname $0)) cd ${TOP} CONFIG_DIR=${TOP}/config -THIS_SCRIPT=$(realpath ${0}) # add module paths to environment for use in ioc startup script source ${SUPPORT}/configure/RELEASE.shell @@ -67,64 +65,48 @@ epics_db=/tmp/ioc.db # 1. start.sh ****************************************************************** -if [[ -f ${override} && ${override} != ${THIS_SCRIPT} ]]; then - exec bash ${override} +if [ -f ${override} ]; then + exec ${override} -# 2. ioc.yaml ****************************************************************** + elif [ -f ${ibek_src} ]; then + # 2. ioc.yaml ****************************************************************** -elif [ -f ${ibek_src} ]; then # Database generation script generated by ibek - db_src=/tmp/make_db.sh + db_src=/tmp/ioc.subst final_ioc_startup=/tmp/st.cmd # get ibek the support yaml files this ioc's support modules defs=/workspaces/*/ibek-support/*/*.ibek.support.yaml ibek startup generate ${ibek_src} ${defs} --out ${final_ioc_startup} --db-out ${db_src} - # build expanded database using the db_src shell script + # build expanded database using msi if [ -f ${db_src} ]; then - bash ${db_src} > ${epics_db} + includes=$(for i in ${SUPPORT}/*/db; do echo -n "-I $i "; done) + bash -c "msi -o${epics_db} ${includes} -S${db_src}" fi -# 3. st.cmd + ioc.substitutions ************************************************ + # 3. st.cmd + ioc.substitutions ************************************************ -elif [ -f ${ioc_startup} ] ; then + elif [ -f ${ioc_startup} ] ; then if [ -f ${CONFIG_DIR}/ioc.substitutions ]; then # generate ioc.db from ioc.substitutions, including all templates from SUPPORT includes=$(for i in ${SUPPORT}/*/db; do echo -n "-I $i "; done) - # msi tries to open substitutions file R/W so copy to a writable location - cp ${CONFIG_DIR}/ioc.substitutions /tmp - msi ${includes} -S /tmp/ioc.substitutions -o ${epics_db} + msi ${includes} -S ${CONFIG_DIR}/ioc.substitutions -o ${epics_db} fi final_ioc_startup=${ioc_startup} -# 4. empty config folder ******************************************************* + # 4. empty config folder ******************************************************* else - echo "ERROR - no startup script found in config folder" - echo "${CONFIG_DIR} must contain one of st.cmd, ioc.yaml, start.sh" + final_ioc_startup=${TOP}/example/st.cmd fi # Launch the IOC *************************************************************** if [[ ${TARGET_ARCHITECTURE} == "rtems" ]] ; then - - # this mount point is defined in helm-ioc-lib _deployment.yaml - K8S_IOC_ROOT=/nfsv2-tftp - - echo "RTEMS IOC. Copying IOCs files to RTEMS mount point ..." - rm -rf ${K8S_IOC_ROOT}/* - cp -r ${IOC}/* ${K8S_IOC_ROOT} - mkdir -p ${K8S_IOC_ROOT}/support/db - cp -r ${SUPPORT}/*/db/* ${K8S_IOC_ROOT}/support/db - - if [[ -f /tmp/ioc.db ]]; then - cp /tmp/ioc.db ${K8S_IOC_ROOT}/config - fi - - # Connect to the RTEMS console and reboot the IOC if requested - echo "Connecting to RTEMS console at ${RTEMS_VME_CONSOLE_ADDR}:${RTEMS_VME_CONSOLE_PORT}" - exec python3 /ctools/telnet3.py connect ${RTEMS_VME_CONSOLE_ADDR} ${RTEMS_VME_CONSOLE_PORT} --reboot ${RTEMS_VME_AUTO_REBOOT} --pause ${RTEMS_VME_AUTO_PAUSE} + echo "RTEMS IOC startup - copying IOC to RTEMS mount point ..." + cp -r ${IOC} ${K8S_IOC_ROOT} + sleep 100 else # Execute the IOC binary and pass the startup script as an argument exec ${IOC}/bin/linux-x86_64/ioc ${final_ioc_startup}