Skip to content

Commit

Permalink
base: add build-static-ioc.sh to musl image.
Browse files Browse the repository at this point in the history
This script automates building fully statically linked IOCs using the
musl image.

Also document it in the README.
  • Loading branch information
ericonr committed Aug 28, 2024
1 parent 743e0cc commit eb2469e
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
35 changes: 35 additions & 0 deletions base/build-static-ioc.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions base/musl/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit eb2469e

Please sign in to comment.