From eb2469e16498706b709c4bd4e8479f9e07188080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89rico=20Nogueira?= Date: Wed, 28 Aug 2024 17:35:36 -0300 Subject: [PATCH] base: add build-static-ioc.sh to musl image. This script automates building fully statically linked IOCs using the musl image. Also document it in the README. --- README.md | 28 ++++++++++++++++++++++++++++ base/build-static-ioc.sh | 35 +++++++++++++++++++++++++++++++++++ base/musl/Dockerfile | 2 ++ 3 files changed, 65 insertions(+) create mode 100755 base/build-static-ioc.sh diff --git a/README.md b/README.md index 74e1530..fb12d17 100644 --- a/README.md +++ b/README.md @@ -151,3 +151,31 @@ default image with older kernels. It can be obtained directly from the [GitHub registry](https://github.com/cnpem/epics-in-docker/pkgs/container/lnls-alpine-3.18-epics-7). + +### Building fully static IOCs + +Fully static IOCs can be built using the `build-static-ioc.sh` script provided +by this image. One way to automate this is using a `docker-compose.yml` file +and running `docker compose up`; the file should have the following contents: + +``` +services: + build-static-ioc: + image: ghcr.io/cnpem/lnls-alpine-3.18-epics-7:v0.10.0-dev + volumes: + - type: bind + source: ./ + target: /opt/REPOSITORY + working_dir: /opt/REPOSITORY + command: build-static-ioc.sh REPOSITORY +``` + +This will generate a versioned tarball containing the built IOC. For this +reason, it is recommended to use git repositories with tagged releases. +Furthermore, the `target` and `working_dir` keys are where the IOC expects to +be installed, meaning files like `envPaths` will encode this information. If it +is necessary to install it elsewhere, and building it with different values for +the keys isn't possible, it will be necessary to edit `envPaths`. + +For development, one can set the `SKIP_CLEAN` environment variable (under +`environment`), to skip the cleanup build steps and speed up rebuilds. diff --git a/base/build-static-ioc.sh b/base/build-static-ioc.sh new file mode 100755 index 0000000..ee5e2c3 --- /dev/null +++ b/base/build-static-ioc.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +set -ex + +IOC=$1 + +cp /opt/epics/RELEASE configure/ +cat << EOF > configure/CONFIG_SITE.local +STATIC_BUILD=YES +FULL_STATIC_BUILD=YES +USR_LDFLAGS = -static-pie +EOF + +git config --global --add safe.directory $PWD + +make_skip() { + if [ -z "$SKIP_CLEAN" ]; then + make "$@" + fi +} + +make_skip distclean +make +make_skip clean +make -C iocBoot + +version=$(git describe --tags) + +echo $version > $IOC-version +echo ".git/" > /tmp/globs +# this trick is done so the resulting tarball has a root $IOC/ directory +(cd .. && tar caf $IOC/$IOC-${version}.tar.gz -X /tmp/globs $IOC/) +rm $IOC-version + +make_skip distclean diff --git a/base/musl/Dockerfile b/base/musl/Dockerfile index b2d2089..ab176b5 100644 --- a/base/musl/Dockerfile +++ b/base/musl/Dockerfile @@ -73,3 +73,5 @@ COPY backport-ipmicomm.patch . COPY caputlog-waveform-fix.patch . COPY install_modules.sh . RUN NEEDS_TIRPC=YES ./install_modules.sh + +COPY build-static-ioc.sh /usr/local/bin