Skip to content

Commit

Permalink
add ioc source into repo (#24)
Browse files Browse the repository at this point in the history
* switch to ioc source in project

* bump ec client

* add the ioc source folder

* update ibek support to 2024 rework

* switch to /epics/generic-source mount

* ignore changes to ioc/config

* bump ibek to 1.6.0

* update ibek-support
  • Loading branch information
gilesknap authored Jan 18, 2024
1 parent d0c73fc commit a6f3fd5
Show file tree
Hide file tree
Showing 21 changed files with 364 additions and 26 deletions.
25 changes: 14 additions & 11 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 Down
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ repos*
# 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

# config folder is there to be replaced there is just a dummy with Readme.
ioc/config
15 changes: 10 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ ARG REGISTRY=ghcr.io/epics-containers

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

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

# Get latest ibek while in development. Will come from epics-base when stable
COPY requirements.txt requirements.txt
RUN pip install --upgrade -r requirements.txt

# 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
WORKDIR ${SOURCE_FOLDER}/ibek-support

# copy the global ibek files
COPY ibek-support/_global/ _global
Expand Down Expand Up @@ -41,8 +45,9 @@ RUN ADCore/install.sh R3-12-1
COPY ibek-support/ADSimDetector/ ADSimDetector/
RUN ADSimDetector/install.sh R2-10

# create IOC source tree, generate Makefile and compile IOC Instance
RUN ibek ioc build
# get the ioc source and build it
COPY ioc ${SOURCE_FOLDER}/ioc
RUN cd ${IOC} && make

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

Expand Down
10 changes: 10 additions & 0 deletions ioc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*~
O.*
bin
dbd
db
data
lib
.svn*
iocs/*IOC*
.idea
7 changes: 7 additions & 0 deletions ioc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
TOP = .
include $(TOP)/configure/CONFIG

DIRS += configure
DIRS += iocApp/src

include $(TOP)/configure/RULES_TOP
30 changes: 30 additions & 0 deletions ioc/configure/CONFIG
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# CONFIG - Load build configuration data
#
# Do not make changes to this file!

# Allow user to override where the build rules come from
RULES = $(EPICS_BASE)

# RELEASE files point to other application tops
include $(TOP)/configure/RELEASE
-include $(TOP)/configure/RELEASE.$(EPICS_HOST_ARCH).Common
ifdef T_A
-include $(TOP)/configure/RELEASE.Common.$(T_A)
-include $(TOP)/configure/RELEASE.$(EPICS_HOST_ARCH).$(T_A)
endif

CONFIG = $(RULES)/configure
include $(CONFIG)/CONFIG
-include $(CONFIG)/CONFIG.Dls

# Override the Base definition:
INSTALL_LOCATION = $(TOP)

# CONFIG_SITE files contain other build configuration settings
include $(TOP)/configure/CONFIG_SITE
-include $(TOP)/configure/CONFIG_SITE.$(EPICS_HOST_ARCH).Common
ifdef T_A
-include $(TOP)/configure/CONFIG_SITE.Common.$(T_A)
-include $(TOP)/configure/CONFIG_SITE.$(EPICS_HOST_ARCH).$(T_A)
endif

5 changes: 5 additions & 0 deletions ioc/configure/CONFIG_SITE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# CONFIG_SITE

CROSS_COMPILER_TARGET_ARCHS =
CHECK_RELEASE = NO

8 changes: 8 additions & 0 deletions ioc/configure/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
TOP=..

include $(TOP)/configure/CONFIG

TARGETS = $(CONFIG_TARGETS)
CONFIGS += $(subst ../,,$(wildcard $(CONFIG_INSTALLS)))

include $(TOP)/configure/RULES
5 changes: 5 additions & 0 deletions ioc/configure/RELEASE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# The following definitions must be changed for each site
#
# Common prefixes
SUPPORT=/epics/support
include $(SUPPORT)/configure/RELEASE
7 changes: 7 additions & 0 deletions ioc/configure/RULES
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# RULES

-include $(CONFIG)/RULES.Dls
include $(CONFIG)/RULES

# Library should be rebuilt because LIBOBJS may have changed.
$(LIBNAME): ../Makefile
2 changes: 2 additions & 0 deletions ioc/configure/RULES.ioc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#RULES.ioc
include $(CONFIG)/RULES.ioc
2 changes: 2 additions & 0 deletions ioc/configure/RULES_DIRS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#RULES_DIRS
include $(CONFIG)/RULES_DIRS
3 changes: 3 additions & 0 deletions ioc/configure/RULES_TOP
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#RULES_TOP
include $(CONFIG)/RULES_TOP

21 changes: 21 additions & 0 deletions ioc/iocApp/src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generic IOC Makefile

TOP = ../..
include $(TOP)/configure/CONFIG

PROD_IOC = ioc
DBD += ioc.dbd
ioc_DBD += base.dbd

# add in the dbds collected by ibek during container build
ioc_DBD += $(shell cat /epics/support/configure/dbd_list)

ioc_SRCS += ioc_registerRecordDeviceDriver.cpp

# add in the libs collected by ibek during container build
ioc_LIBS += $(shell cat /epics/support/configure/lib_list)

ioc_LIBS += $(EPICS_BASE_IOC_LIBS)
ioc_SRCS += iocMain.cpp

include $(TOP)/configure/RULES
20 changes: 20 additions & 0 deletions ioc/iocApp/src/iocMain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* This file was automatically generated on Fri 25 May 2018 08:06:10 BST from
* source: /home/hgv27681/R3.14.12.3/support/pmac/etc/makeIocs/lab.xml
*
* *** Please do not edit this file: edit the source file instead. ***
* */
#include "epicsExit.h"
#include "epicsThread.h"
#include "iocsh.h"

int main(int argc, char *argv[])
{
if(argc>=2) {
iocsh(argv[1]);
epicsThreadSleep(.2);
}
iocsh(NULL);
epicsExit(0);
return 0;
}

40 changes: 40 additions & 0 deletions ioc/liveness.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
TOP=/epics/ioc
cd ${TOP}
CONFIG_DIR=${TOP}/config

set -ex

CONFIG_DIR=/epics/ioc/config
THIS_SCRIPT=$(realpath ${0})
override=${CONFIG_DIR}/liveness.sh

if [[ -f ${override} && ${override} != ${THIS_SCRIPT} ]]; then
exec bash ${override}
fi

if [[ ${K8S_IOC_LIVENESS_ENABLED} != 'true' ]]; then
exit 0
fi

# use devIOCStats UPTIME as the default liveness PV
# but allow override from the environment
K8S_IOC_PV=${K8S_IOC_PV:-"${IOC_PREFIX}:UPTIME"}

# use default CA PORT or override from the environment
K8S_IOC_PORT=${K8S_IOC_PORT:-5064}

export EPICS_CA_ADDR_LIST=${K8S_IOC_ADDRESS}
export EPICS_CA_SERVER_PORT=${K8S_IOC_PORT}

# verify that the IOC is running
if caget ${K8S_IOC_PV} ; then
exit 0
else
# send the error message to the container's main process stdout
echo "Liveness check failed for ${IOC_NAME}" > /proc/1/fd/1
echo "Failing PV: ${K8S_IOC_PV}" > /proc/1/fd/2
echo "Address list: ${EPICS_CA_ADDR_LIST}" > /proc/1/fd/2
echo "CA Port: ${EPICS_CA_SERVER_PORT}" > /proc/1/fd/2
exit 1
fi
Loading

0 comments on commit a6f3fd5

Please sign in to comment.