Skip to content

Commit

Permalink
switch to /epics/generic-source mount
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesknap committed Jan 17, 2024
1 parent dedb6b8 commit 4256860
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 183 deletions.
27 changes: 15 additions & 12 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
"EC_PROJECT": "${localWorkspaceFolderBasename}"
},
"features": {
// add quality of life features for developers including git config integration
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": false,
"installOhMyZsh": false,
"installOhMyZshConfig": false,
// don't upgrade to make this similar to the runtime container
"upgradePackages": false
}
},
// IMPORTANT for this devcontainer to work with docker EC_REMOTE_USER must be
// set to vscode. For podman it should be left blank.
// set to vscode. You will run as vscode with full sudo rights.
// For podman it should be left blank. You will run as root but host mounts
// will be owned by your user.
"remoteUser": "${localEnv:EC_REMOTE_USER}",
"customizations": {
"vscode": {
Expand All @@ -34,7 +35,7 @@
"redhat.vscode-yaml",
"ryanluker.vscode-coverage-gutters",
"epicsdeb.vscode-epics",
"ms-python.black-formatter"
"charliermarsh.ruff"
]
}
},
Expand All @@ -47,15 +48,17 @@
"runArgs": [
// Allow the container to access the host X11 display and EPICS CA
"--net=host",
// Make sure SELinux does not disable with access to host filesystems like tmp
// Make sure SELinux does not disable write access to host filesystems like tmp
"--security-opt=label=disable"
],
"workspaceMount": "source=${localWorkspaceFolder},target=/epics/${localWorkspaceFolderBasename},type=bind",
"workspaceFolder": "/epics/${localWorkspaceFolderBasename}",
// Mount the parent of the project folder so we can access peer projects
"workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind",
// mount in other useful files from the host
"mounts": [
// Mount some useful local files from the user's home directory
// By mounting the parent of the workspace we can work on multiple peer projects
"source=${localWorkspaceFolder}/../,target=/repos,type=bind",
// we also mount the project folder into a know location in the container
// this is where the ibek-support and ioc folders reside in the container build
// in this way the devcontainer and runtime look very similar
"source=${localWorkspaceFolder},target=/epics/generic-source,type=bind",
// this provides eternal bash history in and out of the container
"source=${localEnv:HOME}/.bash_eternal_history,target=/root/.bash_eternal_history,type=bind",
// this bashrc hooks up the .bashrc_dev_container in the following mount
Expand All @@ -67,4 +70,4 @@
// provides the same command line editing experience as your host
"source=${localEnv:HOME}/.inputrc,target=/root/.inputrc,type=bind"
]
}
}
7 changes: 2 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ ARG REGISTRY=ghcr.io/epics-containers

FROM ${REGISTRY}/epics-base-${TARGET_ARCHITECTURE}-developer:${BASE} AS developer

ARG PROJECT_NAME
RUN test -n "${PROJECT_NAME}" || (echo "PROJECT_NAME must be set" && false)

# The devcontainer mounts the project root to /workspaces/${PROJECT_NAME}
# The devcontainer mounts the project root to /epics/generic-source
# Using the same location here makes devcontainer/runtime differences transparent.
ENV SOURCE_FOLDER=/workspaces/${PROJECT_NAME}
ENV SOURCE_FOLDER=/epics/generic-source
# connect ioc source folder its know location
RUN ln -s ${SOURCE_FOLDER}/ioc ${IOC}

Expand Down
6 changes: 6 additions & 0 deletions ioc/config/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This config folder is where the generic IOC container will look
for configuration files. These configuration files are used to
bootstrap a unique IOC instance.

For this reason this folder is intended to be mounted over at container
runtime. The mounted folder should the IOC instance's config folder.
61 changes: 0 additions & 61 deletions ioc/config/ioc.yaml

This file was deleted.

43 changes: 0 additions & 43 deletions ioc/config/start.sh

This file was deleted.

160 changes: 102 additions & 58 deletions ioc/start.sh
Original file line number Diff line number Diff line change
@@ -1,51 +1,78 @@
#!/bin/bash

#
# The epics-containers IOC startup script.
#
# This script is used to start an EPICS IOC in a Kubernetes pod. Implementers
# of generic IOCs are free to replace this script with their own. But
# this script as is should work for most IOCs.
#
# When a generic IOC runs in a kubernetes pod it is expected to have
# a config folder that defines the IOC instance.
# The helm chart for the generic IOC will mount the config folder
# as a configMap and this turns a generic IOC into aspecific IOC instance.
#
# Here we support the following set of options for the contents of
# the config folder:
#
# 1. ioc.yaml *************************************************************
# If the config folder contains an ioc.yaml file we invoke the ibek tool to
# generate the startup script and database. Then launch with the generated
# startup script.
#
# 2. st.cmd + ioc.subst *********************************************************
# If the config folder contains a st.cmd script and a ioc.subst file then
# optionally generate ioc.db from the ioc.subst file and use the st.cmd script
# as the IOC startup script. Note that the expanded database file will
# be generated in /tmp/ioc.db
#
# 3. start.sh ******************************************************************
# If the config folder contains a start.sh script it will be executed.
# This allows the instance implementer to provide a conmpletely custom
# startup script.
#
# 4. empty config folder *******************************************************
# If the config folder is empty the default script that prints a message
# will run
#
# 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:
# - copy the IOC directory to the RTEMS mount point
# - send a reboot command to the RTEMS crate
# - start a telnet session to the RTEMS IOC console
#
description='
set -x -e
The epics-containers IOC Startup Script
=======================================
This script is used to start an EPICS IOC in a Kubernetes pod. Implementers
of generic IOCs are free to replace this script with their own. But
this script as is should work for most IOCs.
When a generic IOC runs in a kubernetes pod it is expected to have
a config folder that defines the IOC instance.
The helm chart for the generic IOC will mount the config folder
as a configMap and this turns a generic IOC into a specific IOC instance.
Here we support the following set of options for the contents of
the config folder:
1. start.sh ******************************************************************
If the config folder contains a start.sh script it will be executed.
This allows the instance implementer to provide a completely custom
startup script. Any other files that the script needs can also be placed
in the config folder.
The presence of this file overrides all other options.
WARNING: config maps are restricted to 1MB total.
2. ioc.yaml *************************************************************
If the config folder contains a yaml file we invoke the ibek tool to
generate the startup script and database. Then launch with the generated
startup script. The file name should be the name of the ioc with a 'yaml'
extension e.g. bl38p-ea-panda-02.yaml. Using a unique name allows for:
ioc_name: "{{ ioc_yaml_file_name }}"
at the top of the file and in turn "{{ ioc_name }}"" can be used in any
of the fields within the file.
3. st.cmd + ioc.subst *********************************************************
If the config folder contains a st.cmd script and a ioc.subst file then
optionally generate ioc.db from the ioc.subst file and use the st.cmd script
as the IOC startup script. Note that the expanded database file will
be generated in ${RUNTIME_DIR}/ioc.db
4. empty config folder *******************************************************
If the config folder is empty this message will be displayed.
RTEMS IOCS - RTEMS IOC startup files can be generated using any of the above.
For RTEMS we do not execute the ioc inside of the pod. Instead we:
- copy the IOC directory to the RTEMS mount point
- send a reboot command to the RTEMS crate
- start a telnet session to the RTEMS IOC console and connect that to
stdio of the pod.
'

# error reporting *************************************************************

function ibek_error {
echo "${1}"

# Wait indefinitely so the container does not exit and restart continually.
while true; do
sleep 1000
done
}

# environment setup ************************************************************

set -x -e

export TOP=$(realpath $(dirname $0))
cd ${TOP}
CONFIG_DIR=${TOP}/config
Expand All @@ -58,43 +85,59 @@ fi
# override startup script
override=${CONFIG_DIR}/start.sh
# source YAML for IOC Builder for EPICS on Kubernetes (ibek)
ibek_src=${CONFIG_DIR}/ioc.yaml
ibek_yamls=(${CONFIG_DIR}/*.yaml)
# Startup script for EPICS IOC generated by ibek
ioc_startup=${CONFIG_DIR}/st.cmd

# folder for runtime assets
export RUNTIME_DIR=${EPICS_ROOT}/runtime
mkdir -p ${RUNTIME_DIR}

# expanded database file
epics_db=/tmp/ioc.db
epics_db=${RUNTIME_DIR}/ioc.db

# in case there are multiple YAML, pick the first one in the glob
ibek_src=${ibek_yamls[0]}

# 1. start.sh override script **************************************************
if [ -f ${override} ]; then
exec bash ${override}
# 2. ioc.yaml ******************************************************************
elif [ -f ${ibek_src} ]; then

# 1. ioc.yaml ******************************************************************
if [ -f ${ibek_src} ]; then
if [[ ${#ibek_yams[@]} > 1 ]]; then
ibek_error "ERROR: Multiple YAML files found in ${CONFIG_DIR}."
fi

# Database generation script generated by ibek
db_src=/tmp/ioc.subst
final_ioc_startup=/tmp/st.cmd
db_src=${RUNTIME_DIR}/ioc.subst
final_ioc_startup=${RUNTIME_DIR}/st.cmd

# get ibek the support yaml files this ioc's support modules
defs=/epics/links/ibek/*.ibek.support.yaml
ibek startup generate ${ibek_src} ${defs} --out ${final_ioc_startup} --db-out ${db_src}
# get the ibek support yaml files this ioc's support modules
defs=/epics/ibek-defs/*.ibek.support.yaml
ibek runtime generate ${ibek_src} ${defs} --out ${final_ioc_startup} --db-out ${db_src}

# build expanded database using msi
if [ -f ${db_src} ]; then
includes=$(for i in ${SUPPORT}/*/db; do echo -n "-I $i "; done)
bash -c "msi -o${epics_db} ${includes} -S${db_src}"
bash -c "msi -o${epics_db} ${includes} -I${RUNTIME_DIR} -S${db_src}"
fi

# 2. st.cmd + ioc.substitutions ************************************************
# 2. st.cmd + ioc.subst ************************************************
elif [ -f ${ioc_startup} ] ; then

if [ -f ${CONFIG_DIR}/ioc.substitutions ]; then
# generate ioc.db from ioc.substitutions, including all templates from SUPPORT
if [ -f ${CONFIG_DIR}/ioc.subst ]; then
# generate ioc.db from ioc.subst, including all templates from SUPPORT
includes=$(for i in ${SUPPORT}/*/db; do echo -n "-I $i "; done)
msi ${includes} -S ${CONFIG_DIR}/ioc.substitutions -o ${epics_db}
msi ${includes} -I${RUNTIME_DIR} -S ${CONFIG_DIR}/ioc.subst -o ${epics_db}
fi
final_ioc_startup=${ioc_startup}
# 4. empty config folder ***************************************************
else
echo "No startup assets found in ${CONFIG_DIR}"
echo

elif [ -f ${override} ]; then
exec bash ${override}
ibek_error "${description}"
fi

# Launch the IOC ***************************************************************
Expand All @@ -107,3 +150,4 @@ else
# Execute the IOC binary and pass the startup script as an argument
exec ${IOC}/bin/linux-x86_64/ioc ${final_ioc_startup}
fi

4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ibek==1.6.0b1
# ibek==1.6.0b1
# to install direct from github during development in the dev branch:
#git+https://github.com/epics-containers/ibek.git@dev
git+https://github.com/epics-containers/ibek.git@remove-ioc-template
Loading

0 comments on commit 4256860

Please sign in to comment.