Skip to content

Commit 391ed79

Browse files
authored
Merge pull request #50 from epics-containers/dev
Add Tutorial IOC Changes 1
2 parents 37525c9 + 7830b63 commit 391ed79

File tree

4 files changed

+187
-107
lines changed

4 files changed

+187
-107
lines changed

docs/user/tutorials/create_ioc.rst

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,21 @@ detector as follows:
188188
entities:
189189
190190
- type: ADSimDetector.simDetector
191-
PORT: DET.DET
192-
P: BL01T-EA-TST-01
193-
R: ":DET:"
191+
PORT: DET.DET
192+
P: BL01T-EA-TST-01
193+
R: ":DET:"
194+
195+
.. note::
196+
197+
If you are unfamiliar with YAML then you could take a look at
198+
the YAML spec here: https://yaml.org/spec/1.2/spec.html#id2759963.
199+
200+
Be aware that white space is significant. i.e. indentation represents
201+
nesting. Above we have a list of entities, each list item is denoted by
202+
``-``. There is currently a single entry in the list which is a dictionary
203+
of key value pairs. The first key is ``type`` and the value is
204+
``ADSimDetector.simDetector``.
205+
194206

195207
This will create us a simulation detector driver with PV prefix
196208
``BL01T-EA-TST-01:DET:`` that publishes its output on the Asyn port ``DET.DET``.

docs/user/tutorials/dev_container.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,33 @@ simply launch the developer container in a shell and use it via CLI only.
8585
Starting a Developer Container
8686
------------------------------
8787

88+
.. Warning::
89+
90+
DLS Users and Redhat Users:
91+
92+
There is a
93+
`bug in VSCode devcontainers extension <https://github.com/microsoft/vscode-remote-release/issues/8557>`_
94+
at the time of writing
95+
that makes it incompatible with podman and an SELinux enabled /tmp directory.
96+
This will affect most Redhat users and you will see an error regarding
97+
permissions on the /tmp folder when VSCode is building your devcontainer.
98+
99+
Here is a temporary workaround, paste this into a terminal:
100+
101+
.. code-block:: bash
102+
103+
echo '
104+
#!/bin/bash
105+
if [[ "${@}" == "buildx build"* ]] ; then
106+
shift 2
107+
/usr/bin/podman buildx build --security-opt=label=disable "${@}"
108+
else
109+
/usr/bin/podman "${@}"
110+
fi
111+
' > $HOME/.local/bin/podman
112+
chmod +x $HOME/.local/bin/podman
113+
114+
88115
For this section we will work with the ADSimDetector Generic IOC that we
89116
used in previous tutorials. Let's go and fetch a version of the Generic IOC
90117
source and build it locally.
@@ -118,6 +145,17 @@ for working on Generic IOCs from *outside* of the container. These commands
118145
are useful for debugging container builds: although most work is done inside
119146
the container, you will need these commands if it fails to build.
120147

148+
149+
.. note::
150+
151+
Before continuing this tutorial make sure you have not left the IOC
152+
bl01t-ea-ioc-02 running from a previous tutorial. Execute this command
153+
outside of the devcontainer to stop it:
154+
155+
.. code-block:: bash
156+
157+
ec ioc stop bl01t-ea-ioc-02
158+
121159
Once built, open the project in VSCode:
122160

123161
.. code-block:: bash

docs/user/tutorials/ioc_changes1.rst

Lines changed: 133 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,50 @@
11
Changing the IOC Instance
22
=========================
33

4-
5-
.. Warning::
6-
7-
This tutorial is out of date and will be updated in November 2023.
8-
9-
10-
This tutorial will make a very simple change to the example IOC ``bl01t-ea-ioc-01``.
11-
This is a type 1. change from the above list, types 2, 3 will be covered in the
4+
This tutorial will make a very simple change to the example IOC ``bl01t-ea-ioc-02``.
5+
This is a type 1 change from `ioc_change_types`, types 2, 3 will be covered in the
126
following 2 tutorials.
137

8+
Strictly speaking, Type 1 changes do not require a devcontainer. You created
9+
and deployed the IOC instance in a previous tutorial without one. It is up to
10+
you how you choose to make these types of changes. Types 2,3 do require a
11+
devcontainer because they involve compiling Generic IOC / support module code.
12+
1413
We are going to add a hand crafted EPICS DB file to the IOC instance. This will
1514
be a simple record that we will be able to query to verify that the change
1615
is working.
1716

17+
.. note::
18+
19+
Before doing this tutorial make sure you have not left the IOC
20+
bl01t-ea-ioc-02 running from a previous tutorial. Execute this command
21+
outside of the devcontainer to stop it:
22+
23+
.. code-block:: bash
24+
25+
ec ioc stop bl01t-ea-ioc-02
26+
1827
Make the following changes in your test IOC config folder
19-
(``bl01t/iocs/bl01t-ea-ioc-01/config``):
28+
(``bl01t/iocs/bl01t-ea-ioc-02/config``):
2029

2130
1. Add a file called ``extra.db`` with the following contents.
22-
IMPORTANT replace [$USER] with your username:
2331

2432
.. code-block:: text
2533
26-
record(ai, "[$USER]-EA-IOC-01:TEST") {
34+
record(ai, "BL02T-EA-IOC-01:TEST") {
2735
field(DESC, "Test record")
2836
field(DTYP, "Soft Channel")
2937
field(SCAN, "Passive")
3038
field(VAL, "1")
3139
}
3240
33-
2. Add the following line to the ``st.cmd`` file after the last ``dbLoadRecords``
34-
line:
41+
2. Add the following lines to the end ``ioc.yaml`` (verify that the indentation
42+
matches the above entry so that ``- type:`` statements line up):
3543

36-
.. code-block:: text
44+
.. code-block:: yaml
3745
38-
dbLoadRecords(config/extra.db)
46+
- type: epics.StartupCommand
47+
command: dbLoadRecords(config/extra.db)
3948
4049
Locally Testing Your changes
4150
----------------------------
@@ -46,106 +55,127 @@ folder:
4655

4756
.. code-block:: bash
4857
49-
ec dev ioc-launch iocs/bl01t-ea-ioc-01
58+
# stop any existing IOC shell by hitting Ctrl-D or typing exit
59+
cd /epics/ioc
60+
./start.sh
5061
51-
This will launch Generic IOC container specified in the ``bl01t-ea-ioc-01``
52-
helm chart and mount into it the local config specified in
53-
``/iocs/bl01t-ea-ioc-01/config``.
62+
If all is well you should see your iocShell prompt and the output should
63+
show ``dbLoadRecords(config/extra.db)``.
5464

55-
If all is well you should see your iocShell prompt and you can test your change
65+
Test your change
5666
from another terminal (VSCode menus -> Terminal -> New Terminal) like so:
5767

5868
.. code-block:: bash
5969
60-
caget $USER-EA-IOC-01:TEST
70+
caget BL02T-EA-IOC-02:TEST
6171
6272
If you see the value 1 then your change is working.
6373

64-
.. note::
65-
66-
If you also wanted to make local changes
67-
to the Generic IOC itself you could clone the Generic IOC source repo,
68-
locally build the container image and then use ``ec dev ioc-launch`` as
69-
follows:
74+
.. Note::
7075

71-
.. code-block:: bash
72-
73-
# advanced example - not part of this tutorial
74-
cd <root of your workspace>
75-
git clone [email protected]:epics-containers/ioc-adsimdetector.git
76-
cd ioc-adsimdetector
77-
# this makes a local image with tag :local
78-
ec dev build
79-
cd ../bl01t
80-
ec dev ioc-launch iocs/bl01t-ea-ioc-01 ../ioc-adsimdetector
76+
You are likely to see
77+
*"Identical process variable names on multiple servers"* warnings. This is
78+
because caget can see the PV on the host network and the container network,
79+
but as these are the same IOC this is not a problem.
8180

81+
You can change this and make your devcontainer network isolated by removing
82+
the line ``"--net=host",`` from ``.devcontainer/devcontainer.json``, but
83+
it is convenient to leave it if you want to run OPI tools locally on the
84+
host. You may want to isolate your development network if multiple
85+
developers are working on the same subnet. In this case some other solution
86+
is required for running OPI tools on the host (TODO add link to solution).
8287

83-
Note you can see your running IOC in podman using this command:
88+
Because of the symlink between ``/epics/ioc/config`` and
89+
``/repos/bl01t/iocs/bl01t-ea-ioc-02/config`` the same files you are testing
90+
by launching the ioc inside of the devcontainer are also ready to be
91+
committed and pushed to the bl01t repo. i.e.:
8492

8593
.. code-block:: bash
8694
87-
podman ps
88-
89-
You should see a container named bl01t-ea-ioc-01 and also a another one with a
90-
random name and an image called ``localhost/vsc-work...``. The latter is the
91-
container that is running your developer environment.
92-
93-
If you would like to take a look inside the container you can run a bash shell
94-
in the container like this:
95-
96-
.. code-block:: bash
97-
98-
podman exec -it bl01t-ea-ioc-01 bash
99-
100-
When you type exit on the iocShell the container will stop and and be removed.
101-
102-
.. _local_deploy_ioc:
103-
104-
Deploying a Beta IOC Instance to The Cluster
105-
============================================
106-
107-
In ``05_deploy_example`` we deployed a tagged version of the IOC instance to
108-
the cluster. This the correct way to deploy a production IOC instance as it
109-
means there is a record of version of the IOC instance in the Helm Chart
110-
OCI registry and you can always roll back to that version if needed.
111-
112-
However, it is also possible to directly deploy a version of the IOC instance
113-
from your local machine to the cluster.
114-
This is useful for testing changes to the IOC instance
115-
before publishing a new version. In this case
116-
your IOC will be given a beta tag in the cluster, indicating that it has
117-
not yet been released.
118-
119-
To deploy your changes direct to the cluster use the following command:
120-
121-
.. code-block:: bash
122-
123-
ec ioc deploy-local iocs/bl01t-ea-ioc-01
124-
125-
You will get a warning that this is a temporary deployment and you will see that
126-
the version number will look something like ``2023.3.29-b14.29`` this
127-
indicates that this is a beta deployment made at 14:29 on 29th March 2023.
128-
129-
Now when you ask for the IOCs running in your domain you should see your IOC
130-
with beta version listed:
131-
132-
.. code-block:: bash
133-
134-
$ ec ps -w
135-
POD VERSION STATE RESTARTS STARTED IP GENERIC_IOC_IMAGE
136-
bl01t-ea-ioc-01-7d7c5bc759-5bjsr 2023.3.29-b14.29 Running 0 2023-03-29T14:29:18Z 192.168.0.32 ghcr.io/epics-containers/ioc-adsimdetector-linux-runtime:23.3.4
137-
138-
You can check it is working as before (replace the IP with yours
139-
from the above command):
140-
141-
.. code-block:: bash
142-
143-
export EPICS_CA_ADDR_LIST=192.168.0.32
144-
caget $USER-EA-IOC-01:TEST
145-
146-
Once you are happy with your changes you can push and tag your beamline repo.
147-
This will publish a new version of the IOC instance helm chart to the OCI helm
148-
registry. You can then deploy the versioned IOC instance to the cluster.
149-
150-
151-
95+
# Do this from a host terminal (not a devcontainer terminal)
96+
cd bl01t
97+
git add .
98+
git commit -m "Added extra.db"
99+
git push
100+
# tag a new version of the beamline repo
101+
git tag 2023.11.2
102+
git push origin 2023.11.2
103+
# deploy the new version of the IOC to the local docker / podman instance
104+
ec deploy bl01t-ea-ioc-02 2023.11.2
105+
106+
The above steps were performed on a host terminal because we are using ``ec``.
107+
However all of the steps except for the ``ec`` command could have been done
108+
*inside* the devcontainer starting with ``cd /repos/bl01t``.
109+
110+
We choose not to have ``ec`` installed inside of the devcontainer because
111+
that would involve containers in containers which adds too much complexity.
112+
113+
Raw Startup Assets
114+
------------------
115+
116+
If you plan not to use ``ibek`` runtime asset creation you could use the raw
117+
startup assets from the previous tutorial. If you do this then the process
118+
above is identical except that you will add the ``dbLoadRecords`` command to
119+
the end of ``st.cmd``.
120+
121+
More about ibek Runtime Asset Creation
122+
--------------------------------------
123+
124+
The set of ``entities`` that you may create in your ioc.yaml is defined by the
125+
``ibek`` IOC schema that we reference at the top of ``ioc.yaml``.
126+
The schema is in turn defined by the set of support modules that were compiled
127+
into the Generic IOC (ioc-adsimdetector). Each support module has an
128+
``ibek`` *support YAML* file that contributes to the schema.
129+
130+
The *Support yaml* files are in the folder ``/epics/ibek`` inside of the
131+
container. They were placed their during the compilation of the support
132+
modules at Generic IOC build time.
133+
134+
It can be instructive to look at these files to see what entities are available
135+
to *IOC instances*. For example the global support yaml file
136+
``/epics/ibek/ibek.yaml`` contains the following:
137+
138+
.. code:: yaml
139+
140+
- name: StartupCommand
141+
description: Adds an arbitrary command in the startup script before iocInit
142+
args:
143+
- type: str
144+
name: command
145+
description: command string
146+
default: ""
147+
pre_init:
148+
- type: text
149+
value: "{{ command }}"
150+
151+
- name: PostStartupCommand
152+
description: Adds an arbitrary command in the startup script after iocInit
153+
args:
154+
- type: str
155+
name: command
156+
description: command string
157+
default: ""
158+
post_init:
159+
- type: text
160+
value: "{{ command }}"
161+
162+
These two definitions allow you to add arbitrary commands to the startup script
163+
before and after iocInit. This is how we added the ``dbLoadRecords`` command.
164+
165+
If you want to specify multiple lines in a command you can use the following
166+
syntax for multi-line stings:
167+
168+
.. code-block:: yaml
169+
170+
- type: epics.StartupCommand
171+
command: |
172+
# loading extra records
173+
dbLoadRecords(config/extra.db)
174+
# loading even more records
175+
dbLoadRecords(config/extra2.db)
176+
177+
This would place the 4 lines verbatim into the startup script (except that
178+
they would not be indented - the nesting whitespace is stripped).
179+
180+
In later tutorials we will see where the *Support yaml* files come from and
181+
how to add your own.

docs/user/tutorials/rtems_ioc.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ To deploy an IOC instance to the cluster you can use one of two approaches:
257257

258258
- use ``ec ioc deploy-local`` to directly deploy the local copy of the IOC
259259
instance helm chart to kubernetes as a beta version. This was covered for
260-
linux IOCs in `local_deploy_ioc`.
260+
linux IOCs in --local_deploy_ioc--.
261261

262262
Both types of deployment of IOC instances above work exactly the same for
263263
linux and RTEMS IOCs. We will do the latter as it is quicker for

0 commit comments

Comments
 (0)