Skip to content

Commit

Permalink
make start.sh work with new framework
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesknap committed Sep 28, 2023
1 parent 02943cf commit d15cc62
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 59 deletions.
28 changes: 12 additions & 16 deletions .github/workflows/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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}
Expand Down
6 changes: 3 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
10 changes: 9 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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}
Expand Down
18 changes: 17 additions & 1 deletion build
Original file line number Diff line number Diff line change
@@ -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
62 changes: 62 additions & 0 deletions example/ioc.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion ibek-support
56 changes: 19 additions & 37 deletions ioc/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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}
Expand Down

0 comments on commit d15cc62

Please sign in to comment.