Skip to content

Commit

Permalink
update to latest compose template
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesknap committed Aug 14, 2024
1 parent 4b1e8c3 commit f43040e
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 37 deletions.
5 changes: 5 additions & 0 deletions .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
_commit: 3.6.0
_src_path: gh:epics-containers/services-template-compose
description: t01 IOC Instances and Services
services: t01
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ venv*

# this is the root directory for generated opi files
# and is created at runtime by IOCs using PVI
opi/iocs
opi/iocs/*
!opi/iocs/README.md
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Beamline t01 IOC Instances and Services
# t01 IOC Instances and Services

This repository holds the a definition of example beamline t01 IOC Instances and services. It is a example of how to deploy epics-containers IOCs using docker compose for those facilities that are not using Kubernetes. It can also deploy its set of IOCs to a developer workstation for testing / experimentation.

Expand All @@ -17,10 +17,14 @@ Setup command line completion for docker compose (optional):
# these steps will make cli completion work for zsh
mkdir -p ~/.oh-my-zsh/completions
podman completion zsh > ~/.oh-my-zsh/completions/_podman
# OR
docker completion zsh > ~/.oh-my-zsh/completions/_docker

# these steps will make cli completion work for bash
mkdir -p ~/.local/share/bash-completion/completions
podman completion bash > ~/.local/share/bash-completion/completions/podman
# OR
docker completion bash > ~/.local/share/bash-completion/completions/docker
```

## Local Developer Testing Environment
Expand Down Expand Up @@ -75,15 +79,15 @@ docker compose --profile deploy -f my_server_01.yml up -d

IMPORTANT: if you are using docker then IOCs deployed this way will automatically be brought up again on server reboot. podman will not do this by default because it is running in user space - there are workarounds for this but podman is not recommended for this purpose.

The gold standard for orchestrating these containers in production is Kubernetes. See https://epics-containers.github.io/main/tutorials/setup_k8s.html. Although compose is really useful for development and testing, Kubernetes is far superior for managing services across a cluster of hosts.
The gold standard for orchestrating these containers in production is Kubernetes. See https://epics-containers.github.io/main/tutorials/setup_k8s.html. Although compose is really useful for development and testing, Kubernetes is superior for managing services across a cluster of hosts.

# Compose goals

These goals for switching to compose (from beskope code in the `ec` tool) have all been met:
These goals for switching to compose (from bespoke code in the `ec` tool) have all been met:

- be as DRY as possible
- work with docker-compose controlling either docker or podman
- enable isolated testing where PVs are not availble to the whole subnet
- enable isolated testing where PVs are not available to the whole subnet
- include separate profiles for:
- local testing - including phoebus OPI
- deployment to a beamline server - this would need either:
Expand Down
13 changes: 6 additions & 7 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@
#
# For this example we have a single compose file. However, if you wanted to keep
# all IOCs for a beamline in a single repo but deploy to multiple servers,
# then each server would have its own named compose file
# then each server would have its own named compose file, or you could
# use a single compose file with a different profile for each server.

# to deploy IOCs to the local machine, clone this repo and run the following
# command from the repo root:
# docker compose --profile deploy up --detach
# or for a multiple server repo:
# docker compose --profile deploy -f my_server_01.yml up --detach

# to deploy the IOCs to a workstation for testing and development, use:
# docker compose up --detach
#

include:
# all profiles
# test and deploy profiles
- services/bl01t-ea-test-01/compose.yml
- services/bl01t-di-cam-01/compose.yml
- services/gateway/compose.yml
- services/pvagw/compose.yml

# develop profile only
# dev and test profiles
- services/phoebus/compose.yml
- services/gateway/compose.yml

# deploy profile only
- services/epics-opis/compose.yml
15 changes: 11 additions & 4 deletions environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@

# This script must be sourced
if [ "$0" = "$BASH_SOURCE" ]; then
echo "ERROR: Please source this script (source environment.sh)"
echo "ERROR: Please source this script (source ./environment.sh)"
exit 1
fi

# if there is a docker-compose module then load it
if [[ $(module avail docker-compose 2>/dev/null) != "" ]] ; then
module load docker-compose
fi

function check_docker {
# return 0 if docker is detected, or 1 otherwise,
# cope with the possibility that podman is aliased to docker
Expand All @@ -22,9 +27,11 @@ function check_docker {
fi
}

# set user id for the phoebus container for easy X11 forwarding.
if check_docker; then
USER_ID=$(id -u); USER_GID=$(id -g)
else
alias docker=podman
USER_ID=0; USER_GID=0
fi

Expand All @@ -35,9 +42,9 @@ xhost +SI:localuser:$(id -un)

# set user id for the phoebus container for easy X11 forwarding.
export UIDGID=$USER_ID:$USER_GID
# choose develop profile for docker compose
export COMPOSE_PROFILES=develop
# for develop profile our ca-gateway publishes PVS on the loopback interface
# choose test profile for docker compose
export COMPOSE_PROFILES=test
# for test profile our ca-gateway publishes PVS on the loopback interface
export EPICS_CA_ADDR_LIST=127.0.0.1
# make a short alias for docker-compose for convenience
alias ec='docker compose'
10 changes: 4 additions & 6 deletions include/ioc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@ services:
linux_ioc: &linux_ioc
labels:
# a reference to which repository created this IOC
ioc_group: bl01t
ioc_group: t01
# lets tools like ec identify which containers are IOCs
is_ioc: true
# in K8S each IOC can have an indication of what physical location it
# should be (used by machine IOCs) this is for parity (but redundant).
location: localhost

# NOTE: blank environment vars should be overriden in individual IOCs
# NOTE: blank environment vars should be overridden in individual IOCs
environment:
IOCSH_PS1:
IOC_NAME:
# a prefix for devIocStats PVs. Configured externally for health_check
IOC_PREFIX:
IOC_LOCATION: localhost
BEAMLINE: bl01t
IOC_GROUP: bl01t
BEAMLINE: t01
IOC_GROUP: t01

tty: true
stdin_open: true
Expand Down
3 changes: 2 additions & 1 deletion include/networks.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
networks:
channel_access:
name: "channel_access"
ipam:
driver: default
config:
- subnet: "172.20.0.0/16"
- subnet: "172.20.0.0/16"
11 changes: 11 additions & 0 deletions opi/iocs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
OPI Files
=========

All files under the opi/iocs folder will be generated by PVI at IOC runtime.

These files are not committed to git and any changes made to them will be lost
when the related IOC is restarted.

To make custom opi files, create them in the opi folder or other subfolders of
opi.

31 changes: 31 additions & 0 deletions services/.ioc_template/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
services:

replace_me:

extends:
service: linux_ioc
file: ../../include/ioc.yml

image: replace_with_image_uri

labels:
version: 0.1.0

environment:
IOCSH_PS1: replace_me >
IOC_NAME: replace_me

volumes:
- ../../opi/iocs/replace_me:/epics/opi

configs:
- source: replace_me_config
target: epics/ioc/config

configs:
replace_me_config:
file: ./config

include:
- path:
../../include/networks.yml
16 changes: 16 additions & 0 deletions services/.ioc_template/config/ioc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# yaml-language-server: $schema=https://github.com/epics-containers/ioc-template-example/releases/download/3.5.1/ibek.ioc.schema.json

# TODO replace above with the generic IOC schema this IOC is based on
ioc_name: "{{ _global.get_env('IOC_NAME') }}"

description: REPLACE WITH DESCRIPTION

entities:
- type: epics.EpicsEnvSet
name: EPICS_TZ
value: GMT0BST

- type: devIocStats.iocAdminSoft
IOC: "{{ ioc_name | upper }}"

# - todo: Add more entities to make a meaningful IOC
33 changes: 25 additions & 8 deletions services/gateway/compose.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# When deploying IOCs to a server with docker, the choice is:
#
# 1. Use host network so their PVs available on the subnet
# 2. Run a ca-gateway on each server and add all servers to client's
# EPICS_CA_ADDR_LIST
# 2. Run a ca-gateway on each server
#
# at present the only available option for podman is to use host network
# for local testing we also run a ca-gateway and bind it to localhost

services:

# ca-gateway for development #################################################
# ca-gateway for test / dev ##################################################

ca-gateway: &ca-gateway

container_name: ca-gateway

image: ghcr.io/epics-containers/docker-ca-gateway:2.1.3ec1

expose:
Expand All @@ -27,7 +28,6 @@ services:

networks:
channel_access:
ipv4_address: 172.20.255.254

configs:
- source: ca-gateway_config
Expand All @@ -36,16 +36,29 @@ services:
command: -cip 172.20.255.255 -pvlist /config/pvlist -access /config/access -log /dev/stdout -debug 1

profiles:
- develop
- test
- dev

# debugging version of gateway container #####################################
ca-gateway-debug:

container_name: ca-gateway-debug

<<: *ca-gateway

# this image is not distroless and has network tools installed
image: ghcr.io/epics-containers/docker-ca-gateway-debug:2.1.3ec1

profiles:
- debug

# per server ca-gateway for deployment #######################################
ca-gateway-deploy:

<<: *ca-gateway

ports:
# TODO - drop the IP address but also set up pvlist to make sure there
# are no loops - I need to look into safe config for per server ca-gateways
# TODO - I need to look into safe config for per server ca-gateways
- 127.0.0.1:5064:5064/udp
- 127.0.0.1:5064-5065:5064-5065

Expand All @@ -57,3 +70,7 @@ services:
configs:
ca-gateway_config:
file: ./config

include:
- path:
../../include/networks.yml
10 changes: 8 additions & 2 deletions services/phoebus/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

services:
phoebus:
container_name: phoebus
image: ghcr.io/epics-containers/ec-phoebus:4.7.3ec2
environment:
DISPLAY: $DISPLAY
Expand All @@ -27,9 +28,14 @@ services:
target: /config

profiles:
- develop
- phoebus
- test
- dev
- debug

configs:
phoebus_config:
file: ./config

include:
- path:
../../include/networks.yml
12 changes: 8 additions & 4 deletions services/pvagw/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

services:

# local pvagw for development ################################################
# local pvagw for test/dev ##################################################

pvagw: &pvagw
container_name: pvagw

image: ghcr.io/epics-containers/ec-p4p:4.1.12ec1

Expand All @@ -20,8 +21,7 @@ services:
restart: unless-stopped

networks:
channel_access:
ipv4_address: 172.20.255.250
- channel_access

configs:
- source: pvagw_config
Expand All @@ -48,8 +48,12 @@ services:
command: -c "pvagw /config/pvagw.config"

profiles:
- removed_due_to_networking_issue
- removed

configs:
pvagw_config:
file: ./config

include:
- path:
../../include/networks.yml

0 comments on commit f43040e

Please sign in to comment.