Skip to content

Commit 83b1766

Browse files
committed
Overhaul, generalize containerized build scripts
Accept command-line arguments and environment variables to specify: - BUILDROOT: the default source of config, hostid and zpool.cache files - ZBMCONF: a specific configuration file to use inside the container - ZBMOUTPUT: a directory where build artifacts will be copied - HOSTID: a specific hostid file to be copied to /etc/hostid - POOLCACHE: a specific cache to be copied to /etc/zfs/zpool.cache - ZBMTAG: a tag to fetch if /zbm is not pre-populated in container The zbm-build.sh script now overrides ImageDir values and removes Global.BootMountPoint from any configuration, writing artifacts to a temporary directory and copying them to the output directory after a successful run. When /zbm is not pre-populated, it is now built in-container from a tarball fetched from github.com rather than a git clone. This reduces instantiation time and lightens the dependency burden. Closes: #195.
1 parent cfa0455 commit 83b1766

File tree

5 files changed

+275
-81
lines changed

5 files changed

+275
-81
lines changed

contrib/docker/Dockerfile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ RUN echo "ignorepkg=linux" > /etc/xbps.d/10-nolinux.conf \
1919

2020
# Install components necessary to build the image
2121
RUN xbps-query -Rp run_depends zfsbootmenu | xargs xbps-install -y
22-
RUN xbps-install -y linux5.10 linux5.10-headers zfs gummiboot-efistub
22+
RUN xbps-install -y linux5.10 linux5.10-headers \
23+
zfs gummiboot-efistub curl yq-go bash
24+
25+
# Remove headers and massive dkms development toolchain; binutils
26+
# provides objcopy, which is necessary for UEFI bundle creation
27+
RUN xbps-pkgdb -m manual binutils
28+
RUN echo "ignorepkg=dkms" > /etc/xbps.d/10-nodkms.conf
29+
RUN xbps-remove -Roy linux5.10-headers dkms && rm -f /var/cache/xbps/*
2330

2431
# Record a commit hash if one was provided
2532
RUN if [ -n "${ZBM_COMMIT_HASH}" ]; then echo "${ZBM_COMMIT_HASH}" > /etc/zbm-commit-hash; fi

contrib/docker/README.md

Lines changed: 80 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -50,33 +50,73 @@ components of the ZFSBootMenu repository:
5050

5151
- `90zfsbootmenu`, the Dracut module encapsulating ZFSBootMenu functionality;
5252
- `bin/generate-zbm`, the executable script that creates ZFSBootMenu images;
53-
- `contrib/docker`, providing either `config.yaml` or `config.yaml.default`.
54-
55-
If the build script finds the volume mounted at `/zbm` empty, it will install
56-
the `git` package and clone the master branch of the upstream ZFSBootMenu
57-
repository. This makes the image capable of producing default images without
58-
needing a local clone of the repository. To build anything but the head commit
59-
of the upstream master branch, clone the repository, checkout an aribtrary
60-
commit or make local changes, and mount that repository at `/zbm`.
61-
62-
## Contents of `contrib/docker`
63-
64-
The build script expects to find a valid ZFSBootMenu configuration file at
65-
`/zbm/contrib/docker/config.yaml` within the container. If this file does not
66-
exist, the file `/zbm/contrib/docker/config.yaml.default` will be copied to the
67-
expected location. At least one of these files must exist or the build script
68-
will fail. The default configuration will store images in the directory
69-
`contrib/docker/build`, which will be created by `generate-zbm` if it does not
70-
already exist.
71-
72-
Builder containers do not have access to local files `/etc/zfs/zpool.cache` or
73-
`/etc/hostid`. If one or both of these components are desired in the output
74-
image (for example, to ensure consistency with the build host), copy the
75-
desired files to `contrib/docker/zpool.cache` or `contrib/docker/hostid`,
76-
respectively. If the build script finds these files, it will copy them into the
77-
container where the ZFSBootMenu Dracut module expects to find them. If one of
78-
these files is missing, any corresponding file already installed in the
79-
container will be *removed*.
53+
54+
If the build script finds the volume mounted at `/zbm` empty, it will fetch an
55+
archive of the official ZFSBootMenu repository on github.com. This makes the
56+
image capable of producing default images without needing a local clone of the
57+
repository. The specific commit, tag or branch to fetch can be specified at
58+
container run time.
59+
60+
## Command-Line Arguments and Environment Variables
61+
62+
The build script accepts several command-line arguments or environment
63+
variables that override its default behavior. Run the container with the `-h`
64+
command-line argument to see a summary of build options and their default
65+
options. The options are:
66+
67+
- `$BUILDROOT` specifies a default root for image builds. The build root is
68+
expected to hold a default default configuration file and output directory,
69+
as well as optional hostid and pool cache files. If an output directory,
70+
specific configuration and (when appropriate) hostid or pool cache are
71+
specified, then `$BUILDROOT` is not relevant.
72+
73+
The environment variable or default can be overridden with the `-b` option.
74+
75+
- `$ZBMCONF` specifies the in-container path to a specific configuration file.
76+
The build script will override any `ImageDir` paths and remove any
77+
`Global.BootMountPoint` option but otherwise uses the configuration as-is.A
78+
79+
The environment variable or default can be overridded with the `-c` option.
80+
81+
- `$ZBMOUTPUT` specifies the in-container path to an output directory. As noted
82+
above, the build script overrides any `ImageDir` path in a configuration,
83+
pointing it instead to a temporary output directory. After the script
84+
successfully runs `generate-zbm`, it will copy any artifacts from the
85+
temporary build directory to `$ZBMOUTPUT`.
86+
87+
The environment variable or default can be overridded with the `-o` option.
88+
89+
- `$HOSTID` specifies the in-container path to a hostid file. If this file is
90+
specified, it will be copied to `/etc/hostid` inside the container for
91+
inclusion in ZFSBootMenu images. If not, any `/etc/hostid` in the container
92+
will be removed. (Note: unless the `zfsbootmenu` dracut module is configured
93+
with `release_mode=1`, the module may still create an `/etc/hostid` with
94+
potentially arbitrary contents in output images.
95+
96+
The environment variable or default can be overridded with the `-H` option.
97+
98+
- `$POOLCACHE` specifies the in-container path to a ZFS pool cache file. If
99+
this file is specified, it will be copied to `/etc/zfs/zpool.cache` inside
100+
the container for inclusion in ZFSBootMenu images. If not, any
101+
`/etc/zfs/zpool.cache` in the container will be removed.
102+
103+
The environment variable or default can be overridded with the `-C` option.
104+
105+
- `$ZBMTAG` specifies any "commit-ish" label recognized by `git` as a pointer
106+
to a specific git commit. This can be a branch name (to grab the head of that
107+
branch), tag or commit hash. If `/zbm` in the container is not pre-populated,
108+
the container will fetch and unpack the named tag. By default, the value of
109+
`$ZBMTAG` will be taken from the contents of `/etc/zbm-commit-hash` if the
110+
container was built with the `ZBM_COMMIT_HASH` build argument; otherwise, the
111+
default is `master`. The tag is ignored if `/zbm` in the container is not
112+
empty.
113+
114+
The environment variable or default can be overridded with the `-t` option.
115+
116+
An additional command-line argument, `-e`, allows the ZFSBootMenu configuration
117+
to be modified with `yq-go eval` statements at container run time. Do not use
118+
this unless you review the build script and understand, without documentation,
119+
what will happen!
80120

81121
## Build Examples
82122

@@ -85,7 +125,7 @@ default configuration using a local ZFSBootMenu repository `/sw/zfsbootmenu`,
85125
simply run
86126

87127
```sh
88-
podman run -v /sw/zfsbootmenu:/zbm /zbm
128+
podman run -v /sw/zfsbootmenu:/zbm zbm
89129
```
90130

91131
After some console output, the container should terminate and the directory
@@ -101,7 +141,18 @@ directory:
101141

102142
```sh
103143
cp /etc/hostid /sw/zfsbootmenu/contrib/docker/hostid
104-
podman run -v /sw/zfsbootmenu:/zbm /zbm
144+
podman run -v /sw/zfsbootmenu:/zbm zbm
145+
```
146+
147+
To create an image from the current `master` branch without having a local
148+
repository, store the output images in `/boot/efi/EFI/zfsbootmenu` and include
149+
the hostid of the current system, assuming a `zbm` builder container is tagged
150+
locally:
151+
152+
```sh
153+
mkdir -p /boot/efi/EFI/zfsbootmenu
154+
podman run -v /boot/efi/EFI/zfsbootmenu:/output \
155+
-v /etc/hostid:/hostid:ro zbm -o /output -H /hostid
105156
```
106157

107158
# Using Docker Compose

contrib/docker/config.yaml.default

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ Global:
44
# Make sure to look for dracut configuration in the repo
55
DracutConfDir: /zbm/etc/zfsbootmenu/dracut.conf.d
66
Components:
7-
# Dump kernel/initramfs components in the tree;
8-
# generate-zbm creates this directory if necessary
7+
# zbm-build.sh overwrites this anyway
98
ImageDir: /zbm/contrib/docker/build
109
Enabled: true
1110
# Disable versioning, this is usually a one-off creation
1211
Versions: false
1312
syslinux:
1413
Enabled: false
1514
EFI:
15+
# zbm-build.sh overwrites this anyway
1616
ImageDir: /zbm/contrib/docker/build
1717
Versions: false
1818
Enabled: true

0 commit comments

Comments
 (0)