Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to template 3.4.0 #16

Merged
merged 6 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
_commit: 3.4.0
_src_path: gh:epics-containers/ioc-template
description: Generic IOC for controlling PLCs via the opcua protocol
git_platform: github.com
github_org: epics-containers
name: ioc-opcua
repo_uri: [email protected]:epics-containers/ioc-opcua.git
rtems: false
24 changes: 8 additions & 16 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
"dockerfile": "../Dockerfile",
"target": "developer",
"args": {
"TARGET_ARCHITECTURE": "linux"
// Native target development settings ==============================
"EPICS_TARGET_ARCH": "linux-x86_64"
// Local cross compilation settings ================================
// "EPICS_TARGET_ARCH": "RTEMS-beatnik",
// "IMAGE_EXT": "-rtems-beatnik"
}
},
"remoteEnv": {
Expand Down Expand Up @@ -39,11 +43,9 @@
]
}
},
// Make sure the files we are mapping into the container exist on the host
// You can place any other outside of the container before-launch commands here
// You can place any outside of the container before-launch commands here
"initializeCommand": "bash .devcontainer/initializeCommand ${devcontainerId}",
// Hooks the global .bashprofile_dev_container but also can add any other commands
// to run in the container at creation in here
// One time global setup commands inside the container
"postCreateCommand": "bash .devcontainer/postCreateCommand ${devcontainerId}",
"runArgs": [
// Allow the container to access the host X11 display and EPICS CA
Expand All @@ -58,16 +60,6 @@
// 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
"source=${localWorkspaceFolder}/.devcontainer/.bashrc,target=/root/.bashrc,type=bind",
// provides a place for you to put your shell customizations for all your dev containers
"source=${localEnv:HOME}/.bashrc_dev_container,target=/root/.bashrc_dev_container,type=bind",
// provides a place to install any packages you want to have across all your dev containers
"source=${localEnv:HOME}/.bashprofile_dev_container,target=/root/.bashprofile_dev_container,type=bind",
// provides the same command line editing experience as your host
"source=${localEnv:HOME}/.inputrc,target=/root/.inputrc,type=bind"
"source=${localWorkspaceFolder},target=/epics/generic-source,type=bind"
]
}
13 changes: 2 additions & 11 deletions .devcontainer/initializeCommand
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
#!/bin/bash

# make sure all the files we mount into the container exist
for i in \
.bash_eternal_history \
.bashrc_dev_container \
.bashprofile_dev_container \
.inputrc
do
if [ ! -f $HOME/$i ] ; then
touch $HOME/$i;
fi
done
# custom initialization goes here - runs outside of the dev container
# just before the container is launched but after the container is created

echo "devcontainerID ${1}"
30 changes: 16 additions & 14 deletions .devcontainer/postCreateCommand
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
#!/bin/bash

# Custom initialization goes here if needed.
# Runs inside the dev container after the container is created

################################################################################
# When using docker we will not be root inside the container
# the following steps are then required
################################################################################

if [[ $USER != "root" ]] ; then
# make sure the non-root user can build iocs and (mounted in) support modules
sudo chown -R ${USER}:${USER} /epics/links /venv
sudo chown -h ${USER}:${USER} /epics /epics/ioc

# also give non-root user access to the same bash config we use in podman
sudo chmod a+rx /root
for f in .inputrc .bash_eternal_history .bashrc .bashrc_dev_container; do
sudo chmod a+rw /root/$f
ln -sf /root/$f $HOME/$f
done
sudo chown -R ${USER}:${USER} /epics/ibek-defs /epics/pvi-defs /epics/support/configure /venv
sudo chown -h ${USER}:${USER} /epics /epics/ioc /epics/support
fi

################################################################################
# Custom install script for each developer to add whatever they like to
# all epics-containers devcontainers
# Shell customizations for Generic IOC devcontainers
################################################################################

# add ibek completion to bash and zsh
echo 'source <(ibek --show-completion bash)' >> $HOME/.bashrc
echo 'source <(ibek --show-completion zsh)' >> $HOME/.zshrc

# pick a theme that does not cause completion corruption in zsh
sed -i $HOME/.zshrc -e 's/ZSH_THEME="devcontainers"/ZSH_THEME="lukerandall"/'

# add user's custom profile container creation script
if [ -f ~/.bashprofile_dev_container ]; then
. ~/.bashprofile_dev_container
# allow personalization of all devcontainers in this subdirectory
# by placing a .devcontainer_rc file in the workspace root
if [[ -f /workspaces/.devcontainer_rc ]] ; then
source /workspaces/.devcontainer_rc
fi
4 changes: 0 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,3 @@ updates:
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "daily"
75 changes: 56 additions & 19 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,33 @@ on:
pull_request:

jobs:
build-push-images:
build:
# pull requests are a duplicate of a branch push if within the same repo.
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
permissions:
contents: read
packages: write
strategy:
fail-fast: false
max-parallel: 1 # take advantage of caching
matrix:
target: [developer, runtime]
architecture: [linux]
epics-target: [linux-x86_64] # , linux-aarch64]
include:
- os: ubuntu-latest
- os: ubuntu-latest # everyone is on ubuntu-latest
- epics-target: linux-x86_64
extension: ""
platform: linux/amd64

# # a temporary name until multi-arch is supported
# - epics-target: linux-aarch64
# extension: -native-aarch64
# platform: linux/arm64

runs-on: ${{ matrix.os }}
env:
TAG: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}${{ matrix.extension }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: recursive

Expand All @@ -35,39 +42,69 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: ${{ github.event_name == 'push' && github.ref_type == 'tag' }}
platform: ${{ matrix.platform }}
target: ${{ matrix.target }}
build-args: TARGET_ARCHITECTURE=${{ matrix.architecture }}
tags: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}-${{ matrix.architecture }}-${{ matrix.target }}:${{ github.ref_name }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: ${{ matrix.platform }}
target: runtime
build-args: |
IMAGE_EXT=${{ matrix.extension }}
cache-from: type=gha,scope=${{ matrix.epics-target }}
cache-to: type=gha,mode=max,scope=${{ matrix.epics-target }}
tags: ci_test
load: true

- name: Test image
# can't test non native without some hardware to run on
if: ${{ matrix.epics-target == 'linux-x86_64' }}
run: tests/run-tests.sh ci_test

- name: Push developer image
if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }}
uses: docker/build-push-action@v5
with:
context: .
platforms: ${{ matrix.platform }}
target: developer
build-args: |
IMAGE_EXT=${{ matrix.extension }}
tags: ${{ env.TAG }}-developer:${{ github.ref_name }}
push: true

- name: Push runtime image
if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }}
uses: docker/build-push-action@v5
with:
context: .
platforms: ${{ matrix.platform }}
target: runtime
build-args: |
IMAGE_EXT=${{ matrix.extension }}
tags: ${{ env.TAG }}-runtime:${{ github.ref_name }}
push: true

release:
# Release on tag push - publish ioc schema
needs: [build-push-images]
needs: [build]
if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }}
runs-on: ubuntu-latest

# this job runs in the (linux) developer container we just made
# this job runs in the native developer container we just made
container:
image: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}-linux-developer:${{ github.ref_name }}
image: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}-developer:${{ github.ref_name }}

steps:
- name: generate-schema
run: |
ibek ioc generate-schema --output ibek.ioc.schema.json

# TODO add back in some tests that run INSIDE the container

- name: Github Release
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # v0.1.15
with:
Expand Down
19 changes: 8 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
*~
O.*
bin
dbd
db
data
lib


.history
repos*
**/.ruff_cache/
Expand All @@ -21,5 +12,11 @@ ibek
*workspace

# config folder is there to be replaced there is just a dummy with Readme.
# NOTE: we are shipping a sample ioc instance so dont ignore this folder
# ioc/config
ioc/config

# podman may leave this around in aborted builds
.build.swp

# this gets updated during RTEMS builds in devcontainer but we dont want to commit it
# TODO this entry does not work - why on earth not?
ioc/configure/CONFIG_SITE.Common.linux-x86_64
49 changes: 49 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Generic IOC debugging launcher
// To use this l
// 1. make sure you have gdb installed in your container with
// apt update; apt-get install gdb
// 2. run the IOC once to make sure rutime assets are generated:
// cd /epics/ioc; make
// ./start.sh
// 3. stop the IOC with 'exit'
// 4. In vscode go to the support source in /epics/support/xxx
// 5. Set any breakpoints in the source code that you require.
// 6. You may want to set 'HOST_OPT=NO' in CONFIG_SITE and rebuild the support
// 6. Go to the debug tab and select 'IOC devcontainer debug' from the
// RUN AND DEBUG dropdown
{
"version": "0.2.0",
"configurations": [
{
"name": "IOC devcontainer debug",
"type": "cppdbg",
"request": "launch",
"program": "/epics/ioc/bin/linux-x86_64/ioc",
"args": [
"/epics/runtime/st.cmd"
],
"stopAtEntry": false,
"cwd": "/epics/ioc",
"environment": [
{
"name": "RUNTIME_DIR",
"value": "/epics/runtime"
}
],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
35 changes: 19 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
##### build stage ##############################################################
ARG IMAGE_EXT

ARG TARGET_ARCHITECTURE
ARG BASE=7.0.7ec3
ARG BASE=7.0.8ec2
ARG REGISTRY=ghcr.io/epics-containers
ARG RUNTIME=${REGISTRY}/epics-base${IMAGE_EXT}-runtime:${BASE}
ARG DEVELOPER=${REGISTRY}/epics-base${IMAGE_EXT}-developer:${BASE}

FROM ${REGISTRY}/epics-base-${TARGET_ARCHITECTURE}-developer:${BASE} AS developer
##### build stage ##############################################################
FROM ${DEVELOPER} 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
# connect ioc source folder to its know location
RUN ln -s ${SOURCE_FOLDER}/ioc ${IOC}

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

Expand All @@ -22,31 +24,32 @@ WORKDIR ${SOURCE_FOLDER}/ibek-support
COPY ibek-support/_global/ _global

COPY ibek-support/iocStats/ iocStats
RUN iocStats/install.sh 3.1.16
RUN iocStats/install.sh 3.2.0

COPY ibek-support/opcua opcua
RUN opcua/install.sh v0.9.5

# get the ioc source and build it
COPY ioc ${SOURCE_FOLDER}/ioc
RUN cd ${IOC} && make
RUN cd ${IOC} && ./install.sh && make

##### runtime preparation stage ################################################
# install runtime proxy for non-native builds
RUN bash ${IOC}/install_proxy.sh

##### runtime preparation stage ################################################
FROM developer AS runtime_prep

# get the products from the build stage and reduce to runtime assets only
RUN ibek ioc extract-runtime-assets /assets ${SOURCE_FOLDER}/ibek*
RUN ibek ioc extract-runtime-assets /assets

##### runtime stage ############################################################

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

# get runtime assets from the preparation stage
COPY --from=runtime_prep /assets /

# install runtime system dependencies, collected from install.sh script
RUN ibek support apt-install --runtime
ENV TARGET_ARCHITECTURE ${TARGET_ARCHITECTURE}
# install runtime system dependencies, collected from install.sh scripts
RUN ibek support apt-install-runtime-packages --skip-non-native

CMD "bash -c ${IOC}/start.sh"

ENTRYPOINT ["/bin/bash", "-c", "${IOC}/start.sh"]
Loading
Loading